我有Thor任务,它会启动失败的测试。我不喜欢我当前的方法,因此我决定使用直接调用Cucumber API来执行运行测试(例如,它启用突出显示)。所以,我有这样一个任务:
LIB /任务/ parallel.thor
require File.expand_path('config/environment.rb')
require 'cucumber/cli/main'
class Parallel < MyProject::TasksBase
def rerun_with_cucumber
# ...
Cucumber::Cli::Main.new(["@tmp/parallel_cucumber_failures_copy.log"]).execute!
end
end
当我尝试启动此任务时,我收到错误:
Using the default profile...
@javascript @sphinx
Feature: Edit a service
Scenario Outline: Editing # features/service/edit.feature:3
Given I exist as an "individual" # features/step_definitions/user.steps.rb:18
...
Then I should see I18n translation for key "views.services.titles.edit" # features/step_definitions/share.steps.rb:129
And I update form for service and choose price as "<price>" # features/step_definitions/service.steps.rb:295
And I click on I18n translation for key "views.labels.publish" # features/step_definitions/share.steps.rb:54
Then I should see I18n translation for key "views.messages.notices.add.updated" # features/step_definitions/share.steps.rb:129
Examples:
| price |
| fixed |
uninitialized constant FactoryGirl (NameError)
/Users/serj/Projects/my-project/features/support/env.rb:70:in `Before'
uninitialized constant FactoryGirl (NameError)
./features/support/spec_helper.rb:55:in `eval'
(eval):1:in `create_and_init'
./features/support/spec_helper.rb:55:in `eval'
./features/support/spec_helper.rb:55:in `create_and_init'
./features/step_definitions/user.steps.rb:19:in `/^I exist as [a|an]+ "([^\"]*)"$/'
features/service/edit.feature:4:in `Given I exist as an "individual"'
Failing Scenarios:
cucumber features/service/edit.feature:3 # Scenario: Editing
这个测试工作正常,当我用bash手动启动它时终端。但是当我尝试从thor任务运行此测试时,它失败了。我该如何解决这个问题?
答案 0 :(得分:0)
好的,问题是Thor默认以development
模式运行,而不是test
。为了解决我的问题,我只需要设置这个ENV变量:
RAILS_ENV=test bundle exec thor ...
这对我有帮助。第二个提示:在您的任务中确保您处于Test ENV中,否则您将丢失所有开发数据。您可以查看我的article about this task。