Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to expand a capture group into a custom type when using NativeTestCase? #146

Open
cameroncooke opened this issue Nov 2, 2018 · 1 comment · May be fixed by #149
Open
Labels

Comments

@cameroncooke
Copy link

cameroncooke commented Nov 2, 2018

This is simplistic example but proves my point.

Given I have a feature file like:

Scenario Outline: My test outline
    Given I enter the name <name>

    Examples:
    | name       |
    | Jill Smith |

and the step definition:

step("I enter the name (.+)") { (match: Person) in 
    ...
}

and the model:

struct Person: CodableMatchedStringRepresentable {
    let name: String
    ...
    func doSomethingToPerson() {
        ...
    }
}

In the above example, the expression will be I enter the name (Jill Smith) and I would like to turn the String "Jill Smith" from the capture group into the type Person in my step definition.

I note that you can do this when using native Swift based feature steps as shown in your README by resolving the Person instance into JSON via the description property.

Given("User is loggeed in as \(Person(name: "Nick"))")

I assume what happens here is Person(name: "Nick") is encoded into JSON so the expression becomes: "User is logged in as ({"name": "Nick"}))" and then when the test is run it encodes that back into the Person type?

I assume in my situation I would have to write the feature file like:

Scenario Outline: My test outline
    Given I enter the name {"name": "<name>"}

    Examples:
    | name       |
    | Jill Smith |

But this is less than ideal.

Is there another way I achieve this? Thanks.

@ilyapuchka
Copy link
Collaborator

@cameroncooke yes, in swift tests json string is encoded as part of the step expression and then decoded from this string. It might work if you write json structure in a feature file if you implement step so that it uses Codable parameter, but this was not tested specifically (we can add tests for that if it really works).

I think more proper solution though would be to support data tables - I had it working for swift tests, don't remember if I did anything for feature files, but I'll need to find time to get back to this.

@ilyapuchka ilyapuchka linked a pull request Dec 17, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants