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

Already on GitHub? Sign in to your account

lambda / expect with AR proxy #411

sbounmy opened this Issue Jul 8, 2011 · 4 comments


None yet
4 participants

sbounmy commented Jul 8, 2011

Having an issue while comparing activerecord association using lambda / expect.

This spec is failing :

lambda { do_something_that_change_the_ar_proxy }.should change(user, :friend_lists).from([existing_fl]).to([new_fl])
# result should have changed, but is still [new_fl]

Whereas this one is passing :

user.friend_lists.should == [existing_fl]
user.friend_lists.should == [new_fl]

Found this thread but I am not sure if this issue is solved or not : http://www.ruby-forum.com/topic/166936


dchelimsky commented Oct 5, 2011

This is related to rspec/rspec-expectations#41, which was fixed for Array and Hash, but not AssociationProxy (since that is rails-specific). I see two ways to address this:

  1. override the change matcher in rspec-rails
  2. update the change matcher in rspec-expectation to check for Enumerable (or something else equally general).



myronmarston commented Oct 5, 2011

I like options 2. I can't think of any downsides to applying the duping logic to Enumerable, and it's always good to make code more general rather than more specific.


justinko commented Oct 5, 2011

And you can even change this line to when Enumerable


dchelimsky commented Oct 6, 2011

Fixed in rspec-expectations: rspec/rspec-expectations@ea01a6f

@dchelimsky dchelimsky closed this Oct 6, 2011

kchien pushed a commit to kchien/rspec-expectations that referenced this issue Mar 7, 2014

Change matcher dups Enumerable before the action, supporting custom
Enumerable types like CollectionProxy in Rails.

- Closes rspec/rspec-rails#411
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment