1

I am new to Gherkin.

I am writing the following statement in Gherkin:

Given user have institution_1 in database

And here institution_1 for me is just a regular noun, I do not want it to be a variable or have index "1".

The Java function auto-generated by Cucumber-JVM is:

@Given("^user have institution_(\\d+) in database as follows:$")
public void user_have_institution__in_database(int arg1) throws Throwable {
}

How do I rewrite it so that Cucumber-JVM will recognize that "1" does not have special meaning, and return to me something like:

@Given("^user have institution_1 in database as follows:$")
public void user_have_institution_1_in_database() throws Throwable {
}

Thanks!

EDIT: My question is: Cucumber-JVM see every number is Gherkins as numeric argument, for example,

"institution_1" 

is converted to:

 "institution_(\\d+)" 

and the java function will have a

(int arg1) 

argument.

What I want is to have Cucumber-JVM not to convert to:

@Given("^user have institution_(\\d+) in database as follows:$")

but to something like:

@Given("^user have institution_1 in database as follows:$") 

or some other form where regular expression will catch it but not having an argument. Because in common sense, 1 in XXXXX_1 is not meant be a numeric argument, but a character.

If that's not possible, how can I have this to work?

@Given("^user have institution_(\\d+) in database as follows:$")
public void user_have_institution__in_database() throws Throwable {
}
user1559625
  • 2,583
  • 5
  • 37
  • 75
  • Do you mean that you want to configure Cucumber to generate the function you want, or do you just want to know how you can change the generated function to get the results you want? – Dave Schweisguth Mar 10 '16 at 22:28
  • @Dave Schweisguth Right now I just want to change the generated function "@Given("^user have institution_(\\d+) in database as follows:$") ... " so that no "int" arg is passed in, while it's still linked to the gherkins statement. But any further suggestions are welcome. – user1559625 Mar 11 '16 at 00:30
  • Related post - [How to write numbers in cucumber scenarios](https://stackoverflow.com/q/32475031/465053) – RBT Mar 06 '21 at 12:43

1 Answers1

2

Manually edit the generated Gherkin to:

@Given("^user have institution_1 in database as follows:$")
public void user_have_institution_in_database() throws Throwable {
}
MikeJRamsey56
  • 2,779
  • 1
  • 20
  • 34
  • Great, thanks! I think I tried something like this before but it complaint about regex mismatch. Silly me. – user1559625 Mar 14 '16 at 22:34
  • Alternatively: `@Given("^user have "([^"]*)" in database as follows:$") public void user_have_institution_in_database(int arg1) throws Throwable { }` – KyleFairns Mar 15 '16 at 12:32