Are the definitions of cucumbers global?

I just study Cucumber and notice that if two completely separate functions have two steps that are randomly worded identically, Cucumber offers only one definition of step for them. Does this mean that step definitions are global and are intended to be shared?

Example

Suppose a business analyst team writes specifications for a financial firm with a banking and brokerage unit. Further, suppose that two different people write functions for their respective departments to calculate transaction fees.

Bank 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 

Broker 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 scenarios. Worse, both guys put this script in a file called transaction-fee.feature (in different directories, of course).

Cucumber gives the following recommendation for determining steps:

 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(); }); 

Please note that the when clause is only offered once.

  • Does this mean that there should be only one step definition that needs to be entered in only one of the two step definition files?
  • Are cucumbers associated with function files with similar step_definition files? In other words, does he link transaction fees with transaction fees .steps.js? If all step definitions are global, then I can mistakenly assume that the installation of files / directories is for the organization only and does not mean anything, as far as running around.

Thank you in advance for your time and clarification.

+5
source share
1 answer

step defs are tied to the World object, which is "this" in your code above.

  • There should be only one step definition. They are intended for sharing. IIRC, Cucumber Boo, p. 149 ( https://pragprog.com/book/hwcuc/the-cucumber-book ) goes into the details of this design decision. Although this is a ruby, I think it is one and the same in all implementations of the cucumber.

  • Cucumbers do not link function files and step_definition files. The file tree / convention is for convenience only.

+2
source

Source: https://habr.com/ru/post/1203940/


All Articles