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

expect { ... }.to change { model.association }.to ... fails when there was a change #2416

Open
pirj opened this issue Dec 13, 2020 · 0 comments

Comments

@pirj
Copy link
Member

pirj commented Dec 13, 2020

  user = User.create!
  expect {
    user.visits << Visit.new(session_id: 1)
  }.to change { user.visits }.to include(have_attributes(session_id: 1))

fails.

It reminds me of rspec/rspec-expectations#1100, since adding to_a makes the spec pass:

change { user.visits.to_a }

I've just scratched the surface, but for some reason in rspec-expectations-3.9.2/lib/rspec/matchers/built_in/change.rb:

@actual_before == @actual_after

and their @before_hash == @actual_after.hash as well.

Seems that the issue is just the opposite to what we've fixed in rspec/rspec-expectations#1100, the hash does not change while contents does change.

What Ruby, Rails and RSpec versions are you using?

Ruby version: 2.5.7
Rails version: 5.2
RSpec version: rspec-expectations 3.9.2, rails-rails 4.0.1

Observed behaviour

Expectation fails:

expected `user.visits` to have changed to include (have attributes {:session_id => 1}), but did not change

Expected behaviour

Spec passes

Can you provide an example app?

A bit later

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

No branches or pull requests

1 participant