6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

#Rails + #rspec の change 記法で model のインスタンスを検証する時、うまくいかないときは reload を挟めば良いじゃない

Last updated at Posted at 2019-10-20

こんなノリ

subject { change_name! }
let!(:user) { create :user }

it { expect { subject }.to change { user.reload.name }.from('Alice').to('Bob')  }

以前は次のようににいみにくい reload を subject の中に挟んでしまっていたが、メソッドチェーンの中に relaod を仕込むほうが良いね

subject { change_name! }
let!(:user) { create :user }

it { expect { subject; user.reload }.to change { user }.from('Alice').to('Bob')  }

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

6
1
0

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
6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?