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



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/anyt/ext/minitest.rb', line 93

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



108
109
110
# File 'lib/anyt/ext/minitest.rb', line 108

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



83
84
85
86
87
88
89
# File 'lib/anyt/ext/minitest.rb', line 83

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

  define_method "test_ #{desc}", &block

  desc
end