9
4

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 5 years have passed since last update.

Rspec changeでnilから何らかの値に変化することをテストする

Posted at

テストの前後で値がnilから何らかの値に変化することを確認したい。だけど具体的な値はわからない(スタブするのも面倒)という場合には以下のように書ける。

    describe '#set_token' do
      subject { user.set_token }

      it 'tokenに値が設定されること' do
        expect { subject }.to change(user, :token).from(nil).to(String)
      end
    end
9
4
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
9
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?