Skip to content

.any_instance.and_call_original throws NilError

gitlab-qa-bot requested to merge fix_any_instance_and_call_orignal into master

Created by: JonRowe

Original code:

Git::Base.any_instance.stub(:object).and_call_original
      Git::Base.any_instance.stub(:object).with('2dc20c984283bede1f45863b8f3b4dd9b5b554cc^{tree}:file-en.svg').
          and_return(mock('Git::Object::Blob', contents: @svg))

Error:


     Failure/Error: Git::Base.any_instance.stub(:object).and_call_original
     NoMethodError:
       undefined method `include?' for nil:NilClass
     # /Users/tim/.rvm/gems/ruby-1.9.3-p392@shuttle/gems/rspec-mocks-2.13.0/lib/rspec/mocks/any_instance/stub_chain.rb:31:in `verify_invocation_order'
     # /Users/tim/.rvm/gems/ruby-1.9.3-p392@shuttle/gems/rspec-mocks-2.13.0/lib/rspec/mocks/any_instance/chain.rb:71:in `record'
     # /Users/tim/.rvm/gems/ruby-1.9.3-p392@shuttle/gems/rspec-mocks-2.13.0/lib/rspec/mocks/any_instance/chain.rb:18:in `and_call_original'
     # ./spec/controllers/commits_controller_spec.rb:277:in `block (3 levels) in <top (required)>'

Values in #verify_invocation_order at time of exception:

invocation_order = {:stub=>[nil], :with=>[:stub], :and_return=>[:with, :stub], :and_raise=>[:with, :stub], :and_yield=>[:with, :stub]}

rspec_method_name = :and_call_original

Merge request reports