Ruby on Rails: Cucumber: how do I turn off the database cleaner?
The system I'm testing is complex enough where writing separated test cases would be a huge waste of time and resources. So, I need my tests to build off each other.
But, for example, whenever I got User.new in one of my step definitions, once the scenario is done, the User is removed from the DB.
How do I keep all my information... unless I force a 开发者_开发技巧db:test:prepare?
This is my env.rb:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
require 'cucumber/rails/world'
require 'cucumber/rails/active_record'
require 'cucumber/web/tableish'
require 'cucumber/rails/rspec'
require 'rake'
require 'capybara/rails'
require 'capybara/cucumber'
require 'capybara/session'
require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript
require 'database_cleaner'
require 'database_cleaner/cucumber'
DatabaseCleaner.strategy = :transaction
@subscription_plan = Factory(:subscription_plan)
@subscription_plan.save!
Capybara.default_selector = :css
Capybara.default_wait_time = 2
Capybara.javascript_driver = :culerity
Capybara.current_driver = :culerity
Capybara.default_host = "cucumber.test.com" #for Rack::Test
Capybara.app_host = "cucumber.test.com" #if Capybara.current_driver == :culerity
Cucumber::Rails::World.use_transactional_fixtures = false
Having your tests build off each other is a terrible idea, because it means each test can't stand on its own, and makes your tests leak state (which gives lots of false test results). If your tests can't start from a clean slate, make them more atomic.
As things stand now, you're not really testing your system properly, judging from your description.
Just remove
gem 'database_cleaner'
from your Gemfile.
And checkout active_record file if NameError
exception occurred.
It is due to silent dependency of cucumber-rails
gem from database_cleaner
gem.
Database Cleaner also includes a null strategy (that does no cleaning at all) which can be used with any ORM library. You can also explicitly use it by setting your strategy to nil.
https://github.com/bmabey/database_cleaner as of Nov 12, 2013
In features/support/env.rb should be a line:
Cucumber::Rails::World.use_transactional_fixtures = true
Set that to false, and your database truncation should cease.
Edit: Since this failed, try adding the tag @no-txn to feature files that require data to persist; it seems like this is a reserved tag used by Cucumber to cause scenarios to not be wrapped in a transaction.
Try with @no-database-cleaner in your feature
The only thing that worked for me was
# features/support/env.rb
# ...
Cucumber::Rails::Database.autorun_database_cleaner = false
It comes from the GitHub README.
精彩评论