a(*args, &block)
click to toggle source
an(*args, &block)
click to toggle source
be(*args, &block)
click to toggle source
def be(*args, &block)
if args.empty?
self
else
block = args.shift unless block_given?
satisfy(*args, &block)
end
end
equal(value)
click to toggle source
def equal(value) self == value end
flunk(reason="Flunked")
click to toggle source
def flunk(reason="Flunked")
raise Bacon::Error.new(:failed, reason)
end
identical_to(value)
click to toggle source
def identical_to(value) self.equal? value end
match(value)
click to toggle source
def match(value) self =~ value end
method_missing(name, *args, &block)
click to toggle source
def method_missing(name, *args, &block)
name = "#{name}?" if name.to_s =~ %r\w[^?]\z/
desc = @negated ? "not " : ""
desc << @object.inspect << "." << name.to_s
desc << "(" << args.map{|x|x.inspect}.join(", ") << ") failed"
satisfy(desc) { |x| x.__send__(name, *args, &block) }
end
not(*args, &block)
click to toggle source
def not(*args, &block)
@negated = !@negated
if args.empty?
self
else
be(*args, &block)
end
end
same_as(value)
click to toggle source
satisfy(*args) { |object, *args| ... }
click to toggle source
def satisfy(*args, &block)
if args.size == 1 && String === args.first
description = args.shift
else
description = ""
end
r = yield(@object, *args)
if Bacon::Counter[:depth] > 0
Bacon::Counter[:requirements] += 1
raise Bacon::Error.new(:failed, description) unless @negated ^ r
end
@negated ^ r ? r : false
end