10
7

More than 3 years have passed since last update.

RSpec 1つのexpectで複数のchangeを検証する

Last updated at Posted at 2019-10-29

表題通り1つのexpectに対して複数のchangeを検証したい

it '複数のchangeを見るぞ' do
  expect { subject }.to change { x }.by(1).
                    and change { y }.by(2)
end

長くなるし見づらいのであまり使いたくない…

it '複数のchangeの結果だけ見るパターン' do
  # x, y が 1, 2になることだけ確認するbyは使え無さそう
  expect { subject }.to change { [x, y] }.to [1 ,2]
end

参考

ruby on rails - RSpec: Expect to change multiple - Stack Overflow

RSpec3.1からの機能らしい
http://rspec.info/blog/2014/09/rspec-3-1-has-been-released/

※自ブログからの転載です
http://akinov.hatenablog.com/entry/2019/10/29/190642

10
7
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
7