Skip to content

Instantly share code, notes, and snippets.

@tkfm-yamaguchi
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkfm-yamaguchi/9636302 to your computer and use it in GitHub Desktop.
Save tkfm-yamaguchi/9636302 to your computer and use it in GitHub Desktop.
[1] pry(main)> require 'rspec/mocks/standalone'
=> true
[2] pry(main)> class A; def m; "a" ; end; end
=> :m
[3] pry(main)> class B < A; def m; super + "b"; end; end
=> :m
[4] pry(main)> A.any_instance.stub(:m).and_return("c")
=> #<RSpec::Mocks::AnyInstance::StubChain:0x007fa8eba258f0
@expectation_args=[:m],
@expectation_block=nil,
@invocation_order=
{:with=>[nil],
:and_return=>[:with, nil],
:and_raise=>[:with, nil],
:and_yield=>[:with, nil],
:and_call_original=>[:with, nil]},
@messages=[[[:and_return, "c"], nil]],
@recorder=
#<RSpec::Mocks::AnyInstance::Recorder:0x007fa8eba264d0
@expectation_set=false,
@klass=A,
@message_chains=
{:m=>[#<RSpec::Mocks::AnyInstance::StubChain:0x007fa8eba258f0 ...>]},
@observed_methods=[:m],
@played_methods={},
@stubs={}>>
[5] pry(main)> B.new.m
SystemStackError: stack level too deep
[6] pry(main)> A.new.m
=> "c"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment