Sha256: 5b2772f1ffc9bb7e30ac7ffc9cbf8a2f5c70513fdf692918a9f9fedac19ce7f6

Contents?: true

Size: 1.75 KB

Versions: 5

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

describe Bogus::HaveReceivedMatcher do
  let(:verifies_stub_definition) { stub(verify!: nil) }
  let(:records_double_interactions) { stub(record: nil) }
  let(:have_received_matcher) { isolate(Bogus::HaveReceivedMatcher) }
  let(:have_received) { have_received_matcher.method_call }
  let(:fake) { Samples::FooFake.new }

  before do
    fake.foo("a", "b")
  end

  it "matches when the spy has received the message" do
    fake.should have_received.foo("a", "b")
  end

  it "does not match if the spy hasn't received the message" do
    fake.should_not have_received.foo("a", "c")
  end

  it "verifies that the method call has the right signature" do
    mock(verifies_stub_definition).verify!(fake, :foo, ["a", "b"])

    have_received.foo("a", "b")

    have_received_matcher.matches?(fake)
  end

  it "records the interaction so that it can be checked by contract tests" do
    mock(records_double_interactions).record(fake, :foo, ["a", "b"])

    have_received.foo("a", "b")

    have_received_matcher.matches?(fake)
  end

  it "returns a readable error message for object with no shadow" do
    have_received.upcase

    have_received_matcher.matches?("foo").should be_false
    have_received_matcher.failure_message_for_should.should == Bogus::HaveReceivedMatcher::NO_SHADOW
    have_received_matcher.failure_message_for_should_not.should == Bogus::HaveReceivedMatcher::NO_SHADOW
  end

  it "returns a readable error message for fakes" do
    have_received.foo("a", "c")

    have_received_matcher.matches?(fake)

    have_received_matcher.failure_message_for_should.should ==
      %Q{Expected #{fake.inspect} to have received foo("a", "c"), but it didn't.\n\n}+
        %Q{The recorded interactions were:\n} +
        %Q{  - foo("a", "b")\n}
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bogus-0.1.0 spec/bogus/have_received_matcher_spec.rb
bogus-0.0.4 spec/bogus/have_received_matcher_spec.rb
bogus-0.0.3 spec/bogus/have_received_matcher_spec.rb
bogus-0.0.3.rc.2 spec/bogus/have_received_matcher_spec.rb
bogus-0.0.3.rc.1 spec/bogus/have_received_matcher_spec.rb