groovyjbehave

In jbehave is it possible to use parameterised tabular parameter?


Let's say i have main app code that changes file names using some pattern. In jbehave story i want to move this pattern and expected file name to "Examples". Problem is "expected file name" column should contain patter (previous column). Is it possible to use "variables" in "Examples" section?

story file

Given that exist file named originalFName
When …
Than file name should be expectedFName

Examples:
|pattern    | originalFName | expectedFName   |
|someString | pattern.txt   | AAA_pattern.rtf |

grrovy

@Given('that exist file named $originalFName')
void isFileExist(@Named('originalFName') String fName) {…}

@Than('file name should be expectedFName')
void fNameShouldBe(@Named('expectedFName') String expectedFName) {…}

So i wonder is possible to get, when compiled (in this case)

originalFName == someString.txt

expectedFName == AAA_someString.rtf


Solution

  • many ways to implement this. for example

    Given fileNamePart
    When exist file named originalFName
    When …
    Than file name should be expectedFName
    
    Examples:
    |fileNamePart| originalFName | expectedFName   |
    |someString  | %s.txt        | AAA_%s.rtf      |
    

    and in code just replace %s with fileNamePart:

    originalFName = String.format(originalFName,fileNamePart)
    

    instead of %s + String.format you could use regexp, or dynamic groovy evaluation...