Say I have a method MyKlass#do_thing
that I want to call exactly once in a test (because it might change a state), and that should return true
on successful state change and false
otherwise. I want to write a spec that looks something like this:
it "Updates myvalue if condition is met" do wojit = MyKlass.new # ... assuming condition is met expect { wojit.do_thing }.to change { wojit.value }.and.be trueend
But this particular approach gets an ArgumentError, because #and
expects 1 argument.
I can make it work with the following abomination:
expect { expect(wojit.do_thing).to be true }.to change { wojit.value }
But that is hiiiiideous. Am I missing something more idiomatic?