I'm trying to make sure certain data has remain unchanged by a single action:
expect {
# running migration and user reload here
}.not_to change(user, :avatar_url).from(sample_avatar_url).and change(user, :old_avatar).from(nil)
sample_avatar_url
is a string defined in the beginning of the spec file.
Basically, I want to check whether the avatar_url
and old_avatar
remain untouched by what's happening in the expect
block.
The output from the above code is:
expect(...).not_to matcher.and matcher
is not supported, since it creates a bit of an ambiguity. Instead, define negated versions of whatever matchers you wish to negate withRSpec::Matchers.define_negated_matcher
and useexpect(...).to matcher.and matcher
.
This doesn't work because it's not clear reading whether thats supposed to mean not change the first and not change the second, or not change the first but change the second. You have a couple of options to get around this
Since you're checking static values just don't use change
..run migration and user reload..
expect(user.avatar_url).to eq(sample_avatar_url)
expect(user.old_avatar).to eq nil
or use define_negated_matcher to create a not_change matcher
RSpec::Matchers.define_negated_matcher :not_change, :change
expect {
# running migration and user reload here
}.to not_change(user, :avatar_url).from(sample_avatar_url).and not_change(user, :old_avatar).from(nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With