Sha256: 3b06b57b2c4540416f4461c1edc1749eb2a6e787c1278d9a65be2cd6f75ecf31

Contents?: true

Size: 1.83 KB

Versions: 39

Compression:

Stored size: 1.83 KB

Contents

module RSpec
  module Matchers
    module BuiltIn
      # @api private
      # Provides the implementation for `equal`.
      # Not intended to be instantiated directly.
      class Equal < BaseMatcher
        # @api private
        # @return [String]
        def failure_message
          if expected_is_a_literal_singleton?
            simple_failure_message
          else
            detailed_failure_message
          end
        end

        # @api private
        # @return [String]
        def failure_message_when_negated
          <<-MESSAGE

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

Compared using equal?, which compares object identity.

MESSAGE
        end

        # @api private
        # @return [Boolean]
        def diffable?
          !expected_is_a_literal_singleton?
        end

      private

        def match(expected, actual)
          actual.equal? expected
        end

        LITERAL_SINGLETONS = [true, false, nil]

        def expected_is_a_literal_singleton?
          LITERAL_SINGLETONS.include?(expected)
        end

        def actual_inspected
          if LITERAL_SINGLETONS.include?(actual)
            actual.inspect
          else
            inspect_object(actual)
          end
        end

        def simple_failure_message
          "\nexpected #{expected.inspect}\n     got #{actual_inspected}\n"
        end

        def detailed_failure_message
          <<-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
`expect(actual).to eq(expected)` if you don't care about
object identity in this example.

MESSAGE
        end

        def inspect_object(o)
          "#<#{o.class}:#{o.object_id}> => #{o.inspect}"
        end
      end
    end
  end
end

Version data entries

39 entries across 36 versions & 10 rubygems

Version Path
opal-rspec-0.8.0 rspec-expectations/upstream/lib/rspec/matchers/built_in/equal.rb
opal-rspec-0.8.0.alpha3 rspec-expectations/upstream/lib/rspec/matchers/built_in/equal.rb
opal-rspec-0.8.0.alpha2 rspec-expectations/upstream/lib/rspec/matchers/built_in/equal.rb
opal-rspec-0.8.0.alpha1 rspec-expectations/upstream/lib/rspec/matchers/built_in/equal.rb
opal-rspec-0.7.1 rspec-expectations/upstream/lib/rspec/matchers/built_in/equal.rb
opal-rspec-0.7.0 rspec-expectations/upstream/lib/rspec/matchers/built_in/equal.rb
opal-rspec-0.6.2 rspec-expectations/lib/rspec/matchers/built_in/equal.rb
opal-rspec-0.7.0.rc.2 rspec-expectations/upstream/lib/rspec/matchers/built_in/equal.rb
opal-rspec-0.6.1 rspec-expectations/lib/rspec/matchers/built_in/equal.rb
opal-rspec-0.6.0 rspec-expectations/lib/rspec/matchers/built_in/equal.rb
opal-rspec-0.6.0.beta1 rspec-expectations/lib/rspec/matchers/built_in/equal.rb
opal-connect-rspec-0.5.0 rspec-expectations/lib/rspec/matchers/built_in/equal.rb
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/rspec-expectations-3.1.2/lib/rspec/matchers/built_in/equal.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/rspec-expectations-3.1.0/lib/rspec/matchers/built_in/equal.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/rspec-expectations-3.1.0/lib/rspec/matchers/built_in/equal.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/rspec-expectations-3.1.0/lib/rspec/matchers/built_in/equal.rb
opal-rspec-0.5.0 rspec-expectations/lib/rspec/matchers/built_in/equal.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/logstash-codec-json-2.0.3/vendor/gems/rspec-expectations-3.1.2/lib/rspec/matchers/built_in/equal.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/rspec-expectations-3.1.2/lib/rspec/matchers/built_in/equal.rb
logstash-codec-json-2.0.3 vendor/gems/rspec-expectations-3.1.2/lib/rspec/matchers/built_in/equal.rb