Deviseで作成したフォームにRSpecでテストしようとしています。
以下のようなエラーが出て困っております。どのようにしたら直りますでしょうか?
ご教示頂ければ幸いです。
bash
1$ bin/rspec 2Running via Spring preloader in process 18113 3/Users/noriakitakamizawa/xxx/spec/controller/test_login_spec.rb:3:in `<top (required)>': uninitialized constant TestLoginController (NameError) 4 from /Users/noriakitakamizawa/xxx/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1435:in `block in load_spec_files' 5 from /Users/noriakitakamizawa/xxx/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `each' 6 from /Users/noriakitakamizawa/xxx/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `load_spec_files' 7
テストコードはこちらです。
spec/controller/test_login_spec.rb
ruby
1require 'rails_helper' 2 3describe TestLoginController do 4 login_admin 5 6 it "should have a current_user" do 7 # note the fact that you should remove the "validate_session" parameter if this was a scaffold-generated controller 8 expect(subject.current_user).to_not eq(nil) 9 end 10 11 it "should get index" do 12 # Note, rails 3.x scaffolding may add lines like get :index, {}, valid_session 13 # the valid_session overrides the devise login. Remove the valid_session from your specs 14 get 'index' 15 response.should be_success 16 end 17end
spec/rails_helper.rb
ruby
1ENV['RAILS_ENV'] ||= 'test' 2require File.expand_path('../../config/environment', __FILE__) 3abort("The Rails environment is running in production mode!") if Rails.env.production? 4require 'spec_helper' 5require 'rspec/rails' 6require 'devise' 7require 'rspec/autorun' 8 9Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } 10ActiveRecord::Migration.maintain_test_schema! 11 12RSpec.configure do |config| 13 config.include Devise::Test::ControllerHelpers, :type => :controller 14 15 # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 16 config.fixture_path = "#{::Rails.root}/spec/fixtures" 17 18 # If you're not using ActiveRecord, or you'd prefer not to run each of your 19 # examples within a transaction, remove the following line or assign false 20 # instead of true. 21 config.use_transactional_fixtures = true
spec/spec_helper.rb
ruby
1ENV["RAILS_ENV"] ||= 'test' 2require File.expand_path("../../config/environment", __FILE__) 3 4require 'rspec/rails' 5require 'rspec/autorun' 6require 'capybara/rails' 7require 'devise' 8Rails.logger = Logger.new(STDOUT) 9 10RSpec.configure do |config| 11 config.include Rails.application.routes.url_helpers 12 config.include Capybara::DSL 13 14 # for Devise 15 #config.include Devise::TestHelpers, :type => :controller 16 #config.include Capybara::DSL 17 config.include Devise::Test::ControllerHelpers, :type => :controller
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/11 00:00