class Pork::Expect
Public Class Methods
new(stat, object=nil, message=nil, message_lazy=nil, &checker)
click to toggle source
# File lib/pork/expect.rb, line 7 def initialize stat, object=nil, message=nil, message_lazy=nil, &checker @stat, @object, @negate = stat, object, false @message, @message_lazy = message, message_lazy satisfy(&checker) if checker end
Public Instance Methods
__not__()
click to toggle source
# File lib/pork/expect.rb, line 71 def __not__; if @negate == true then 'not ' else '' end; end
approx(rhs, precision=10)
click to toggle source
# File lib/pork/expect.rb, line 43 def approx rhs, precision=10 round(precision) == rhs.round(precision) end
eq(rhs;)
click to toggle source
# File lib/pork/expect.rb, line 37 def eq rhs; self == rhs; end
gt(rhs;)
click to toggle source
# File lib/pork/expect.rb, line 39 def gt rhs; self > rhs; end
gte(rhs;)
click to toggle source
# File lib/pork/expect.rb, line 41 def gte rhs; self >= rhs; end
lt(rhs;)
click to toggle source
# File lib/pork/expect.rb, line 38 def lt rhs; self < rhs; end
lte(rhs;)
click to toggle source
# File lib/pork/expect.rb, line 40 def lte rhs; self <= rhs; end
method_missing(msg, *args, &block)
click to toggle source
# File lib/pork/expect.rb, line 13 def method_missing msg, *args, &block satisfy(nil, Inspect.with(@object, msg, args, @negate)) do @object.public_send(msg, *args, &block) end end
not(&checker)
click to toggle source
# File lib/pork/expect.rb, line 31 def not &checker @negate = !@negate satisfy(&checker) if checker self end
raise(exception=::RuntimeError) { |else call end| ... }
click to toggle source
# File lib/pork/expect.rb, line 47 def raise exception=::RuntimeError satisfy("#{__not__}raising #{exception}") do begin if ::Kernel.block_given? then yield else @object.call end rescue exception => e e else false end end end def throw msg satisfy("#{__not__}throwing #{msg}") do flag = true data = ::Kernel.catch(msg) do if ::Kernel.block_given? then yield else @object.call end flag = false end flag && [msg, data] end end private def __not__; if @negate == true then 'not ' else '' end; end end end
satisfy(desc=@object, desc_lazy=nil) { |object| ... }
click to toggle source
# File lib/pork/expect.rb, line 19 def satisfy desc=@object, desc_lazy=nil result = yield(@object) if !!result == @negate d = desc_lazy && desc_lazy.call || desc m = @message_lazy && @message_lazy.call || @message ::Kernel.raise Failure.new("Expect #{d}\n#{m}".chomp) else @stat.incr_assertions end result end
throw(msg) { |else call end| ... }
click to toggle source
# File lib/pork/expect.rb, line 59 def throw msg satisfy("#{__not__}throwing #{msg}") do flag = true data = ::Kernel.catch(msg) do if ::Kernel.block_given? then yield else @object.call end flag = false end flag && [msg, data] end end private def __not__; if @negate == true then 'not ' else '' end; end end