5

パラメータやその他のものを含むテーブルがいくつかありますが、変更されることはありません。

しかし、このデータを保持するようにdatabase_cleanerに指示することはできません。各テストの後で、すべてのデータベースが切り捨てられます。

宝石

gem "cucumber-rails", "~> 1.3.0", require: false
gem 'factory_girl_rails'
gem 'database_cleaner'

Config / cucumber.yml

enter code here
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'}     features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
%>
default: <%= std_opts %> features
wip: --tags @wip:3 --wip features
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip

機能/サポート/環境

require 'cucumber/rails'
require 'database_cleaner'
require 'database_cleaner/cucumber'
require 'factory_girl_rails'

Capybara.default_selector = :css
ActionController::Base.allow_rescue = false

begin
  DatabaseCleaner.logger = Rails.logger
  DatabaseCleaner.clean_with(:truncation, :except => %w[regions departements villes positions levels footballtypes genders publicies types])
  DatabaseCleaner.strategy = :truncation, {:except => %w[regions departements villes positions levels footballtypes genders publicies types]}
rescue NameError
  raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

Cucumber::Rails::World.use_transactional_fixtures = false
Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
  DatabaseCleaner.clean_with(:truncation, :except => %w[regions departements villes positions levels footballtypes genders publicies types])
  DatabaseCleaner.strategy = :truncation, {:except => %w[regions departements villes positions levels footballtypes genders publicies types]}
end

Before do
  DatabaseCleaner.strategy = :truncation, {:except => %w[regions departements villes positions levels footballtypes genders publicies types]}
  DatabaseCleaner.clean_with(:truncation, :except => %w[regions departements villes positions levels footballtypes genders publicies types])
  DatabaseCleaner.start
end

After do |scenario|
  DatabaseCleaner.clean_with(:truncation, :except => %w[regions departements villes positions levels footballtypes genders publicies types])
  DatabaseCleaner.strategy = :truncation, {:except => %w[regions departements villes positions levels footballtypes genders publicies types]}
  DatabaseCleaner.clean
end

手がかりはありますか?ありがとう、ネルソン

4

2 に答える 2

0

上に貼り付けたコード (env.rb) で最初に問題になるのは、すべての重複です。database_cleaner を使用する場合、これを行う必要はありませんでした。ファイルを次のように単純化するとどうなるでしょうか。

require 'cucumber/rails'
require 'database_cleaner'
require 'database_cleaner/cucumber'
require 'factory_girl_rails'

Capybara.default_selector = :css
ActionController::Base.allow_rescue = false
Cucumber::Rails::World.use_transactional_fixtures = false


DatabaseCleaner.logger = Rails.logger
DatabaseCleaner.strategy = :truncation, {:except => %w[regions departements villes positions levels footballtypes genders publicies types]}

Before do
  DatabaseCleaner.start
end

After do |scenario|
  DatabaseCleaner.clean
end

これは、私が過去に行ったことや、私が見た仕事に非常に近いものです。

于 2012-05-26T14:05:53.533 に答える