Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4610

Can you simultaneously test a state change and a return value in RSpec?

$
0
0

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?


Viewing all articles
Browse latest Browse all 4610

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>