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 ?

pawel7318
  • 3,383
  • 2
  • 28
  • 44

1 Answers1

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)
pawel7318
  • 3,383
  • 2
  • 28
  • 44
  • 18
    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)` – Nicos Karalis Jul 16 '15 at 16:14