{"action":"created","issue":{"url":"https://api.github.com/repos/jbodah/spy_rb/issues/16","labels_url":"https://api.github.com/repos/jbodah/spy_rb/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/jbodah/spy_rb/issues/16/comments","events_url":"https://api.github.com/repos/jbodah/spy_rb/issues/16/events","html_url":"https://github.com/jbodah/spy_rb/issues/16","id":87530751,"number":16,"title":"AlreadySpiedError not being thrown","user":{"login":"jbodah","id":6093002,"avatar_url":"https://avatars.githubusercontent.com/u/6093002?v=3","gravatar_id":"","url":"https://api.github.com/users/jbodah","html_url":"https://github.com/jbodah","followers_url":"https://api.github.com/users/jbodah/followers","following_url":"https://api.github.com/users/jbodah/following{/other_user}","gists_url":"https://api.github.com/users/jbodah/gists{/gist_id}","starred_url":"https://api.github.com/users/jbodah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbodah/subscriptions","organizations_url":"https://api.github.com/users/jbodah/orgs","repos_url":"https://api.github.com/users/jbodah/repos","events_url":"https://api.github.com/users/jbodah/events{/privacy}","received_events_url":"https://api.github.com/users/jbodah/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jbodah/spy_rb/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-11T23:02:02Z","updated_at":"2015-06-11T23:20:35Z","closed_at":null,"body":"```rb\r\nirb(main):001:0> require 'spy'\r\n=> true\r\nirb(main):002:0> Spy.on(Object, :to_s)\r\n=> #<Spy::Instance:0x007fd8e93e4da0 @spied=Object, @original=#<Method: Class(Module)#to_s>, @visibility=:public, @conditional_filters=[], @before_callbacks=[], @after_callbacks=[], @around_procs=[], @call_history=[], @strategy=#<Spy::Instance::Strategy::Intercept:0x007fd8e93e4af8 @spy=#<Spy::Instance:0x007fd8e93e4da0 ...>, @intercept_target=#<Class:Object>>>\r\nirb(main):003:0> Spy.on(Object, :to_s)\r\n=> #<Spy::Instance:0x007fd8e93dea40 @spied=Object, @original=#<Method: Object.to_s>, @visibility=:public, @conditional_filters=[], @before_callbacks=[], @after_callbacks=[], @around_procs=[], @call_history=[], @strategy=#<Spy::Instance::Strategy::Wrap:0x007fd8e93de8b0 @spy=#<Spy::Instance:0x007fd8e93dea40 ...>>>\r\nirb(main):004:0> Spy.on(Object, :to_s)\r\nObject: Spy::Errors::AlreadySpiedError\r\n        from /Users/Bodah/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/spy_rb-0.3.0/lib/spy/collection.rb:12:in `insert'\r\n        from /Users/Bodah/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/spy_rb-0.3.0/lib/spy/collection.rb:39:in `<<'\r\n        from /Users/Bodah/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/spy_rb-0.3.0/lib/spy/core.rb:13:in `add_spy'\r\n        from /Users/Bodah/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/spy_rb-0.3.0/lib/spy/api.rb:10:in `on'\r\n        from (irb):4\r\n        from /Users/Bodah/.rbenv/versions/2.1.3/bin/irb:11:in `<main>'\r\n```"},"comment":{"url":"https://api.github.com/repos/jbodah/spy_rb/issues/comments/111304802","html_url":"https://github.com/jbodah/spy_rb/issues/16#issuecomment-111304802","issue_url":"https://api.github.com/repos/jbodah/spy_rb/issues/16","id":111304802,"user":{"login":"jbodah","id":6093002,"avatar_url":"https://avatars.githubusercontent.com/u/6093002?v=3","gravatar_id":"","url":"https://api.github.com/users/jbodah","html_url":"https://github.com/jbodah","followers_url":"https://api.github.com/users/jbodah/followers","following_url":"https://api.github.com/users/jbodah/following{/other_user}","gists_url":"https://api.github.com/users/jbodah/gists{/gist_id}","starred_url":"https://api.github.com/users/jbodah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbodah/subscriptions","organizations_url":"https://api.github.com/users/jbodah/orgs","repos_url":"https://api.github.com/users/jbodah/repos","events_url":"https://api.github.com/users/jbodah/events{/privacy}","received_events_url":"https://api.github.com/users/jbodah/received_events","type":"User","site_admin":false},"created_at":"2015-06-11T23:20:35Z","updated_at":"2015-06-11T23:20:35Z","body":"The issue is likely:\r\n\r\n1. Spy called with to_s; Module is the owner of to_s\r\n2. Spy::Collection logs the spy\r\n3. Intercept strategy is used defining the method on the singleton\r\n4. Spy called with to_s; Singleton is the owner of to_s\r\n5. Spy::Collection doesn't find that the spy is logged\r\n6. Wrap strategy is used redefining the method on the singleton\r\n7. Spy called with to_s; Singleton is still the owner of to_s\r\n8. Spy::Collection finds the Spy::Collection::Entry and raises AlreadySpiedError"}}