I had problems with the cucumber and database transactions - in particular, when I run the test suite, the database transactions are not cleared after that.
I am running rails 3.1 with spork, postgres.
The functions /support/env.rb were originally set to use database_cleaner, but they received the following error in sequence with each db call:
No database specified. Missing argument: database. (ArgumentError) /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:22:in postgresql_connection'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:innew_connection '/ Users / john /.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:302:in checkout_new_connection'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:254:inblock (2 levels) in the ordering '/ Users /john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:50:in loop'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:250:inblock in checkout '/ Users / john / .rvm / rubies / ruby-1.9.2-p290 / lib / ruby / 1.9.1 / monitor.rb: 201: inmon_synchronize'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:249:incheckout '/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:151:in connection'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:388:inretrieve_connection' / Users / john / .rvm / gems / ruby-1.9.2-p290 / gems / activerecord-3.1.0.rc4 / lib / active_record / connection_adapters / abstract / connection_specification.rb: 107: in retrieve_connection'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-rails-1.0.2/lib/cucumber/rails/hooks/active_record.rb:7:inconnection '/Users/john/.rvm/ gems / ruby-1.9.2-p290 / gems / database_cleaner-0.6.7 / lib / database_cleaner / active_record / transaction.rb: 17: in clean'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.6.7/lib/database_cleaner/base.rb:77:inclean '/Users/john/.rvm/gems/ruby-1.9.2-p290 /gems/database_cleaner-0.6.7/lib/database_cleaner/configuration.rb:56:in block in clean'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.6.7/lib/database_cleaner/configuration.rb:56:ineach '/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.6.7/lib/ database_cleaner / configuration.rb: 56: in clean'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-rails-1.0.2/lib/cucumber/rails/hooks/database_cleaner.rb:9:inAfter
, . ( ) // . config/database.yml, features/support/env.rb, config/environment/cucumber.rb rspec/spec_helper.rb. , , - :
CONFIG/database.yml
default: &defaults
adapter: postgresql
username: rails_dev
password: foobar
development:
<<: *defaults
database: fcct_d
test: &test
<<: *defaults
database: fcct_t
production:
<<: *defaults
database: fcct_p
username: fcct
password: k#1*5Avb3dTa
cucumber:
adapter: postgresql
username: rails_dev
password: foobar
database: fcct_t
//ENV.RB
require 'rubygems'
require 'spork'
Spork.prefork do
require 'cucumber/rails'
require 'database_cleaner'
require 'database_cleaner/cucumber'
Capybara.default_selector = :css
ActionController::Base.allow_rescue = false
begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
end
Spork.each_run do
require 'factory_girl'
require File.join(File.dirname(__FILE__), '../../lib/existing_factory/existing_factory.rb')
end
CONFIG//CUCUMBER.RB
BusinessschoolCorporate:: Application.configure do # , /application.rb
#
. .
# - " " # . !
config.cache_classes = true
config.use_transactional_fixtures = true
# Cache-Control performance config.serve_static_assets = true
config.static_cache_control = "public, max-age = 3600"
# nil config.whiny_nils = true
#
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
#
config.action_dispatch.show_exceptions = false
#
config.action_controller.allow_forgery_protection = false
# Action Mailer, . # : # ActionMailer:: Base.deliveries array.
config.action_mailer.delivery_method =: test
# SQL Active Record . # , , # , # config.active_record.schema_format =: sql
# stderr
config.active_support.deprecation =: stderr end
SPEC/SPEC_HELPER.RB
, "rubygems" "spork"
Spork.prefork do # . , # spork . # spec/ 'rails rspec: 'ENV [ "RAILS_ENV" ] || =' test 'require File.expand_path ( "../../config/environment", FILE) 'RSpec/'
# , etc, # spec/support/ .
Dir [Rails.root.join( "spec/support/*/. Rb" )]. {| f | f}
RSpec.configure do | config | # == Mock Framework # # mocha, flexmock RR, : # # config.mock_with: mocha # config.mock_with: flexmock # config.mock_with: rr config.mock_with: rspec
# Remove this line if you're not using ActiveRecord or
ActiveRecord # config.fixture_path = "# {:: Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run
# , false # true. config.use_transactional_fixtures = true end
Spork.each_run do # , .