Sha256: d192ee9f054539ee5a8ce8a5be5b443a41ea9a6fdf8b94df5de7563b460f7a99

Contents?: true

Size: 1.33 KB

Versions: 46

Compression:

Stored size: 1.33 KB

Contents

module RSpec
  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

46 entries across 46 versions & 4 rubygems

Version Path
rspec-expectations-2.7.0.rc1 lib/rspec/matchers/equal.rb
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/rspec-expectations-2.5.0/lib/rspec/matchers/equal.rb
messagebus_ruby_api-0.4.4 spec/ruby/1.9.1/gems/rspec-expectations-2.5.0/lib/rspec/matchers/equal.rb
rspec-expectations-2.6.0 lib/rspec/matchers/equal.rb
rspec-expectations-2.6.0.rc6 lib/rspec/matchers/equal.rb
rspec-expectations-2.6.0.rc4 lib/rspec/matchers/equal.rb
rspec-expectations-2.6.0.rc2 lib/rspec/matchers/equal.rb
rspec-expectations-2.5.0 lib/rspec/matchers/equal.rb
vim-jar-0.1.2.0001 bundler/ruby/1.8/gems/rspec-expectations-2.1.0/lib/rspec/matchers/equal.rb
rspec-expectations-2.4.0 lib/rspec/matchers/equal.rb
vim-jar-0.1.2 bundler/ruby/1.8/gems/rspec-expectations-2.1.0/lib/rspec/matchers/equal.rb
vim-jar-0.1.1 bundler/ruby/1.8/gems/rspec-expectations-2.1.0/lib/rspec/matchers/equal.rb
vim-jar-0.1.0 bundler/ruby/1.8/gems/rspec-expectations-2.1.0/lib/rspec/matchers/equal.rb
rspec-expectations-2.3.0 lib/rspec/matchers/equal.rb
vim-jar-0.0.3 bundler/ruby/1.8/gems/rspec-expectations-2.1.0/lib/rspec/matchers/equal.rb
vim-jar-0.0.2 bundler/ruby/1.8/gems/rspec-expectations-2.1.0/lib/rspec/matchers/equal.rb
vim-jar-0.0.1 bundler/ruby/1.8/gems/rspec-expectations-2.1.0/lib/rspec/matchers/equal.rb
rspec-expectations-2.2.0 lib/rspec/matchers/equal.rb
rspec-expectations-2.1.0 lib/rspec/matchers/equal.rb
rspec-expectations-2.0.1 lib/rspec/matchers/equal.rb