{"action":"created","issue":{"url":"https://api.github.com/repos/rspec/rspec-mocks/issues/1077","repository_url":"https://api.github.com/repos/rspec/rspec-mocks","labels_url":"https://api.github.com/repos/rspec/rspec-mocks/issues/1077/labels{/name}","comments_url":"https://api.github.com/repos/rspec/rspec-mocks/issues/1077/comments","events_url":"https://api.github.com/repos/rspec/rspec-mocks/issues/1077/events","html_url":"https://github.com/rspec/rspec-mocks/issues/1077","id":149810413,"number":1077,"title":"Unable to set any_instance expectation on superclass + subclass","user":{"login":"joshuap","id":474649,"avatar_url":"https://avatars.githubusercontent.com/u/474649?v=3","gravatar_id":"","url":"https://api.github.com/users/joshuap","html_url":"https://github.com/joshuap","followers_url":"https://api.github.com/users/joshuap/followers","following_url":"https://api.github.com/users/joshuap/following{/other_user}","gists_url":"https://api.github.com/users/joshuap/gists{/gist_id}","starred_url":"https://api.github.com/users/joshuap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshuap/subscriptions","organizations_url":"https://api.github.com/users/joshuap/orgs","repos_url":"https://api.github.com/users/joshuap/repos","events_url":"https://api.github.com/users/joshuap/events{/privacy}","received_events_url":"https://api.github.com/users/joshuap/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-20T15:53:26Z","updated_at":"2016-04-20T16:07:57Z","closed_at":null,"body":"Re: https://twitter.com/joshuap/status/722545431104753664\r\ncc @samphippen \r\n\r\nTo reproduce this bug check out my [gist](https://gist.github.com/joshuap/4561dff8af653d1f6a3862557d15c503):\r\n\r\n```sh\r\ngit clone git@gist.github.com:4561dff8af653d1f6a3862557d15c503.git rspec_bug\r\ncd rspec_bug\r\nbundle install\r\nbundle exec rspec bug_spec.rb\r\n```\r\n\r\nExample:\r\n\r\n```ruby\r\nclass ExampleBase\r\n  def foo(arg)\r\n    true\r\n  end\r\nend\r\n\r\nclass ExampleObj < ExampleBase\r\n  def foo(arg)\r\n    super\r\n  end\r\nend\r\n\r\ncontext \"when subclass is object of expect_any_instance_of\" do\r\n  before do\r\n    allow_any_instance_of(ExampleBase).to receive(:foo)\r\n  end\r\n\r\n  it \"blows up\" do\r\n    expect_any_instance_of(ExampleObj).to receive(:foo).with(:bar)\r\n    ExampleObj.new.foo(:bar)\r\n  end\r\nend\r\n```\r\n\r\nResulting error:\r\n\r\n```\r\n     NameError:\r\n       method `__foo_without_any_instance__' not defined in ExampleObj\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/any_instance/recorder.rb:197:in `remove_method'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/any_instance/recorder.rb:197:in `block in restore_original_method!'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/any_instance/recorder.rb:194:in `class_exec'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/any_instance/recorder.rb:194:in `restore_original_method!'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/any_instance/recorder.rb:184:in `restore_method!'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/any_instance/recorder.rb:144:in `stop_observing!'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/any_instance/recorder.rb:230:in `observe!'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/any_instance/recorder.rb:63:in `should_receive'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/any_instance/proxy.rb:80:in `perform_proxying'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/any_instance/proxy.rb:62:in `should_receive'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/matchers/receive.rb:96:in `setup_method_substitute'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/matchers/receive.rb:89:in `setup_any_instance_method_substitute'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/matchers/receive.rb:45:in `setup_any_instance_expectation'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/targets.rb:45:in `define_matcher'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-mocks-3.4.1/lib/rspec/mocks/targets.rb:14:in `block in delegate_to'\r\n     # ./bug_spec.rb:19:in `block (2 levels) in <top (required)>'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:236:in `instance_exec'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:236:in `block in run'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:478:in `block in with_around_and_singleton_context_hooks'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:435:in `block in with_around_example_hooks'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:478:in `block in run'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:616:in `run_around_example_hooks_for'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:478:in `run'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:435:in `with_around_example_hooks'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:478:in `with_around_and_singleton_context_hooks'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:233:in `run'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:581:in `block in run_examples'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:577:in `map'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:577:in `run_examples'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:543:in `run'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:119:in `block (3 levels) in run_specs'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:119:in `map'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:119:in `block (2 levels) in run_specs'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1680:in `with_suite_hooks'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:118:in `block in run_specs'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/reporter.rb:77:in `report'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:117:in `run_specs'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:93:in `run'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in `run'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in `invoke'\r\n     # /usr/local/var/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/exe/rspec:4:in `<top (required)>'\r\n     # /usr/local/var/rbenv/versions/2.2.2/bin/rspec:23:in `load'\r\n     # /usr/local/var/rbenv/versions/2.2.2/bin/rspec:23:in `<main>'\r\n```"},"comment":{"url":"https://api.github.com/repos/rspec/rspec-mocks/issues/comments/212492472","html_url":"https://github.com/rspec/rspec-mocks/issues/1077#issuecomment-212492472","issue_url":"https://api.github.com/repos/rspec/rspec-mocks/issues/1077","id":212492472,"user":{"login":"samphippen","id":96662,"avatar_url":"https://avatars.githubusercontent.com/u/96662?v=3","gravatar_id":"","url":"https://api.github.com/users/samphippen","html_url":"https://github.com/samphippen","followers_url":"https://api.github.com/users/samphippen/followers","following_url":"https://api.github.com/users/samphippen/following{/other_user}","gists_url":"https://api.github.com/users/samphippen/gists{/gist_id}","starred_url":"https://api.github.com/users/samphippen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samphippen/subscriptions","organizations_url":"https://api.github.com/users/samphippen/orgs","repos_url":"https://api.github.com/users/samphippen/repos","events_url":"https://api.github.com/users/samphippen/events{/privacy}","received_events_url":"https://api.github.com/users/samphippen/received_events","type":"User","site_admin":false},"created_at":"2016-04-20T16:07:57Z","updated_at":"2016-04-20T16:07:57Z","body":"I've just pushed a commit (4648b31) which adds a failing spec to demonstrate this."}}