Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Assertion < RunnableBlock
- def self.pass() [:pass]; end
- def self.fail(message) [:fail, message]; end
- def self.error(e) [:error, e]; end
- def run(situation)
- #apply expectation block
- @expectings << situation.evaluate(&@expectation_block) if @expectation_block
- action = @@assertions[@action]
- process_macro(situation,action[0]) { |actual| action[1].call(actual,*@expectings) }
- end
- @@assertions = Hash.new([false,Proc.new { |actual| actual ? Assertion.pass : Assertion.fail("failed") }])
- def self.assertion(name, expect_exception=false, &assertion_block)
- @@assertions[name] = [expect_exception,assertion_block]
- class_eval <<-END_RUBY
- def #{name}(*expectings,&expectation_block)
- @action, @expectings, @expectation_block = :#{name}, expectings, expectation_block
- self
- end
- END_RUBY
- end
- private
- def process_macro(situation, expect_exception)
- actual = situation.evaluate(&@definition)
- yield(expect_exception ? nil : actual)
- rescue Exception => e
- expect_exception ? yield(e) : Assertion.error(e)
- end
- end # Assertion
Add Comment
Please, Sign In to add comment