Ruby on rails 轨道:黄瓜不清洁DB

Ruby on rails 轨道:黄瓜不清洁DB,ruby-on-rails,cucumber,spork,Ruby On Rails,Cucumber,Spork,我在cucumber和数据库事务方面遇到了一些问题——特别是,当我运行测试套件时,数据库事务在之后不会被清理 我正在用spork和postgres运行rails 3.1 最初,features/support/env.rb设置为使用database_cleaner,但每次调用db时都会出现以下错误: 没有指定数据库。缺少参数:数据库。(错误) /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active\

我在cucumber和数据库事务方面遇到了一些问题——特别是,当我运行测试套件时,数据库事务在之后不会被清理

我正在用spork和postgres运行rails 3.1

最初,features/support/env.rb设置为使用database_cleaner,但每次调用db时都会出现以下错误:

没有指定数据库。缺少参数:数据库。(错误) /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active\u record/connection\u adapters/postgresql\u adapter.rb:22:in
postgresql\u connection'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:292:in
new\u connection' /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:302:in
checkout\u new\u connection'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:254:in
block(2层)in checkout' /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:250:in
loop'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:250:in
block in checkout' /Users/john/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in
mon\u synchronize'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:249:in
checkout' /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:151:in
connection'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:388:in
retrieve\u connection' /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active\u record/connection\u adapters/abstract/connection\u specification.rb:107:in
retrieve\u connection'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-rails-1.0.2/lib/cucucumber/rails/hooks/active_record.rb:7:in
connection' /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database\u cleaner-0.6.7/lib/database\u cleaner/active\u record/transaction.rb:17:in
clean'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database\u cleaner-0.6.7/lib/database\u cleaner/base.rb:77:in
clean' /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database\u cleaner-0.6.7/lib/database\u cleaner/configuration.rb:56:in
block in clean'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database\u cleaner-0.6.7/lib/database\u cleaner/configuration.rb:56:in
each' /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database\u cleaner-0.6.7/lib/database\u cleaner/configuration.rb:56:in
clean'
/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-rails-1.0.2/lib/cucucumber/rails/hooks/database_cleaner.rb:9:in
After'

我试着恢复正常交易,但没有任何乐趣。我可以通过控制台(cucumber环境)访问数据库,并可以毫无问题地创建/删除/检索记录。下面添加了config/database.yml、features/support/env.rb、config/environments/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
CONFIG/ENVIRONMENTS/CUCUMBER.RB

BusinessschoolCorporate::Application.configure do#设置 此处指定的将优先于中指定的 config/application.rb

#测试环境专门用于运行应用程序的

测试套件。否则,你永远不需要使用它。记得 您的测试数据库是测试套件和 在测试运行之间被擦除并重新创建。不要依赖这些数据 那里
config.cache_classes=true
config.use\u transactional\u fixtures=true

#为测试配置静态资产服务器,并为其配置缓存控制 performance config.service\u static\u assets=true
config.static\u cache\u control=“public,max age=3600”

#在意外调用nil上的方法时记录错误消息
config.whiny_nils=true

#显示完整的错误报告并禁用缓存
config.consive_all_requests_local=true
config.action\u controller.perform\u caching=false

#引发异常而不是呈现异常模板
config.action\u dispatch.show\u exceptions=false

#在测试环境中禁用请求伪造保护
config.action\u controller.allow\u forgery\u protection=false

#告诉Action Mailer不要向现实世界发送电子邮件# 测试传递方法将发送的电子邮件累积到# ActionMailer::Base.deliveries数组。
config.action\u mailer.delivery\u method=:test

#在创建 测试数据库如果您的模式不能被修改,这是必要的 完全被模式转储程序转储,就像 约束或特定于数据库的列类型# config.active\u record.schema\u format=:sql

#将弃用通知打印到stderr
config.active\u support.deprecation=:stderr end

SPEC/SPEC_HELPER.RB

需要“rubygems”需要“spork”

Spork.prefork do#在此块中加载更多内容将导致您的测试失败 跑得更快。但是,如果您更改任何配置或代码 从这里加载的库中,您需要重新启动spork 生效运行“rails”时,此文件将复制到spec/中 生成rspec:安装'ENV[“RAILS_ENV”]| |='test'需要
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
# Remove this line if you're not using ActiveRecord or
# If you're not using ActiveRecord, or you'd prefer not to run