Skip to content

Commit

Permalink
Improve the warning message for any_instance block expectations.
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Phippen <samphippen@googlemail.com>
  • Loading branch information
Sam Phippen committed Aug 7, 2013
1 parent 67fbe67 commit 0902a18
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/rspec/mocks/any_instance/expectation_chain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,21 @@ def invocation_order
end

def warn_about_receiver_passing_if_necessary
Kernel.warn(<<MSG
`expect_any_instance_of(...).to receive(:message) { ... }` blocks will get the
receiving instance in 3.0. please explicitly set:
`RSpec::Mocks.configuration.yield_receiver_to_any_instance_implementation_blocks = true`
in your spec helper and fix any failing specs.
RSpec.warn_deprecation(<<MSG
In RSpec 3, `any_instance` implementation blocks will be yielded the receiving
instance as the first block argument to allow the implementation block to use
the state of the receiver. To maintain compatibility with RSpec 3 you need to
either set rspec-mocks' `yield_receiver_to_any_instance_implementation_blocks`
config option to `false` OR set it to `true` and update your `any_instance`
implementation blocks to account for the first block argument being the receiving instance.
To set the config option, use a snippet like:
RSpec.configure do |rspec|
rspec.mock_with :rspec do |mocks|
mocks.yield_receiver_to_any_instance_implementation_blocks = false
end
end
MSG
) if RSpec::Mocks.configuration.should_warn_about_any_instance_blocks?
end
Expand Down

0 comments on commit 0902a18

Please sign in to comment.