0

im new to cucumber, and im having a hard time finding good documentation for ruby with lots of examples

@jobdataAPI

Feature: Submitting a toolbox talk request

  Scenario: When submitting with first aid kit with NO selected, open an HR ticket
    Given first aid kit NO
    Then open an HR ticket

  Scenario: When submitting with first aid kit fully stocked NO, open an HR ticket
    Given first aid kit fully stocked NO
    Then open an HR ticket

  Scenario: When submitting fire extinguisher NO, open an HR ticket
    Given fire extinguisher NO
    Then open an HR ticket

I have a scenario where I am going to have multiple "Then" actions with the same name, but I need to wire up step definitions that have individuality for each Scenario

is it possible to write my step definition with a namespace?

this fails, because Scenario does not exist as a method

# frozen_string_literal: true

World JOBDATA

Scenario('When submitting with first aid kit with NO selected, open an HR ticket') do
  Before do

  end

  After do

  end

  Given('first aid kit NO') do

  end

  Then('open an HR ticket') do

  end
end
alilland
  • 2,039
  • 1
  • 21
  • 42

1 Answers1

0

Namespacing is not supported by Cucumber. Quite the opposite. Cucumber has the concept of a World. This World represents your business domain. Cucumber (quite rightly) suggests that in this world each unique thing should have a unique name. Without this how can your business know what they and you are talking about.

So you can add things to World, but when you do you have to be very disciplined with your naming to ensure you don't overwrite things.

So there is no place for namespacing in Cucumber and you have no need to namespace to do the simple cuking shown in your examples.

On another point Cucumber is designed so that

Given's setup state When's perform an action Then's make assertions on the results of the action

Clearly in your sample feature you are mis-using Then.

Having a feature that explores the effects of different setups on a particular action is a pretty standard thing when cuking. Your feature should have

  1. a preamble, explaining what you are doing and why you are doing it. This gives context to the language you use in your scenarios.

  2. scenario descriptions that match the scenario implementations

  3. scenarios that read well to a business user in their language

There are several anomalies in your current scenario which you should address before trying to do anything technically complex.

  1. You feature talks about Submitting a toolbox talk request but your scenario talk about open an HR ticket

  2. Your Givens don't make sense. What has a first aid kit got to do with any of this.

I'd recommend you back to your feature and try and write it with clarity and simplicity. Think of it as being a document being read by your business owner. Make it clear and obvious, use the preamble to explain the context in which the feature operates. Once you have done that the current problems you have with step definitions should just disappear. If they don't feel free to come back with a revised feature and question ... good luck

diabolist
  • 3,990
  • 1
  • 11
  • 15
  • appriciate the lengthy answer, I was able to hack together a control-flow using global level variables and `After` using this https://stackoverflow.com/questions/23113370/is-there-a-cucumber-hook-to-run-before-and-after-each-feature but i see the business value of your advice – alilland Dec 13 '22 at 17:59