1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
require 'ae/subjunctive'
module AE
# Should
#
# "Always and never are two words you should always
# remember never to use."
# --Wendell Johnson
#
# @note THIS IS AN OPTIONAL LIBRARY.
module Should
# Make an assertion in subjunctive tense.
#
# 4.should == 3 #=> Assertion Error
#
# 4.should do
# self == 4
# end
#
# @return [Assertor] Assertion functor.
def should(*args, &block)
Assertor.new(self, :backtrace=>caller).be(*args, &block)
end
# Same as 'object.should == other'.
#
# @return [Assertor] Assertion functor.
def should=(cmp)
Assertor.new(self, :backtrace=>caller).assert == cmp
end
# Designate a negated expectation via a *functor*.
# Read this as "should not".
#
# 4.should! = 4 #=> Assertion Error
#
# @return [Assertor] Assertion functor.
def should!(*args, &block)
Assertor.new(self, :backtrace=>caller).not.be(*args, &block)
end
# NOTE: It would be nice if their were a single term that
# meant the opposite of should, rather than a two word compound.
# Alias for #should! method.
alias_method :should_not, :should!
# Alias for #should! method.
alias_method :shouldnt, :should!
end
end
class ::Object #:nodoc:
include AE::Should
end
# Copyright (c) 2008 Thomas Sawyer, Rubyworks
|