私は初心者ですが、私はcapybaraで "edit user"という機能をテストしようとしていますが、ここでCapybaraのフィーチャーテスト:アフターフックでエラーが発生しましたActiveRecord :: RecordNotFound:
An error occurred in an after hook
ActiveRecord::RecordNotFound: Couldn't find User with 'id'=
occurred at /var/lib/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/core.rb:155:in `find'
は私のテストコードです:
context 'when wrong parameters' do
scenario 'checkout name is mandatory' do
fill_in 'name', with: ''
fill_in 'email', with: ''
3.times { wait_for_ajax }
click_button '保存'
expect(page).to have_current_path('/users/1')
expect(page).to have_content 'お名前を入力してください'
end
そして、ここでは私のspec_helper.rbとrails_helper.rbは
require 'factory_girl_rails'
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
end
ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'shoulda/matchers'
require 'support/authentication_helper'
require 'capybara'
require 'support/wait_helper'
require 'rake'
require 'support/feature_testing_functions_helper'
Rails.application.load_tasks
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
config.include FactoryGirl::Syntax::Methods
config.include Devise::Test::ControllerHelpers, type: :controller
config.include AuthenticationHelper
config.include Capybara::DSL, type: :feature
config.include Capybara::RSpecMatchers, type: :feature
config.include WaitHelper, type: :feature
config.include FeatureTestingFunctions, type: :feature
Capybara.default_driver = :webkit
config.before :suite do
Rake::Task['db:drop'].invoke
Rake::Task['db:setup'].invoke
end
config.after :each do
Capybara.reset_sessions!
end
end
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
です
このエラーがなぜ発生したのかわかりませんが、これをトラブルシューティングする方法についてアドバイスはありますか?
問題についてのご意見やご感想をお寄せいただきありがとうございます。 "ActiveRecord :: RecordNotFound: 'id' ="のユーザーを見つけることができませんでした。ここでidは1に等しくなければならないが、等号の後に空白がある。それはなぜここに空ですか? –
@ABあなたはユーザーを作成している場所(または訪問している場所)を表示していませんが、アプリコードでユーザーを見ることができない答えが#1ですトランザクション・データベースのテストのためにテスト・コードで作成したものです。あるいは、ユーザーを作成するのではなく、ビルドするためです。 –