user
user

Reputation: 375

How to make Cucumber step definitions load according to feature file being executed

I would like to modify cucumber so that when a given feature is being executed (say "login.feature") I want only login_steps.rb to be loaded for the web steps. Other step files should not be loaded.

IMO this would be very useful to have the same steps but which differ in implementation work accordingly from the feature's name which is being executed.

Since I have almost a hundred scenarios and I would prefer if the steps were of high level steps this would make sense.

Any ideas?

Upvotes: 3

Views: 1823

Answers (3)

Aravin
Aravin

Reputation: 7067

Here is sample code for you,

.feature file

Scenario: Some description of the scenario
Given [some context]
When [some event]
Then [outcome]

.rb (Step Definition in ruby)

Given /^[some context]$/ do
// code module
// code module
end
  • This step definition will execute whenever [some context] comes in feature file.

says,

Given [some context]
When [some context]
Then [some context]
And [some context]

will perform in same operation. i.e Given, When, Then and And are generic.


Also, you can read behat document for better understanding - http://behat.readthedocs.org/

Upvotes: 0

Andy Tinkham
Andy Tinkham

Reputation: 1339

You may be able to achieve something like this using the Cellophane gem. It supports nested step definitions and you can turn off looking for shared steps. I'm not sure this will get you all the way to where you want to be, but I've found the developer to be very responsive if cellophane could be modified to get you what you're looking for.

Upvotes: 1

John
John

Reputation: 30195

Currently, the only way to accomplish this (short of patching cucumber itself) is to put each feature into a separate directory tree with its own env.rb file and step_definitions directory.

See this post on the mailing list for more details.

Upvotes: 1

Related Questions