lib/quarry/grammar/assert.rb in quarry-0.5.0 vs lib/quarry/grammar/assert.rb in quarry-0.5.2

- old
+ new

@@ -11,12 +11,17 @@ # Assert a operational relationship. # # 4.assert == 3 # - def assert - return Expectation.new(self, :backtrace=>caller) + def assert(test=nil, msg=nil) + if test + msg = "failed assertion (no message given)" unless msg + raise Assertion.new(msg, caller) unless test + else + return Expectation.new(self, :backtrace=>caller) + end end # Assert not an operational relationship. # Read it as "assert not". # @@ -24,11 +29,16 @@ # # AUHTOR'S NOTE: This method would not be necessary # if Ruby would allow +!=+ to be define as a method, # or at least +!+ as a unary method. # - def assert! - return Expectation.new(self, :negate=>true, :backtrace=>caller) + def assert!(test=nil, msg=nil) + if test + msg = "failed assertion (no message given)" unless msg + raise Assertion.new(msg, caller) if test + else + return Expectation.new(self, :negate=>true, :backtrace=>caller) + end end # Same as #assert!. # # 4.refute == 4 #=> Assertion Error