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

后端 未结 8 1563
借酒劲吻你
借酒劲吻你 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 07:59

    If you don't want to use the shorthand/context based approach suggested earlier, you can also do something like this but be warned it will run the expectation twice so it might not be appropriate for all tests.

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

提交回复
热议问题