Issue with respond_to_missing? being called on mock
Open
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 117
- Forks
- 51
- Avg merge
- 59m
- Merged PRs (30d)
- 3
Description
class TestMe
class << self
def callme
'failure'
end
private
def method_missing(name, *args, &block)
raise "Failure!"
end
def respond_to_missing?(name, include_private = false)
callme.respond_to?(name, include_private) || super
end
end
end
require 'rspec'
describe TestMe do
it 'mock static method' do
allow(TestMe).to receive(:callme).and_return('success') # will trigger method_missing
expect(TestMe.callme).to eq('success')
end
end
That will produce following output:
Failures:
1) TestMe mock static method
Failure/Error: raise "Failure!"
RuntimeError:
Failure!
# ./stack_level.rb:11:in `method_missing'
# ./stack_level.rb:15:in `respond_to_missing?'
# ./stack_level.rb:25:in `block (2 levels) in <top (required)>'
Finished in 0.00523 seconds (files took 0.11831 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./method_missing_spec.rb:24 # TestMe mock static method
FUNFACT: It worked well in RSpec 3.2, and broke only after update to 3.4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduction in stack_level.rb and method_missing_spec.rb, comparing the behavior between RSpec 3.2 and 3.4. Trace why allow(TestMe).to receive(:callme) invokes respond_to_missing? and method_missing; done means the example passes without raising Failure! while preserving the mocked return value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100