質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
RSpec

RSpecはRuby用のBDD(behaviour-driven development)フレームワークです。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

1152閲覧

【RSpec】Helperでのエラー

karirin3948

総合スコア20

RSpec

RSpecはRuby用のBDD(behaviour-driven development)フレームワークです。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2020/04/12 05:46

お世話になっております。
下記の現象で知見がある方がいらっしゃいましたらご教示お願いします。

#起きているエラー

: An error occurred while loading rails_helper. Failure/Error: config.include TestHelper NameError: uninitialized constant TestHelper :

TestHelperを使用してテストをRSpecを実行したいのですが初期化されていないとのエラーが発生します。

#今回のエラーに至るまで
rails_helper.rbtest_helper.rbへ紐付けの記述を行いました。

#rails_helper.rb Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } : RSpec.configure do |config| : config.include TestHelper :
#test_helper.rb module TestHelper def is_logged_in? !session[:user_id].nil? end end

#試したこと
config.includeの記載の仕方を変えましたがエラーは直りませんでした。

#rails_helper.rb config.include TestHelper #修正前 ↓ config.include(TestHelper) #修正後

#関連ファイル
###rails_helper.rb

require 'spec_helper' ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../config/environment', __dir__) abort("The Rails environment is running in production mode!") if Rails.env.production? require 'rspec/rails' Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } begin ActiveRecord::Migration.maintain_test_schema! rescue ActiveRecord::PendingMigrationError => e puts e.to_s.strip exit 1 end RSpec.configure do |config| config.include FactoryBot::Syntax::Methods config.include TestHelper config.fixture_path = "#{::Rails.root}/spec/fixtures" config.use_transactional_fixtures = true config.infer_spec_type_from_file_location! config.filter_rails_from_backtrace! end Shoulda::Matchers.configure do |config| config.integrate do |with| with.test_framework :rspec with.library :rails end end

###test_helper.rb

module TestHelper def is_logged_in? !session[:user_id].nil? end end

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問