lulalala
lulalala

Reputation: 17991

RSpec how to have should_receive check for call but let it run

In my RSpec I have:

discount.should_receive(:ended=).with(true)

In my model I have:

self.ended = document.at_css('#buy_now').blank?
  if not ended?
    ...

I want to check the ended= is called, but my spec would check it is called and then skip the actual update so the ended is not set properlyl.

I want it to actually run so subsequent logic would run correctly. Is there a way to do this, elegantly if possible?

Upvotes: 1

Views: 511

Answers (1)

Brian Bice
Brian Bice

Reputation: 316

You could use an expect change to verify that ended was updated properly without preventing the actual update.

expect {
  # code which changes ended to true
}.to change(discount, :ended).from(false).to(true)

https://www.relishapp.com/rspec/rspec-expectations/v/2-0/docs/matchers/expect-change

Upvotes: 1

Related Questions