I am just learning Cucumber and notice that if two completely seperate features have two steps that are accidentally worded the same, Cucumber suggests only one step definition for them. Does this mean that step definitions are global and they are meant to be shared?
Example
Suppose a team of business analysts is writing specs for a financial firm that has a banking division and a brokerage division. Further assume that two different people are writing features for their respective divisions to calculate transaction fees.
The banking guy writes:
Feature: Transaction Fees
Scenario: Cutomer withdraws cash from an out-of-netwrok ATM
Given that a customer has withdrawn cash from an out-of-netwrok ATM
When I calculate the transaction fees
Then I must include an out-of-netwrok ATM charge
The brokerage guy writes
Feature: Transaction Fees
Scenario: Cutomer places a limit order
Given that a customer has placed a limit order
When I calculate the transaction fees
Then I must include our standard limit-order charge
Note that the When clause is the same for both the scenarios. Even worse, both guys put this scenario in a file called transaction-fees.feature (in different directories of course).
Cucumber produces the following recommendation for step definitions:
You can implement step definitions for undefined steps with these snippets:
this.Given(/^that a customer has withdrawn cash from an out\-of\-netwrok ATM$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.When(/^I calculate the transaction fees$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.Then(/^I must include an out\-of\-netwrok ATM charge$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.Given(/^that a customer has placed a limit order$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.Then(/^I must include our standard limit\-order charge$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
Note that the when clause is suggested only once.
- Does this mean that there needs to be only one step definition that needs to be entered in only one of the two step definition files?
- Does cucumber associate feature files with similarly named step_definition files? In other words, does it associate transaction-fees.feature with transaction-fees.steps.js? If all the step definitions are global, then I might mistakenly assume that file/directory setup is just for organization and doesn't mean anything as far as the execution envirnment goes.
Thanks in advance for your time and clarifications.