Class: Riot::Assertion
Instance Attribute Summary
#definition
Class Method Summary
collapse
Instance Method Summary
collapse
#to_s
Constructor Details
#initialize(description, &definition) ⇒ Assertion
Returns a new instance of Assertion.
11
12
13
14
15
|
# File 'lib/riot/assertion.rb', line 11
def initialize(description, &definition)
super
@expectings, @expectation_block = [], false, nil
@macro = AssertionMacro.default
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing ⇒ Object
30
31
32
33
34
|
# File 'lib/riot/assertion.rb', line 30
def enhance_with_macro(name, *expectings, &expectation_block)
@macro, @expectings, @expectation_block = self.class.macros[name.to_s], expectings, expectation_block
raise(NoMethodError, name) unless @macro
self
end
|
Class Method Details
4
|
# File 'lib/riot/assertion.rb', line 4
def macros; @macros ||= {}; end
|
.register_macro(name, assertion_macro, expect_exception = false) ⇒ Object
6
7
8
|
# File 'lib/riot/assertion.rb', line 6
def register_macro(name, assertion_macro, expect_exception=false)
macros[name.to_s] = assertion_macro.new
end
|
Instance Method Details
#run(situation) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/riot/assertion.rb', line 17
def run(situation)
@expectings << situation.evaluate(&@expectation_block) if @expectation_block
actual = situation.evaluate(&definition)
@macro.evaluate((@macro.expects_exception? ? nil : actual), *@expectings)
rescue Exception => e
@macro.expects_exception? ? @macro.evaluate(e, *@expectings) : @macro.error(e)
end
|