How do I `expect` something which raises exception in RSpec?
You could use the "rescue nil" idiom to shorten what you already have:
it { expect { eat(what: nil) rescue nil }.not_to change(cat, :status) }
You can chain positive assertions with and
. If you want to mix in a negated one in the chain, RSpec 3.1 introduced define_negated_matcher
.
You could do something like:
RSpec::Matchers.define_negated_matcher :not_change, :change
expect { eat(what: nil) }
.to raise_error
.and not_change(cat, :status)
Inspired by this comment.