0
0

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.

【RSpec】let!で定義した値がnilを返す現象

Posted at

テストを書いていてlet!で定義した値がなぜかnilで返ってくる現象に時間をとられたので
もう引っかからないようにまとめる。

##テスト失敗
pryでデバッグしたところcat_countがnil

spec.rb
describe 'cat_countテスト' do
  let!(:cat_count) { 2 }
  it '1が足されること' do
    #binding.pry
    cat_count += 1
    expect(cat_count).to eq 3
  end
end
 NoMethodError:
       undefined method `+' for nil:NilClass

##原因
(近日更新予定)

##テスト成功

spec.rb
describe 'cat_countテスト' do
  it '1が足されること' do
    cat_count = 2
    cat_count += 1
    expect(cat_count).to eq 3
  end
end
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?