Help us understand the problem. What is going on with this article?

Rspec | subject にラムダを使う ( expect でブロックを使う場合の is_expected の書き方 )

More than 3 years have passed since last update.

expect を ブロックで囲わなければいけない検証の場合。

it { expect { some_action }.to change { some_status } }

普通に subject / is_expected を書こうとすると落ちる

subject { some_action }
it { is_expected.to change { some_status } }

ラムダを使えば解決。

subject { -> { some_action } }
it { is_expected.to change { some_status } }

環境

  • rspec 3.4.0
YumaInaura
Ruby on Rails 業務経験 約5年 / Perl PHP Python Golang Linux Apache MySQL BigQuery Jenkins ansible AWS など / いなうらゆうま / YumaInaura / 稲浦悠馬
http://twitter.com/yumainaura
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away