Expecting multiple changes (chaining)

Hi RSpec list,

I have a question about the “expect { … }.to change” construct
(https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/expect-change):

Is there an idiomatic way to test for multiple changes (i.e. chaining)?

Right now I’m doing

expect {
  expect {
    foobuzz
  }.to change { a }
}.to change { b }

to test that calling foobuzz changes a and b. Is there a more compact
way?

(Using tap turns out rather ugly: .tap { |proc| proc.to change { a }
}. Not an improvement IMO.)

Thanks,
Jo

On Thu, Dec 8, 2011 at 3:30 PM, Jo Liss [email protected] wrote:

expect {
foobuzz
}.to change { a }
}.to change { b }

to test that calling foobuzz changes a and b. Is there a more compact way?

If there are two outcomes, then I like to write two examples:

it “changes a” do
expect { foobuzz }.to change {a}
end

it “changes b” do
expect { foobuzz }.to change {b}
end

HTH,
David