我最近尝试安装Cucumber来补充我的测试环境。我已经让Guard完美地与Spork和Rspec合作。我已经把所有东西都设置好了,现在它已经运行了,包含了Cucumber,但有两件事情看起来有点时髦。
第一期:当Guard运行Cucumber测试时,它会在打印“禁用配置文件...”后暂停约10秒钟。大约10秒后,它会完美地运行测试。 第二期:当我更改我的功能(存储在子目录中,例如/features/users/sign_in.feature)或步骤定义时,guard不会运行测试。为了让我运行测试,我必须手动命中并且Guard继续再次运行所有测试。显然,这违背了守卫的目的。
以下是我的一些代码:
警卫终端输出
ben@ben-K53SV:~/rails_projects/katmeer4$ bundle exec guard
16:51:57 - INFO - Guard is using Libnotify to send notifications.
16:51:57 - INFO - Guard is using TerminalTitle to send notifications.
16:51:57 - INFO - Guard::RSpec is running
16:51:57 - INFO - Running all specs
No DRb server is running. Running in local process instead ...
.....[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
........F....
Failures:
1) User abilities admin Index Page
Failure/Error: it {should have_selector('div', text: 'delete')}
Capybara::ExpectationNotMet:
expected to find css "div" with text "delete" but there were no matches
# ./spec/features/role_spec.rb:38:in `block (5 levels) in <top (required)>'
Finished in 1.18 seconds
18 examples, 1 failure
Failed examples:
rspec ./spec/features/role_spec.rb:38 # User abilities admin Index Page
Randomized with seed 16984
16:52:08 - INFO - Starting Spork for RSpec, Cucumber
Using RSpec, Rails
Using Cucumber, Rails
Preloading Rails environment
Preloading Rails environment
Loading Spork.prefork block...
Loading Spork.prefork block...
Spork is ready and listening on 8990!
Spork is ready and listening on 8989!
16:52:18 - INFO - Spork server for RSpec, Cucumber successfully started
16:52:18 - INFO - Running all features
Disabling profiles...
..
P-
(::) pending steps (::)
features/users/sign_in.feature:9:in `Then I see an invalid login message'
1 scenario (1 pending)
4 steps (1 skipped, 1 pending, 2 passed)
0m0.827s
重要的Guardfile代码
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' },
:rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch('config/environments/test.rb')
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb') { :rspec }
watch('test/test_helper.rb') { :test_unit }
watch(%r{features/support/}) { :cucumber }
end
guard 'cucumber' do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
end
功能性/支撑性/ env.rb
require 'rubygems'
require 'spork'
Spork.prefork do
end
Spork.each_run do
end
require 'cucumber/rails'
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
Cucumber::Rails::Database.javascript_strategy = :truncation
答案 0 :(得分:0)
您忘记将env.rb代码拆分为prefork和each_run块。尝试:
require 'rubygems'
require 'spork'
Spork.prefork do
require 'cucumber/rails'
end
Spork.each_run do
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
Cucumber::Rails::Database.javascript_strategy = :truncation
end