You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it"RR should raise 'unexpected method invocation' error"do# @article: an article objectmock(@article.blog).name{"A Blog"}@article.blog.name.should == "A Blog"# This works.@article.blog.url.should == "http://original.url.com"# Invokes original method. Good.@article.blog.url# RR raises 'unexpected method invocation' unexpectedly here!!end
It seems that RR doesn't like ActiveRecord::Associations::AssociationProxy which proxies activerecord object of the association through method_missing like bellow:
I can confirm this is still an issue with 1.4.0 / my fork:
require'rr'require'rspec/core'require'rspec/expectations'RSpec.configuredo |c|
c.mock_with:nothingend# The ProxySample class imitates AssociationProxy class in ActiveRecord.classProxySampledefinitialize@model=ModelSample.newenddefmethod_missing(sym,*args,&block)if@model.respond_to?(sym)@model.send(sym, *args, &block)elsesuperendendend# The ModelSample class imitates ActiveRecord::Base class in ActiveRecord.classModelSampledefname"Brian Takita"enddefgithub_id"btakita"endenddescribe"with a proxy class"doincludeRR::Adapters::RSpec2beforedo@proxy=ProxySample.newmock(@proxy).name.times(1){"Mocked!"}endit"mocks properly usually"do@proxy.name.should == "Mocked!"endit"calls an original method if it is not mocked"do@proxy.name.should == "Mocked!"@proxy.github_id.should == "btakita"endit"calls an original method if it is not mocked for the second time too "do@proxy.name.should == "Mocked!"@proxy.github_id.should == "btakita"@proxy.github_id.should == "btakita"endend
Output:
$ ruby -I ~/code/github/forks/rr/lib -S rspec -f documentation /tmp/rr-test.rb
with a proxy class
mocks properly usually
calls an original method if it is not mocked
calls an original method if it is not mocked for the second time too (FAILED - 1)
Failures:
1) with a proxy class calls an original method if it is not mocked for the second time too
Failure/Error: @proxy.github_id.should == "btakita"
RR::Errors::DoubleNotFoundError:
On subject #<ProxySample:0x007ffa22342cd0>,
unexpected method invocation:
github_id()
expected invocations:
# /tmp/rr-test.rb:60:in `block (2 levels) in <top (required)>'
Finished in 0.0044 seconds
3 examples, 1 failure
Failed examples:
rspec /tmp/rr-test.rb:57 # with a proxy class calls an original method if it is not mocked for the second time too
If you have ActiveRecord classes (rails 2.x) like the following:
Then if you have a spec like this:
It seems that RR doesn't like ActiveRecord::Associations::AssociationProxy which proxies activerecord object of the association through method_missing like bellow:
I wrote a spec which reproduces this issue on my forked repo. Could you have a look?
ono@70d8174
The text was updated successfully, but these errors were encountered: