Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RR.reset does not reset respond_to? #43

Open
ryanb opened this issue Oct 5, 2010 · 4 comments
Open

RR.reset does not reset respond_to? #43

ryanb opened this issue Oct 5, 2010 · 4 comments
Milestone

Comments

@ryanb
Copy link

ryanb commented Oct 5, 2010

After stubbing a method on a class and calling RR.reset the respond_to? call still returns true.

# in irb
require 'rubygems'
require 'rr'
include RR::Adapters::RRMethods
stub(Hash).foo { true }
Hash.foo # => true
Hash.respond_to?(:foo) # => true
RR.reset
Hash.foo # => undefined method error
Hash.respond_to?(:foo) # => true

This problem did not exist in earlier versions such as 0.10.11.

@ryanb
Copy link
Author

ryanb commented Nov 15, 2010

Any word on this problem and if it will be fixed? Confirmation that others can reproduce it would be good too.

@walle
Copy link

walle commented Aug 6, 2011

Your example still breaks in irb(rr 1.0.3).

ruby-1.9.2-p180 :002 > require 'rr'
 => true 
ruby-1.9.2-p180 :003 > include RR::Adapters::RRMethods
 => Object 
ruby-1.9.2-p180 :004 > stub(Hash).foo { true }
 => #, @argument_expectation=#, @times_matcher=#, @after_call_proc=nil, @yields_value=nil, @double_definition_create=#, @handler=#, @args=[], @method_name=:foo, @definition=#>, @implementation_strategy=#, @handler=#, @args=[], @method_name=:foo, @definition=#>, @double_injection_strategy=#, @handler=#, @args=[], @method_name=:foo, @definition=#>, @subject=Hash>, @ordered=false, @verbose=false, @verify_method_signature=false, @double=#, @method_name=:foo, @doubles=[#], @dispatch_method_delegates_to_dispatch_original_method=nil>, @definition=#, @times_called=0, @times_called_expectation=#, @times_called=0, @verify_backtrace=["/home/walle/.rvm/gems/ruby-1.9.2-p180/gems/rr-1.0.3/lib/rr/double.rb:26:in `initialize'", "/home/walle/.rvm/gems/ruby-1.9.2-p180/gems/rr-1.0.3/lib/rr/double_definitions/strategies/double_injection/instance.rb:11:in `new'", "/home/walle/.rvm/gems/ruby-1.9.2-p180/gems/rr-1.0.3/lib/rr/double_definitions/strategies/double_injection/instance.rb:11:in `do_call'", "/home/walle/.rvm/gems/ruby-1.9.2-p180/gems/rr-1.0.3/lib/rr/double_definitions/strategies/strategy.rb:14:in `call'", "/home/walle/.rvm/gems/ruby-1.9.2-p180/gems/rr-1.0.3/lib/rr/double_definitions/double_definition_create.rb:37:in `call'", "/home/walle/.rvm/gems/ruby-1.9.2-p180/gems/rr-1.0.3/lib/rr/double_definitions/double_definition_create_blank_slate.rb:18:in `method_missing'", "(irb):4:in `irb_binding'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/workspace.rb:80:in `eval'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/workspace.rb:80:in `evaluate'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/context.rb:254:in `evaluate'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:159:in `block (2 levels) in eval_input'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:273:in `signal_status'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:156:in `block in eval_input'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:243:in `block (2 levels) in each_top_level_statement'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_statement'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:155:in `eval_input'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:70:in `block in start'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:69:in `catch'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:69:in `start'", "/home/walle/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `'"]>>> 
ruby-1.9.2-p180 :005 > Hash.foo # => true
 => true 
ruby-1.9.2-p180 :006 > Hash.respond_to?(:foo) # => true
 => true 
ruby-1.9.2-p180 :007 > RR.reset
 => {} 
ruby-1.9.2-p180 :008 > Hash.foo # => undefined method error
NoMethodError: undefined method `instance_methods' for nil:NilClass
    from /home/walle/.rvm/gems/ruby-1.9.2-p180/gems/rr-1.0.3/lib/rr/class_instance_method_defined.rb:4:in `class_instance_method_defined'
    from /home/walle/.rvm/gems/ruby-1.9.2-p180/gems/rr-1.0.3/lib/rr/injections/injection.rb:14:in `subject_has_method_defined?'
    from /home/walle/.rvm/gems/ruby-1.9.2-p180/gems/rr-1.0.3/lib/rr/injections/injection.rb:18:in `subject_has_original_method?'
    from /home/walle/.rvm/gems/ruby-1.9.2-p180/gems/rr-1.0.3/lib/rr/method_dispatches/method_dispatch.rb:28:in `call_original_method'
    from /home/walle/.rvm/gems/ruby-1.9.2-p180/gems/rr-1.0.3/lib/rr/injections/double_injection.rb:188:in `dispatch_original_method'
    from /home/walle/.rvm/gems/ruby-1.9.2-p180/gems/rr-1.0.3/lib/rr/injections/double_injection.rb:42:in `dispatch_method'
    from /home/walle/.rvm/gems/ruby-1.9.2-p180/gems/rr-1.0.3/lib/rr/injections/double_injection.rb:147:in `foo'
    from (irb):8
    from /home/walle/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `'
ruby-1.9.2-p180 :009 > Hash.respond_to?(:foo) # => true
 => true

I tried to add a failing test but it reports that respond_to? is false. This test passes somehow, any ideas?

it 'should remove respond_to? after reset' do
  stub(Hash).foo { true }
  RR.reset
  Hash.respond_to?(:foo).should be_false
end

@clupprich
Copy link

When calling the stubbed method (just using respond_to? is not enough), the spec fails:

it 'should remove respond_to? after reset' do
  stub(Hash).foo { true }
  Hash.foo.should be_true
  RR.reset
  Hash.respond_to?(:foo).should be_false
end

@mcmire
Copy link
Collaborator

mcmire commented Mar 8, 2013

I just checked and this bug still exists, for both instances and classes.

Test:

require 'rr'
require 'rspec/core'
require 'rspec/expectations'

describe "issue #43" do
  include RR::Adapters::RSpec2

  it "doesn't exist for an instance of a class" do
    subject = Object.new
    stub(subject).foo { true }
    expect(subject.foo).to eq true
    expect(subject).to respond_to(:foo)
    RR.reset
    expect { subject.foo }.to raise_error(NoMethodError)
    expect(subject).not_to respond_to(:foo)
  end

  it "does exist for a class itself" do
    subject = Object
    stub(subject).foo { true }
    expect(subject.foo).to eq true
    expect(subject).to respond_to(:foo)
    RR.reset
    expect { subject.foo }.to raise_error(NoMethodError)
    expect(subject).not_to respond_to(:foo)
  end
end

Output:

○ rspec /tmp/rr-test.rb
FF

Failures:

  1) issue #43 for an instance of a class
     Failure/Error: expect(subject).not_to respond_to(:foo)
       expected #<Object:0x007f8419491778> not to respond to :foo
     # /tmp/rr-test.rb:15:in `block (2 levels) in <top (required)>'

  2) issue #43 for a class itself
     Failure/Error: expect(subject).not_to respond_to(:foo)
       expected Object not to respond to :foo
     # /tmp/rr-test.rb:25:in `block (2 levels) in <top (required)>'

Finished in 0.00464 seconds
2 examples, 2 failures

Failed examples:

rspec /tmp/rr-test.rb:8 # issue #43 for an instance of a class
rspec /tmp/rr-test.rb:18 # issue #43 for a class itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants