I have the thor task, which launches failing tests. I don't like my current approach, so I decided to use direct call to the Cucumber API to perform tests running (it enables highlighting, for example). So, I have such thor task:
lib/tasks/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
When I try to launch this task I recieve the error:
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
This test works normally, when I launch it manually with the bash it the terminal. But when I try to run this test from thor task, it fails. How can I fix that?
Ok, problem was that Thor runs in development
mode by default, not test
. To solve my problem I just needed to set this ENV variable:
RAILS_ENV=test bundle exec thor ...
This helped me. Second hint: make sure in your task, that you are in Test ENV, otherwise you'll lose all your development data. You can check out my article about this task.