gabrielfalcao / lettuce

Behavior-driven-development tool for python, inspired by Cucumber for Ruby ⛺
http://lettuce.it
GNU General Public License v3.0
1.27k stars 325 forks source link

Undefined steps suggested code does not escape regex #246

Open chris-morgan opened 12 years ago

chris-morgan commented 12 years ago

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.

SystemParadox commented 12 years ago

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.

chris-morgan commented 12 years ago

@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'
SystemParadox commented 12 years ago

Oh sorry I see what you mean now.

I agree this would be a nice change to make.

SystemParadox commented 12 years ago

@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.