not_to change.by() is not supported
Asked Answered
M

1

29

I upgraded rspec version from 2 to 3. This is one of the issues I faced:

Failures:

  1) Slide after .destroy(force: false) visible if .with_deleted
     Failure/Error: expect{@slide.destroy(force: false)}.to_not change(Slide.with_deleted, :count).by(1)
     NotImplementedError:
       `expect { }.not_to change { }.by()` is not supported
     # ./spec/models/slide_spec.rb:36:in `block (3 levels) in <top (required)>'

and in the rspec's changelog I can read it was never supported (oink ?!@#). At the same time there are still some examples how to use change syntax but without not keyword.

So the question is how to expect no change ?

Mercurochrome answered 12/8, 2014 at 15:8 Comment(0)
M
64

Fortunately I want to expect no change (any) so I can omit by() part. It works just fine !

  expect{@slide.destroy(force: false)}.to_not change(Slide.with_deleted, :count)
Mercurochrome answered 12/8, 2014 at 16:37 Comment(1)
Just for the sake of explanation, the problem is at .by(n). I found this answer and didn't understand why this happen. If anyone else have the same problem: the reason is that to_not change means don't change at all, so by is wrong. Other solution could be to change.by(0)Closefisted

© 2022 - 2024 — McMap. All rights reserved.