スペック間でデータベースをクリーンアップしようとしています。そこで、人気の gem database_cleaner を使用することにしました。ここでの問題は、FactoryGirl でモデルの新しいインスタンスを作成すると、作成されてもページに表示されないことです。
これが私のspec_helperです:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rails'
require 'capybara/rspec'
require 'factory_girl_rails'
require 'pry'
require 'database_cleaner'
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.include FactoryGirl::Syntax::Methods
config.order = :random
Kernel.srand config.seed
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each, type: :feature) { DatabaseCleaner.strategy = :truncation }
config.before { DatabaseCleaner.start }
config.after { DatabaseCleaner.clean }
end
そして、私が実行しようとしている簡単なテストは次のとおりです。
require 'spec_helper'
feature 'designs' do
feature 'editing designs' do
before(:each) { visit designs_path}
given!(:design){ create(:design)}
scenario "from the designs index" do
binding.pry
expect(page).to have_content("Ninja Crane")
end
end
end
binding.pry を使ってデザインの数を確認し、ページを表示します。その結果、デザインは正しく作成されていますが、ページに表示されていません。
前もって感謝します!