Just do IT

思うは招く

RSpec で undefined local variable or method パス名 for RSpec::ExampleGroups::Nested:Class エラー

問題

さくっと確かめたいことがあり、system specがまず動くかどうかのスペックを書いた。実行すると以下のエラーがでた。

undefined local variable or method `new_user_session_path' for RSpec::ExampleGroups::Nested:Class

コードはこちら。

RSpec.describe "ユーザー登録", type: :system do
    visit new_user_registration_path
    expect(page).to have_http_status :ok
end

解決

itで囲っていないのが原因だった。

RSpec.describe "ユーザー登録", type: :system do
  it "登録" do
    visit new_user_registration_path
    expect(page).to have_http_status :ok
  end
end

そもそもRSpecが動いてるかどうかのテストを書いてよかった。小さくテストをしたら、エラーの原因の範囲が絞られるので解明しやすい。