Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
Reword any_instance any_return documentation slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Feb 22, 2023
1 parent 0274523 commit 07447e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
6 changes: 1 addition & 5 deletions features/configuring_responses/returning_a_value.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ Feature: Returning a value
different return values for consecutive calls. The final value will continue to be returned if
the message is received additional times.

Note - using the multiple calls feature with `allow_any_instance_of` can result in confusing
behavior. The rspec-mocks team [discourages](../../working_with_legacy_code/any_instance.feature)
using `allow_any_instance_of`, but its interaction with `and_return` is documented in
the [Working with Legacy Code](../../working_with_legacy_code/any_instance.feature#specify-different-return-values-for-multiple-calls-in-combination-with-`allow-any-instance-of`)
section.
Note - If you are looking for documentation for configuring responses from `allow_any_instance_of`, please see the [working with legacy code](../../working_with_legacy_code/any_instance.feature) documentation.

Scenario: Nil is returned by default
Given a file named "returns_nil_spec.rb" with:
Expand Down
12 changes: 5 additions & 7 deletions features/working_with_legacy_code/any_instance.feature
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ Feature: Any Instance

Scenario: Specify different return values for multiple calls in combination with allow_any_instance_of

Using the multiple calls feature with `allow_any_instance_of` can result in confusing behavior. With
`allow_any_instance_of`, the multiple calls are *configured* on the class, but *tracked* on the instance. Therefore,
each individual instance will return the configured return values in the order specified, and then begin to repeat
the last value, as demonstrated in this code:
Using the multiple calls feature with `allow_any_instance_of` results in the behaviour where multiple calls are configured on every instance.
Therefore, each individual instance will return the configured return values in the order specified, and then begin to repeat the last value.

Given a file named "multiple_calls_spec_with_allow_any_instance_of.rb" with:
"""ruby
Expand All @@ -143,14 +141,14 @@ Feature: Any Instance
expect(second.foo).to eq(2)
expect(first.foo).to eq(3)
expect(first.foo).to eq(3) # begins to repeat last value
expect(first.foo).to eq(3) # repeats last value from here
expect(second.foo).to eq(3)
expect(second.foo).to eq(3) # begins to repeat last value
expect(second.foo).to eq(3) # repeats last value from here
expect(third.foo).to eq(1)
expect(third.foo).to eq(2)
expect(third.foo).to eq(3)
expect(third.foo).to eq(3) # begins to repeat last value
expect(third.foo).to eq(3) # repeats last value from here
end
end
"""
Expand Down

0 comments on commit 07447e3

Please sign in to comment.