lib/ae/expect.rb in ae-1.2.3 vs lib/ae/expect.rb in ae-1.3.0

- old
+ new

@@ -37,68 +37,19 @@ # Like #assert it can be used to designate an expectation # via a *functor*. # # 4.expect == 3 # - # def expect(*args, &block) - return Assertor.new(self, :backtrace=>caller) if args.empty? && !block - block = args.shift if !block_given? && Proc === args.first - if block - exp = args.empty? ? self : args.shift - if Exception === exp || (Class===exp && exp.ancestors.include?(Exception)) - begin - block.call - pass = false - msg = "#{exp} not raised" - rescue exp => error - pass = true - rescue Exception => error - pass = false - msg = "#{exp} expected but #{error.class} was raised" - end - else - res = block.call - pass = (exp === res) - msg = "#{exp} === #{res}" - end - else - pass = (exp === self) - msg = "#{exp} === #{self}" - end - flunk(msg, caller) unless pass + Assertor.new(self, :backtrace=>caller).expect(*args, &block) end # Designate a negated expectation. Read this as "expect not". # # See #expect. # - def expect!(exp=NoArgument, &block) - return Assertor.new(self, :backtrace=>caller) if args.empty? && !block - block = args.shift if !block_given? && Proc === args.first - if block - exp = args.empty? ? self : args.shift - if Exception === exp || (Class===exp && exp.is?(Exception)) - begin - block.call - pass = true - rescue exp => error - pass = false - msg = "#{exp} raised" - rescue Exception => error - pass = true - #msg = "#{exp} expected but #{error.class} was raised" - end - else - res = block.call - pass = !(exp === res) - msg = "not #{exp} === #{res}" - end - else - pass = !(exp === self) - msg = "not #{exp} === #{self}" - end - flunk(msg, caller) unless pass + def expect!(*args, &block) + Assertor.new(self, :backtrace=>caller).not.expect(*args, &block) end # Alias for #expect! method. alias_method :forbid, :expect!