Module: Minitest::Spec::DSL

Defined in:
lib/anyt/ext/minitest.rb

Overview

Extend Minitest Spec DSL with custom methodss

Instance Method Summary collapse

Instance Method Details

#channel(id = nil, &block) ⇒ Object

Generates Channel class dynamically and add memoized helper to access its name



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/anyt/ext/minitest.rb', line 108

def channel(id = nil, &block)
  class_name = @name.gsub(/\s+/, "_")
  class_name += "_#{id}" if id
  class_name += "_channel"

  cls = Class.new(ApplicationCable::Channel, &block)

  Anyt::TestChannels.const_set(class_name.classify, cls)

  helper_name = id ? "#{id}_channel" : "channel"

  let(helper_name) { cls.name }
end

#connect_handler(tag, &block) ⇒ Object

Add new #connect handler



123
124
125
# File 'lib/anyt/ext/minitest.rb', line 123

def connect_handler(tag, &block)
  Anyt::ConnectHandlers.add(tag, &block)
end

#scenario(desc, &block) ⇒ Object

Simplified version of ‘it` which doesn’t care about unique method names



98
99
100
101
102
103
104
# File 'lib/anyt/ext/minitest.rb', line 98

def scenario(desc, &block)
  block ||= proc { skip "(no tests defined)" }

  define_method "test_ #{desc}", &block

  desc
end