Class: Riot::Assertion
Instance Attribute Summary
#definition
Class Method Summary
collapse
Instance Method Summary
collapse
#to_s
Constructor Details
#initialize(description, negative = false, &definition) ⇒ Assertion
Returns a new instance of Assertion.
11
12
13
14
15
16
|
# File 'lib/riot/assertion.rb', line 11
def initialize(description, negative=false, &definition)
super(description, &definition)
@negative = negative
@expectings, @expectation_block = [], nil
@macro = AssertionMacro.default
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/riot/assertion.rb', line 33
def enhance_with_macro(name, *expectings, &expectation_block)
@expectings, @expectation_block = expectings, expectation_block
@macro = self.class.macros[name.to_s].new
raise(NoMethodError, name) unless @macro
@macro.file, @macro.line = caller.first.match(/(.*):(\d+)/)[1..2]
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
end
|
Instance Method Details
#run(situation) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/riot/assertion.rb', line 18
def run(situation)
@expectings << situation.evaluate(&@expectation_block) if @expectation_block
actual = situation.evaluate(&definition)
assert((@macro.expects_exception? ? nil : actual), *@expectings)
rescue Exception => e
@macro.expects_exception? ? assert(e, *@expectings) : @macro.error(e)
end
|