Class: Riot::Assertion
- Inherits:
-
RunnableBlock
- Object
- RunnableBlock
- Riot::Assertion
- Defined in:
- lib/riot/assertion.rb,
lib/riot/assertion_macros.rb
Instance Attribute Summary
Attributes inherited from RunnableBlock
Class Method Summary collapse
-
.assertion(name, expect_exception = false, &assertion_block) ⇒ Object
TODO: Make everyone switch to 1.8.7 or above so we can go mostly stateless again.
- .assertions ⇒ Object
- .error(e) ⇒ Object
- .fail(message) ⇒ Object
- .pass ⇒ Object
Instance Method Summary collapse
-
#initialize(description, &definition) ⇒ Assertion
constructor
A new instance of Assertion.
- #run(situation) ⇒ Object
Methods inherited from RunnableBlock
Constructor Details
#initialize(description, &definition) ⇒ Assertion
Returns a new instance of Assertion.
4 5 6 7 8 9 10 |
# File 'lib/riot/assertion.rb', line 4 def initialize(description, &definition) super @expectings, @expect_exception, @expectation_block = [], false, nil @assertion_block = lambda do |actual| actual ? self.class.pass : self.class.fail("Expected non-false but got #{actual.inspect} instead") end end |
Class Method Details
.assertion(name, expect_exception = false, &assertion_block) ⇒ Object
TODO: Make everyone switch to 1.8.7 or above so we can go mostly stateless again. Had to do this for 1.8.6 compatibility {:() I’m a sad sock monkey
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/riot/assertion.rb', line 20 def assertion(name, expect_exception=false, &assertion_block) assertions[name] = [expect_exception, assertion_block] class_eval <<-EOC def #{name}(*expectings, &expectation_block) @expectings, @expectation_block = expectings, expectation_block @expect_exception, @assertion_block = self.class.assertions[#{name.inspect}] self end EOC end |
.assertions ⇒ Object
16 |
# File 'lib/riot/assertion.rb', line 16 def assertions; @assertions ||= {}; end |
.error(e) ⇒ Object
15 |
# File 'lib/riot/assertion.rb', line 15 def error(e) [:error, e]; end |
.fail(message) ⇒ Object
14 |
# File 'lib/riot/assertion.rb', line 14 def fail() [:fail, ]; end |
.pass ⇒ Object
13 |
# File 'lib/riot/assertion.rb', line 13 def pass() [:pass]; end |
Instance Method Details
#run(situation) ⇒ Object
32 33 34 35 |
# File 'lib/riot/assertion.rb', line 32 def run(situation) @expectings << situation.evaluate(&@expectation_block) if @expectation_block process_macro(situation, @expect_exception) { |actual| @assertion_block.call(actual, *@expectings) } end |