Module: Minitest::Spec::DSL
- Defined in:
- lib/anyt/ext/minitest.rb
Overview
Extend Minitest Spec DSL with custom methodss
Instance Method Summary collapse
-
#channel(id = nil) ⇒ Object
Generates Channel class dynamically and add memoized helper to access its name.
-
#connect_handler(tag) ⇒ Object
Add new #connect handler.
-
#scenario(desc, &block) ⇒ Object
Simplified version of ‘it` which doesn’t care about unique method names.
Instance Method Details
#channel(id = nil) ⇒ Object
Generates Channel class dynamically and add memoized helper to access its name
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/anyt/ext/minitest.rb', line 111 def channel(id = nil, &) class_name = @name.gsub(/\s+/, "_") class_name += "_#{id}" if id class_name += "_channel" cls = Class.new(ApplicationCable::Channel, &) Anyt::TestChannels.const_set(class_name.classify, cls) helper_name = id ? "#{id}_channel" : "channel" let(helper_name) { cls.name } end |
#connect_handler(tag) ⇒ Object
Add new #connect handler
126 127 128 |
# File 'lib/anyt/ext/minitest.rb', line 126 def connect_handler(tag, &) Anyt::ConnectHandlers.add(tag, &) end |
#scenario(desc, &block) ⇒ Object
Simplified version of ‘it` which doesn’t care about unique method names
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/anyt/ext/minitest.rb', line 98 def scenario(desc, &block) full_desc = "#{name.gsub("\n", " ").strip} #{desc.gsub("\n", " ").strip}" return if Anyt.config.example_filter && !Anyt.config.example_filter.match?(full_desc) block ||= proc { skip "(no tests defined)" } define_method "test_ #{desc}", &block desc end |