class MotionSpec::Should
Public Class Methods
new(object)
click to toggle source
# File lib/motion-spec/should.rb, line 11 def initialize(object) @object = object @negated = false end
Public Instance Methods
be(*args, &block)
click to toggle source
# File lib/motion-spec/should.rb, line 24 def be(*args, &block) return self if args.empty? block = args.shift unless block_given? satisfy(*args, &block) end
eq=(value)
click to toggle source
TODO: This was in the MacBacon specs and kept for backwards compatibilty but I’ve never seen this used before so possibly kill this.
# File lib/motion-spec/should.rb, line 79 def eq=(value) self === value end
equal(value)
click to toggle source
# File lib/motion-spec/should.rb, line 63 def equal(value) self == value end
Also aliased as: eq
flunk(reason = 'Flunked')
click to toggle source
# File lib/motion-spec/should.rb, line 83 def flunk(reason = 'Flunked') fail Error.new(:failed, reason) end
identical_to(value)
click to toggle source
# File lib/motion-spec/should.rb, line 72 def identical_to(value) self.equal? value end
Also aliased as: same_as
match(value)
click to toggle source
# File lib/motion-spec/should.rb, line 68 def match(value) self =~ value end
method_missing(name, *args, &block)
click to toggle source
# File lib/motion-spec/should.rb, line 51 def method_missing(name, *args, &block) name = "#{name}?" if name.to_s =~ /\w[^?]\z/ desc = @negated ? 'not ' : '' desc << @object.inspect << '.' << name.to_s desc << '(' << args.map(&:inspect).join(', ') << ') failed' satisfy(desc) do |object| object.__send__(name, *args, &block) end end
not(*args, &block)
click to toggle source
# File lib/motion-spec/should.rb, line 16 def not(*args, &block) @negated = !@negated return self if args.empty? be(*args, &block) end
satisfy(*args) { |object, *args| ... }
click to toggle source
# File lib/motion-spec/should.rb, line 33 def satisfy(*args, &_block) if args.size == 1 && String === args.first description = args.shift else description = '' end result = yield(@object, *args) if Counter[:depth] > 0 Counter[:requirements] += 1 flunk(description) unless @negated ^ result result else @negated ? !result : !!result end end