Sha256: c0449bac55e7f64f2059fc93976feb182f7e6e5d088a9e3a3569768db5abd79f

Contents?: true

Size: 1.62 KB

Versions: 7

Compression:

Stored size: 1.62 KB

Contents

require 'spec_helper'

module RSpec
  module Matchers
    describe "eq" do
      it_behaves_like "an RSpec matcher", :valid_value => 1, :invalid_value => 2 do
        let(:matcher) { eq(1) }
      end

      it "is diffable" do
        expect(eq(1)).to be_diffable
      end

      it "matches when actual == expected" do
        expect(1).to eq(1)
      end

      it "does not match when actual != expected" do
        expect(1).not_to eq(2)
      end

      it "compares by sending == to actual (not expected)" do
        called = false
        actual = Class.new do
          define_method :== do |other|
            called = true
          end
        end.new

        expect(actual).to eq :anything # to trigger the matches? method
        expect(called).to be_truthy
      end

      it "describes itself" do
        matcher = eq(1)
        matcher.matches?(1)
        expect(matcher.description).to eq "eq 1"
      end

      it "provides message, expected and actual on #failure_message" do
        matcher = eq("1")
        matcher.matches?(1)
        expect(matcher.failure_message_for_should).to eq "\nexpected: \"1\"\n     got: 1\n\n(compared using ==)\n"
      end

      it "provides message, expected and actual on #negative_failure_message" do
        matcher = eq(1)
        matcher.matches?(1)
        expect(matcher.failure_message_for_should_not).to eq "\nexpected: value != 1\n     got: 1\n\n(compared using ==)\n"
      end

      it 'fails properly when the actual is an array of multiline strings' do
        expect {
          expect(["a\nb", "c\nd"]).to eq([])
        }.to fail_matching("expected: []")
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rspec-expectations-2.99.2 spec/rspec/matchers/eq_spec.rb
rspec-expectations-2.99.1 spec/rspec/matchers/eq_spec.rb
rspec-expectations-2.99.0 spec/rspec/matchers/eq_spec.rb
rspec-expectations-2.99.0.rc1 spec/rspec/matchers/eq_spec.rb
rspec-expectations-2.99.0.beta2 spec/rspec/matchers/eq_spec.rb
rspec-expectations-3.0.0.beta1 spec/rspec/matchers/eq_spec.rb
rspec-expectations-2.99.0.beta1 spec/rspec/matchers/eq_spec.rb