For reasons which have been discussed previously in this forum, there is not a @BeforeAll hook or similar where you can run steps once before all other features.
Instead, I should just put code for it in env.rb.
Before I describe my problem, have a look at my setup:
I have a step like this defined in all feature files:
Background:
Given I log in as testuser10
The step uses capybara/phantomjs:
Given /^I log in as (\w+)$/ do |username|
step "I am not logged in"
visit('/login')
fill_in("username", :with => username)
fill_in("password", :with => LOGIN_PW)
click_button("Logon")
page.should have_content("Authentication successful")
end
And we use cucumber to verify legacy web-app in several environments. For some of these environments, logging in takes up to 5 seconds. In case I could run this step just once, I could shave off 2-3 minutes in our current suite.
My intuition was to run this code directly in env.rb
step "I log in as testuser10"
'
But it fails:
undefined method `step' for main:Object (NoMethodError)
/home/xleap/workspace/core/gitclone/webchannel/test-suite/cucumber/features/support/env.rb:107
/usr/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/rb_support/rb_language.rb:129:in `load'
/usr/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/rb_support/rb_language.rb:129:in `load_code_file'
/usr/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime/support_code.rb:171:in `load_file'
/usr/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime/support_code.rb:83:in `load_files!'
/usr/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime/support_code.rb:82:in `each'
/usr/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime/support_code.rb:82:in `load_files!'
/usr/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime.rb:175:in `load_step_definitions'
/usr/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime.rb:40:in `run!'
/usr/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/cli/main.rb:43:in `execute!'
/usr/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/cli/main.rb:20:in `execute'
/usr/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/cucumber:14
/usr/bin/cucumber:19:in `load'
/usr/bin/cucumber:19
Now my question is: How do I run this code from env.rb?
Thanks!
/Jesper Rønn-Jensen