Give a warning if more than one step can be applied to scenario line #409

Open
k-bx opened this Issue Dec 6, 2013 · 12 comments

Projects

None yet

3 participants

@k-bx
k-bx commented Dec 6, 2013

I just shoot my foot with having this:

@step("I run server sync at \"(.*)\"")
def server_sync_at_date(step, dt):
    pass

and then adding:

@step("I run server sync")
def server_sync_utcnow(step):
    pass

before that.

If it was me, I would just throw an error in this case from lettuce (rejected with same mechanism as if step is not defined at all) and then possibly do some --warn-on-overlap flag for backward compatibility, since these things are just too tricky to catch.

@adaschevici
Collaborator

Hello,
I believe this is fixed now and i am guessing you have a rather old version of lettuce?
Can you send me an exact snippet so i can test further one that reproduces this?
I tried this but it looks like it's working.
https://gist.github.com/adaschevici/dbf8623c6ee6bcf76fb4

@k-bx
k-bx commented Dec 16, 2013

@adaschevici with latest lettuce (from pip) this https://gist.github.com/k-bx/7984357 outputs "> server_sync_utcnow" twice.

@adaschevici
Collaborator

Yes, there seems to be a discrepancy between version from pip(downloaded from the pipy ) and the one on github
this is the output i am getting on the development version.

Feature: Compute factorial # tests/features/zero.feature:1 In order to play with Lettuce # tests/features/zero.feature:2 As beginners # tests/features/zero.feature:3 We'll implement factorial # tests/features/zero.feature:4

Scenario: Backup at certain times # tests/features/zero.feature:6
Given I have the time 18:00 # tests/features/steps.py:24
Then I run server sync at 5:00 # tests/features/steps.py:36

server_sync_utcnow
Then I run server sync at 5:00 # tests/features/steps.py:36

1 feature (1 passed)
1 scenario (1 passed)
2 steps (2 passed)

The pipy should be updated maybe?
If you want a working version you could just manually install from source or install it directly from the repo using:

pip install -e git://github.com/gabrielfalcao/lettuce.git
If the problem persists let me know,
Thanks.

@k-bx
k-bx commented Dec 16, 2013

@gabrielfalcao oh, that's cool then. Absolutely, someone should update pypi :)

@k-bx
k-bx commented Feb 10, 2014

@adaschevici I was wrong. This: https://gist.github.com/adaschevici/dbf8623c6ee6bcf76fb4 should fail ("assert False"), but it works. Also this: https://gist.github.com/k-bx/8926404 should fail ("assert False"), but doesn't.

@adaschevici
Collaborator

@k-bx I think you may be missing something here.
Your second step does not match the regex: Instead of

Then I run server sync at 5:00

You should have:

Then I run server sync at "5:00"

And inside the steps file you should have:

@steps("Then I run server sync at \"(*.)\"")
def second_step(step, date):
       .......
@adaschevici
Collaborator

Basically the regex inside the step decorator should match the gherkin defined step in the feature file.

@danni
Collaborator
danni commented Feb 11, 2014

FYI: regexes are not automatically wrapped in ^ and $

@k-bx
k-bx commented Feb 11, 2014

@adaschevici all right, sorry for not spotting that! It works good with quotes. But I think I have another case then: https://gist.github.com/k-bx/8932666

Please take a look if I missed something. This doesn't fail (but should).

@k-bx
k-bx commented Feb 11, 2014

@danni absolutely, you can either put $ or other "hacks", but the whole point of this issue is to have at least a warning on overlapping step-patterns for a line (I would prefer error).

@danni
Collaborator
danni commented Feb 11, 2014

I agree. I've got a branch that refractors a lot of the runner code and I'm
soon going to refactor the step definition lookups to try and make them
faster so I can add something then.

On Tuesday, 11 February 2014, Konstantine Rybnikov notifications@github.com
wrote:

@danni https://github.com/danni absolutely, you can either put $ or
other "hacks", but the whole point of this issue is to have at least a
warning on overlapping step-patterns for a line (I would prefer error).


Reply to this email directly or view it on GitHubhttps://github.com/gabrielfalcao/lettuce/issues/409#issuecomment-34743054
.

@adaschevici
Collaborator

Looks legit. It's a bug in the parsing.
If the regex matches then it gets the rest of the string as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment