Sha256: 7bd7c01b0c0e4fe9fe99ae67ff332f4a7d2300148a184e36194f0ccfc80a82ca

Contents?: true

Size: 1.33 KB

Versions: 36

Compression:

Stored size: 1.33 KB

Contents

module Spec
  module Matchers

    # :call-seq:
    #   should equal(expected)
    #   should_not equal(expected)
    #
    # Passes if actual and expected are the same object (object identity).
    #
    # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
    #
    # == Examples
    #
    #   5.should equal(5) #Fixnums are equal
    #   "5".should_not equal("5") #Strings that look the same are not the same object
    def equal(expected)
      Matcher.new :equal, expected do |_expected_|
        match do |actual|
          actual.equal?(_expected_)
        end
        
        def inspect_object(o)
          "#<#{o.class}:#{o.object_id}> => #{o.inspect}"
        end
        
        failure_message_for_should do |actual|
          <<-MESSAGE

expected #{inspect_object(_expected_)}
     got #{inspect_object(actual)}

Compared using equal?, which compares object identity,
but expected and actual are not the same object. Use
'actual.should == expected' if you don't care about
object identity in this example.

MESSAGE
        end

        failure_message_for_should_not do |actual|
          <<-MESSAGE

expected not #{inspect_object(actual)}
         got #{inspect_object(_expected_)}

Compared using equal?, which compares object identity.

MESSAGE
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 11 rubygems

Version Path
rspec-instructure-1.3.3 lib/spec/matchers/equal.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rspec-1.3.2/lib/spec/matchers/equal.rb
rspec-1.3.2 lib/spec/matchers/equal.rb
rspec-1.3.1 lib/spec/matchers/equal.rb
rspec-1.3.1.rc lib/spec/matchers/equal.rb
rspec-1.3.0 lib/spec/matchers/equal.rb
hubbub-0.0.11 lib/vendor/plugins/rspec/lib/spec/matchers/equal.rb
hubbub-0.0.10 lib/vendor/plugins/rspec/lib/spec/matchers/equal.rb
hubbub-0.0.9 lib/vendor/plugins/rspec/lib/spec/matchers/equal.rb
hubbub-0.0.8 lib/vendor/plugins/rspec/lib/spec/matchers/equal.rb
hubbub-0.0.6 lib/vendor/plugins/rspec/lib/spec/matchers/equal.rb
simple-templater-0.0.1.4 gems/gems/rspec-1.2.9/lib/spec/matchers/equal.rb
media-path-0.1.2 vendor/rspec/lib/spec/matchers/equal.rb
simple-templater-0.0.1.3 vendor/rspec/lib/spec/matchers/equal.rb
pupu-0.0.2.pre vendor/rspec/lib/spec/matchers/equal.rb
media-path-0.1.1.pre vendor/rspec/lib/spec/matchers/equal.rb
simple-templater-0.0.1.2 vendor/rspec/lib/spec/matchers/equal.rb
media-path-0.1.1 vendor/rspec/lib/spec/matchers/equal.rb
simple-templater-0.0.1.1 vendor/rspec/lib/spec/matchers/equal.rb
pupu-0.0.2 vendor/rspec/lib/spec/matchers/equal.rb