rake cucumber 和 cucumber --tag @tagname 给出不同的结果
如果我使用 rake cucumber ,则不会加载固定装置,并且我的测试会失败。如果我使用 cucumber --tag @tagname 来运行一个场景,它会加载固定装置、工厂,并且一切都会通过。
我的 /features/support/env.rb
的底部如下所示:
Cucumber::Rails::World.use_transactional_fixtures = true
Fixtures.reset_cache
fixtures_folder = File.join(RAILS_ROOT, 'spec', 'fixtures')
fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f| File.basename(f, '.yml') }
Fixtures.create_fixtures(fixtures_folder, fixtures)
if defined?(ActiveRecord::Base)
begin
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
rescue LoadError => ignore_if_database_cleaner_not_present
end
end
其他一切都是相当标准的 Rails 3。
If I use rake cucumber
the fixtures are not loaded and my tests fail. If I use cucumber --tag @tagname
to run a scenario it loads fixtures, factories, and everything passes.
The bottom of my /features/support/env.rb
looks like this:
Cucumber::Rails::World.use_transactional_fixtures = true
Fixtures.reset_cache
fixtures_folder = File.join(RAILS_ROOT, 'spec', 'fixtures')
fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f| File.basename(f, '.yml') }
Fixtures.create_fixtures(fixtures_folder, fixtures)
if defined?(ActiveRecord::Base)
begin
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
rescue LoadError => ignore_if_database_cleaner_not_present
end
end
Everything else is fairly standard Rails 3.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我必须更改这一行:
我需要加载所有这些表才能通过测试,但 DatabaseCleaner 在每个场景后都会截断它们。
I had to change this line:
I needed all of those tables loaded for the tests to pass but DatabaseCleaner was truncating them after each scenario.