1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
require 'spec_helper'
module RSpec
module Matchers
describe "equal" do
it_behaves_like "an RSpec matcher", :valid_value => :a, :invalid_value => :b do
let(:matcher) { equal(:a) }
end
def inspect_object(o)
"#<#{o.class}:#{o.object_id}> => #{o.inspect}"
end
it "matches when actual.equal?(expected)" do
expect(1).to equal(1)
end
it "does not match when !actual.equal?(expected)" do
expect("1").not_to equal("1")
end
it "describes itself" do
matcher = equal(1)
matcher.matches?(1)
expect(matcher.description).to eq "equal 1"
end
it "suggests the `eq` matcher on failure" do
expected, actual = "1", "1"
expect {
expect(actual).to equal(expected)
}.to fail_with <<-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
context "when using only `should`", :uses_only_should do
it "suggests the `eq` matcher on failure" do
expected, actual = "1", "1"
lambda {
actual.should equal(expected)
}.should fail_with <<-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 eq(expected)` if you don't care about
object identity in this example.
MESSAGE
end
end
it "provides message on #negative_failure_message" do
expected = actual = "1"
matcher = equal(expected)
matcher.matches?(actual)
expect(matcher.failure_message_for_should_not).to eq <<-MESSAGE
expected not #{inspect_object(expected)}
got #{inspect_object(actual)}
Compared using equal?, which compares object identity.
MESSAGE
end
end
end
end
|