Module: Thumblemonks::Oughta::MacroMacros::ClassMethods
- Included in:
- Test::Unit::TestCase
- Defined in:
- lib/thumblemonks/oughta/macro_macros.rb
Instance Method Summary collapse
-
#macro(name, &block) ⇒ Object
Defines a macro for use in a TestCase or Context with the given name and block.
-
#use_macro(name) ⇒ Object
Uses a macro defined using the macro method.
Instance Method Details
#macro(name, &block) ⇒ Object
Defines a macro for use in a TestCase or Context with the given name and block. For example, this defines a macro called :should_be_cool
macro :should_be_cool do
should("be true") { assert(true) }
should("be cool") { assert_equal("cool", @message) }
should_eventually "do something else"
end
To then use this macro, see the documentation for use_macro
19 20 21 22 23 |
# File 'lib/thumblemonks/oughta/macro_macros.rb', line 19 def macro(name, &block) (class << self; self; end).instance_eval do define_method(:"Macro: #{name}") { |context| context.instance_eval(&block) } end end |
#use_macro(name) ⇒ Object
Uses a macro defined using the macro method. For example:
class TooLazyToSubmitPatchesToThoughtbotTest < Test::Unit::TestCase
macro :should_be_cool do
should("be cool") { assert_equal("cool", @message) }
end
def setup
@message = "cool"
end
use_macro :should_be_cool
context "intentionally fails" do
setup { @message = "not cool yo" }
use_macro :should_be_cool
end
end
46 47 48 |
# File 'lib/thumblemonks/oughta/macro_macros.rb', line 46 def use_macro(name) send(:"Macro: #{name}", ::Shoulda.current_context || self) end |