Pla*_*Ton 5 ruby-on-rails cucumber spork
我在黄瓜和数据库事务方面遇到了一些问题 - 具体来说,当我运行测试套件时,之后不会清理数据库事务.
我正在使用spork,postgres运行rails 3.1.
最初feature/support/env.rb设置为使用database_cleaner,但在每次调用db时始终出现以下错误:
没有指定数据库.缺少参数:数据库.(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:incheckout_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级)结账时'/ 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: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:inin 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:inconnection' /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:inretrieve_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 /反 action.rb:17:inclean' /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.6.7/lib/database_cleaner/base.rb:77:incleanblock in clean' /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.6.7/lib/database_cleaner/configuration.rb:56:in'/Users/ john/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.6.7/lib/database_cleaner/configuration.rb:56:in each'/ Users /john/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.6.7/lib/database_cleaner/configuration.rb:56:inclean' /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-rails-1.0.2/lib/cucumber/rails/hooks/database_cleaner.rb:9:in'之后'
我试过恢复常规交易,但没有快乐.我可以通过控制台(黄瓜环境)访问数据库并创建/删除/检索记录没有问题.下面添加了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
Run Code Online (Sandbox Code Playgroud)
特点/技术支持/ 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
Run Code Online (Sandbox Code Playgroud)
CONFIG /环境中/ CUCUMBER.RB
BusinessschoolCorporate :: Application.configure do#此处指定的设置将优先于config/application.rb中的设置
#测试环境专门用于运行应用程序
测试套件.否则你永远不需要使用它.记得
#您的测试数据库是测试套件的"临时空间"并被擦除#并在测试运行之间重新创建.不要依赖那里的数据!
config.cache_classes = true
config.use_transactional_fixtures = true#为具有Cache-Control的测试配置静态资产服务器以获得性能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不要向现实世界发送电子邮件.#:test delivery方法在#ActionMailer :: Base.deliveries数组中累积已发送的电子邮件.
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做#在此块中加载更多将导致您的测试运行得更快.但是,#如果您从此处加载的库中更改任何配置或代码,您将需要重新启动spork才能生效.#这个文件被复制到spec /当你运行'rails generate rspec:install'ENV ["RAILS_ENV"] || ='test'需要File.expand_path("../../ config/environment",FILE)require "RSpec的/ Rails的
#需要使用自定义匹配器和宏等支持ruby文件,#spec/support /及其子目录.
Dir [Rails.root.join("spec/support/*/ .rb")].每个{| f | 要求f}RSpec.configure do | config | #==模拟框架##如果您更喜欢使用mocha,flexmock或RR,请取消注释相应的行:## config.mock_with:mocha#config.mock_with:flexmock#config.mock_with:rr config.mock_with:rspec
Run Code Online (Sandbox Code Playgroud)# Remove this line if you're not using ActiveRecord orActiveRecord fixtures#config.fixture_path ="#{:: Rails.root}/spec/fixtures"
Run Code Online (Sandbox Code Playgroud)# If you're not using ActiveRecord, or you'd prefer not to run在事务中的每个#example,删除以下行或指定false#而不是true.config.use_transactional_fixtures =真结束
结束
Spork.each_run do#每次运行规范时都会运行此代码.
结束
| 归档时间: |
|
| 查看次数: |
2178 次 |
| 最近记录: |