Cucumberish icon indicating copy to clipboard operation
Cucumberish copied to clipboard

Why has "And" been deprecated

Open ghost opened this issue 6 years ago • 12 comments

Thanks for a cool library. The MatchAll function doesn't recognize when you use an "And" in your feature file. I see that "And" has been deprecated too. This doesn't make sense to me, can you please explain what the thinking behind this is?

ghost avatar Aug 30 '17 13:08 ghost

And is now implicit. If you implement a match for Given(or When or Then...) it will also work for And. If you are finding that MatchAll isn't matching for And, that's a bug (cc: @TitouanVanBelle).

brentleyjones avatar Aug 30 '17 14:08 brentleyjones

Can I fix the bug and send a pull request?

ghost avatar Aug 31 '17 07:08 ghost

Can you provide more information about the scenario you're trying to run?

TitouanVanBelle avatar Aug 31 '17 07:08 TitouanVanBelle

If you have an And after a Given, and you implement the And step with MatchAll it doesn't recognize that the step exists; for example:

Scenario: Delete an order of tickets
    Given it is the tickets screen
    And I confirm the "Delete" action

And you implement the step with MatchAll like this:

MatchAll("I confirm the \"(*.)\" action") {(args, userInfo) -> Void in
    NSLog("Not implemented")
}

It doesn't recognise the step.

I see that the MatchAll function doesn't have Given:

void MatchAll(NSString * definitionString, CCIStepBody body)
{
    When(definitionString, body);
    Then(definitionString, body);
    But(definitionString, body);
}

ghost avatar Aug 31 '17 07:08 ghost

Yes, that's what I thought. Then feel free to create a PR adding the Given call in the MatchAll function. Unless there was a reason in the beginning for not adding it? @brentleyjones

TitouanVanBelle avatar Aug 31 '17 09:08 TitouanVanBelle

It's just a bug. A PR would be wonderful, thanks.

brentleyjones avatar Aug 31 '17 14:08 brentleyjones

In the documentation for Step Definitions:

Given is left out intentionally because it is very unlikely to have a case when a definition is suitable for Given and any other kind of steps.

TheCodedSelf avatar Nov 09 '17 06:11 TheCodedSelf

This doesn't refer to a left out Given. It's about MatchAll not containing And.

ghost avatar Nov 09 '17 07:11 ghost

@louismza, I'm referring to the comment above:

feel free to create a PR adding the Given call in the MatchAll function. Unless there was a reason in the beginning for not adding it

TheCodedSelf avatar Nov 09 '17 07:11 TheCodedSelf

Oh yeah, but are we saying Given can’t have Ands?

ghost avatar Nov 09 '17 07:11 ghost

I think the idea is that if And is used after When or Then, then it will be called by MatchAll. But MatchAll intentionally does not match Given, and as such, it won't match any Ands following Given.

That's my understanding of the way it works currently.

TheCodedSelf avatar Nov 09 '17 07:11 TheCodedSelf

This is limiting because you can’t reuse a step defined With MatchAll in your Given clause. You can argue that the And step I am implementing here is supposed to be a When step. But I am not trying to implement invalid Cucumber. All steps defined in any way match all Givens, Whens, Thens and Ands in standard Cucumber. I.e. if you define a step with When() in standard Cucumber, you can match it with a Given without a problem.

ghost avatar Nov 09 '17 07:11 ghost