Skip to content

Commit

Permalink
Merge pull request #398 from rspec/any_instance-combine-features
Browse files Browse the repository at this point in the history
Combine 'any instance' cukes
  • Loading branch information
myronmarston committed Aug 22, 2013
2 parents a988d3d + 3751953 commit 986e20c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
30 changes: 26 additions & 4 deletions features/message_expectations/any_instance.feature
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
Feature: expect a message on any instance of a class

Use `any_instance.should_receive` to set an expectation that one (and only
one) instance of a class receives a message before the example is completed.
Use `expect_any_instance_of(Class).to receive` to set an expectation that one
(and only one) instance of a class receives a message before the example is
completed.

The spec will fail if no instance receives a message.
The example will fail if no instance receives the specified message.

Scenario: expect a message on any instance of a class
Given a file named "example_spec.rb" with:
"""ruby
describe "expect_any_instance_of" do
before do
expect_any_instance_of(Object).to receive(:foo).and_return(:return_value)
end
it "verifies that one instance of the class receives the message" do
o = Object.new
expect(o.foo).to eq(:return_value)
end
it "fails unless an instance receives that message" do
end
end
"""
When I run `rspec example_spec.rb`
Then the output should contain "2 examples, 1 failure"
And the output should contain "1) expect_any_instance_of fails unless an instance receives that message"

Scenario: expect a message on any instance of a class (should syntax)
Given a file named "example_spec.rb" with:
"""ruby
describe "any_instance.should_receive" do
Expand All @@ -18,4 +40,4 @@ Feature: expect a message on any instance of a class
end
"""
When I run `rspec example_spec.rb`
Then the examples should all pass
Then the examples should all pass
27 changes: 0 additions & 27 deletions features/message_expectations/expect_any_instance_of.feature

This file was deleted.

0 comments on commit 986e20c

Please sign in to comment.