Skip to content

Commit

Permalink
refactor specs to use verify and include any_instance_of examples
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Sep 9, 2013
1 parent 53cde82 commit 9ef017d
Showing 1 changed file with 31 additions and 39 deletions.
70 changes: 31 additions & 39 deletions spec/rspec/mocks/matchers/receive_messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,57 @@ module Mocks
expect(obj.b).to eq 2
end

it "allows single expectations" do
allow(obj).to receive_messages(:a => 1)
it "complains if a block is given" do
expect do
allow(obj).to receive_messages(:a => 1) { "implementation" }
end.to raise_error "Implementation blocks arn't supported with `receive_messages`"
end
end

describe "allow_any_instance_of(...).to receive_messages(:a => 1, :b => 2)" do
let(:obj) { Object.new }

it "allows the object to respond to multiple messages" do
allow_any_instance_of(Object).to receive_messages(:a => 1, :b => 2)
expect(obj.a).to eq 1
expect(obj.b).to eq 2
end

it "complains if a block is given" do
expect do
allow(obj).to receive_messages(:a => 1) { "implementation" }
allow_any_instance_of(Object).to receive_messages(:a => 1) { "implementation" }
end.to raise_error "Implementation blocks arn't supported with `receive_messages`"
end
end

describe "expect(...).to receive_messages(:a => 1, :b => 2)" do
let(:reporter) { RSpec::Core::Reporter.new }
let(:obj) { double "Object" }

it "sets up multiple expectations" do
expect(reporter).to receive(:example_passed).with("will pass")
expect(reporter).to receive(:example_failed).with("will fail")

example_group = ::RSpec::Core::ExampleGroup.describe do
before do
obj = double "Object"
expect(obj).to receive_messages(:a => 1, :b => 2)
end

it "will pass" do
obj.a && obj.b
end

it "will fail" do
obj.a
end
end
example_group.run reporter
expect(obj).to receive_messages(:a => 1, :b => 2)
obj.a
expect { RSpec::Mocks.space.verify_all }.to raise_error RSpec::Mocks::MockExpectationError
end

it "allows single expectations" do
expect(reporter).to receive(:example_passed).with("will pass")
expect(reporter).to receive(:example_failed).with("will fail")

example_group = ::RSpec::Core::ExampleGroup.describe do
before do
obj = double "Object"
expect(obj).to receive_messages(:a => 1)
end
it "complains if a block is given" do
expect do
expect(double).to receive_messages(:a => 1) { "implementation" }
end.to raise_error "Implementation blocks arn't supported with `receive_messages`"
end
end

it "will pass" do
obj.a
end
describe "expect_any_instance_of(...).to receive_messages(:a => 1, :b => 2)" do
let(:obj) { Object.new }

it "will fail" do
end
end
example_group.run reporter
it "sets up multiple expectations" do
expect_any_instance_of(Object).to receive_messages(:a => 1, :b => 2)
obj.a
expect { RSpec::Mocks.space.verify_all }.to raise_error RSpec::Mocks::MockExpectationError
end

it "complains if a block is given" do
expect do
expect(double).to receive_messages(:a => 1) { "implementation" }
expect_any_instance_of(Object).to receive_messages(:a => 1) { "implementation" }
end.to raise_error "Implementation blocks arn't supported with `receive_messages`"
end
end
Expand Down

0 comments on commit 9ef017d

Please sign in to comment.