Is it possible for RSpec to expect change in two tables?

后端 未结 8 1551
借酒劲吻你
借酒劲吻你 2020-12-09 07:15

RSpec expect change:

it \"should increment the count\" do
  expect{Foo.bar}.to change{Counter.count}.by 1
end

Is there a way to expect chan

8条回答
  •  天命终不由人
    2020-12-09 08:03

    Georg Ladermann's syntax is nicer but it doesn't work. The way to test for multiple value changes is by combining the values in arrays. Else, only the last change assertion will decide on the test.

    Here is how I do it:

    it "should increment the counters" do
      expect { Foo.bar }.to change { [Counter.count, AnotherCounter.count] }.by([1,1])
    end
    

    This works perfectecly with the '.to' function.

提交回复
热议问题