LoginSignup
0
1

More than 3 years have passed since last update.

rspec spec時のNameError: undefined local variable or method `config' for main:Objectの対処法

Posted at

rails5中級チュートリアル中のテスト実行時に起こったエラー

エラー文

ターミナル

#rsepc spec 実行時
NameError:
  undefined local variable or method `config' for main:Object

原因と解決

rails_helper.rbへgemメソッドを使えるようにする記述の記述場所が誤っていた。

rails_helper.rb
下記の記述をRSpec.configure do |config|の中に記述していなかったのが原因

  config.include Devise::Test::IntegrationHelpers, type: :feature
  config.include FactoryBot::Syntax::Methods
  Capybara.javascript_driver = :poltergeist
  Capybara.server = :puma

これでもう一度テストを実行すると...

ターミナル
Finished in 0.17382 seconds (files took 5.23 seconds to load)
2 examples, 0 failures

無事成功😆

反省

今回のエラーで1時間ほど時間を食ってしまった。中級チュートリアルの記事をよく見返すと今回の原因が書いてあったので、以後チュートリアルを進める際は、細部まで目を通すことを心がける。

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