Sha256: fa0d7b0b40344879a76e9eefd923b45761ba4c18a9cf9925fe8579153c6ab8d2

Contents?: true

Size: 1.87 KB

Versions: 7390

Compression:

Stored size: 1.87 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_formatted
          else
            inspect_object(actual)
          end
        end

        def simple_failure_message
          "\nexpected #{expected_formatted}\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}> => #{RSpec::Support::ObjectFormatter.format(o)}"
        end
      end
    end
  end
end

Version data entries

7,390 entries across 7,303 versions & 127 rubygems

Version Path
cvss-suite-1.0.8 vendor/cache/ruby/2.2.0/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/equal.rb
tdiary-5.0.2 vendor/bundle/gems/rspec-expectations-3.5.0/lib/rspec/matchers/built_in/equal.rb
logstash-filter-delta-1.1.0 vendor/bundle/jruby/2.2.0/gems/rspec-expectations-3.5.0/lib/rspec/matchers/built_in/equal.rb
logstash-filter-delta-1.0.1 vendor/bundle/jruby/2.2.0/gems/rspec-expectations-3.5.0/lib/rspec/matchers/built_in/equal.rb
logstash-filter-base64-1.0.4 vendor/bundle/jruby/2.2.0/gems/rspec-expectations-3.5.0/lib/rspec/matchers/built_in/equal.rb
logstash-filter-base64-1.0.3 vendor/bundle/jruby/2.2.0/gems/rspec-expectations-3.5.0/lib/rspec/matchers/built_in/equal.rb
logstash-filter-delta-1.0.0 vendor/bundle/jruby/2.2.0/gems/rspec-expectations-3.5.0/lib/rspec/matchers/built_in/equal.rb
logstash-filter-base64-1.0.2 vendor/bundle/jruby/2.3.0/gems/rspec-expectations-3.5.0/lib/rspec/matchers/built_in/equal.rb
logstash-filter-base64-1.0.1 vendor/bundle/jruby/2.3.0/gems/rspec-expectations-3.5.0/lib/rspec/matchers/built_in/equal.rb
logstash-filter-base64-1.0.0 vendor/bundle/jruby/2.3.0/gems/rspec-expectations-3.5.0/lib/rspec/matchers/built_in/equal.rb
rspec-expectations-3.5.0 lib/rspec/matchers/built_in/equal.rb
tdiary-5.0.1 vendor/bundle/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/equal.rb
cvss-suite-1.0.7 vendor/cache/ruby/2.2.0/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/equal.rb
rspec-expectations-3.5.0.beta4 lib/rspec/matchers/built_in/equal.rb
guesswhat-1.1.0 vendor/bundle/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/equal.rb
guesswhat-1.0.1 vendor/bundle/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/equal.rb
guesswhat-1.0.0 vendor/bundle/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/equal.rb
guesswhat-0.1.0 vendor/bundle/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/equal.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/equal.rb
cvss-suite-1.0.6 vendor/cache/ruby/2.2.0/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/equal.rb