Undefined steps suggested code does not escape regex #246

Open
chris-morgan opened this Issue Apr 10, 2012 · 4 comments

Comments

Projects
None yet
2 participants
Contributor

chris-morgan commented Apr 10, 2012

If I start with a feature with regex magic characters in it:

Feature:
    Scenario:
        Given I have an (undefined) step

It will suggest code like this:

@step(u'Given I have an (undefined) step')
def given_i_have_an_undefined_step(step):
    assert False, 'This step must be implemented'

However, this won't match the step because the magic characters haven't been escaped, so if you put in that code it will still be undefined (or succeed when it shouldn't if you had, for example, . or * in the match).

re.escape should be brought to bear on the matter.

Contributor

SystemParadox commented Apr 10, 2012

Please note the examples with parameters as found here:
http://lettuce.it/tutorial/simple.html#lettuce-b-define-steps-in-python

This behaviour is deliberate and required. If regex's were escaped automatically, it would not be possible to use parameters.

If you wish to match characters with special meaning, you should escape them yourself.

Contributor

chris-morgan commented Apr 10, 2012

@SystemParadox, I think you've misunderstood the problem I'm reporting. I'm saying that the suggested code which will turn an undefined step into a failing step is incorrect, as it does not escape the step text. I'm saying it should be suggesting this:

@step(u'Given I have an \(undefined\) step')
def given_i_have_an_undefined_step(step):
    assert False, 'This step must be implemented'
Contributor

SystemParadox commented Apr 10, 2012

Oh sorry I see what you mean now.

I agree this would be a nice change to make.

Contributor

SystemParadox commented Apr 10, 2012

@chris-morgan, as a point of clarification to help future readers, please could you change this sentence:

"However, this won't match the step because the magic characters haven't been escaped, so if you put in that code it will continue to fail"

to:

"However, this won't match the step because the magic characters haven't been escaped, so if you put in that code it will still be undefined"

Thanks.

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