I find the .and
method very useful for chaining many expectations.
expect {
click_button 'Update Boilerplate'
@boilerplate_original.reload
} .to change { @boilerplate_original.title }.to('A new boilerplate')
.and change { @boilerplate_original.intro }.to('Some nice introduction')
Is there something that let's me check for no change?
.and_not change { @boilerplate_original.intro }
Something like that? I couldn't find anything, and it's hard to search on Google for something like "and not".
No, there is no and_not
and no general negation operator, as discussed in https://github.com/rspec/rspec-expectations/issues/493
There is, however, a mechanism to define a negated version of an existing matcher, as described in http://www.rubydoc.info/github/rspec/rspec-expectations/RSpec/Matchers.define_negated_matcher, which you can use with and
.
The full set of compound matchers is documented at https://www.relishapp.com/rspec/rspec-expectations/v/3-4/docs/compound-expectations
If you are trying to assert that some operation should not change a count, you could do
expect { something }.to change { Foo.count }.by(1).and change { Bar.count }.by(0)
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