Skip to content

Instantly share code, notes, and snippets.

@rodrigomaia
Created May 24, 2012 12:53
Show Gist options
  • Save rodrigomaia/2781396 to your computer and use it in GitHub Desktop.
Save rodrigomaia/2781396 to your computer and use it in GitHub Desktop.
[RSpec] How to get instance that was invoked a stub method on any_instance
ANYCLASS.any_instance.stub(:METHOD) do |METHOD_PARAM|
INSTANCE_ANYCLASS = ANYCLASS.__recorder.instance_that_received(:METHOD)
end
# See docs:
# AnyInstance => http://rubydoc.info/github/rspec/rspec-mocks/RSpec/Mocks/AnyInstance
# Recorder => http://rubydoc.info/github/rspec/rspec-mocks/RSpec/Mocks/AnyInstance/Recorder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment