Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

'nil' not recognized as value in capture_field regex

#15

pickle version: 0.1.23
cucumber version: 0.4.4
rails version: 2.3.4

I have a field on a user that can be nil, but the following step is not recognized in by pickle:

And user should exist with email: "bubba@example.com", token: nil # features/user_password.feature:38

3 scenarios (1 undefined, 2 passed)
26 steps (1 undefined, 25 passed)
0m0.392s

You can implement step definitions for undefined steps with these snippets:

Then /^user should exist with email: "([^"]*)", token: nil$/ do |arg1|
pending # express the regexp above with the code you wish you had end


however, if I change the expected value of the 'token' field to a different type the regex succeeds. for example, these steps are all recognized:

And user should exist with email: "bubba@example.com", token: false # features/step_definitions/pickle_steps.rb:21

And user should exist with email: "bubba@example.com", token: "foo" # features/step_definitions/pickle_steps.rb:21

And user should exist with email: "bubba@example.com", token: 1.5 # features/step_definitions/pickle_steps.rb:20

And user should exist with email: "bubba@example.com", token: 100 # features/step_definitions/pickle_steps.rb:20

Reported by miriam · November 25th, 2009 @ 08:27 PM

State: resolved
Milestone: none
Assigned to: Ian White Ian White

Activity

  1. miriam
    miriam
    • Tag cleared.

    oops. didn't realize we were using markdown. sorry. take 2:


    pickle version: 0.1.23
    cucumber version: 0.4.4
    rails version: 2.3.4

    I have a field on a user that can be nil, but the following step is not recognized in by pickle:

    And user should exist with email: "bubba@example.com", token: nil # features/forgot_password.feature:38

    3 scenarios (1 undefined, 2 passed)
    26 steps (1 undefined, 25 passed)
    0m0.432s

    You can implement step definitions for undefined steps with these snippets:

    Then /^user should exist with email: "([^"]*)", password_token: nil$/ do |arg1|
    pending # express the regexp above with the code you wish you had end

    however, if I change the expected value of the 'token' field to a different type the regex succeeds. for example, these steps are all recognized:

    And user should exist with email: "bubba@example.com", token: false # features/step_definitions/pickle_steps.rb:21 And user should exist with email: "bubba@example.com", token: "foo" # features/step_definitions/pickle_steps.rb:21<br/> And user should exist with email: "bubba@example.com", token: 1.5 # features/step_definitions/pickle_steps.rb:20<br/> And user should exist with email: "bubba@example.com", token: 100 # features/step_definitions/pickle_steps.rb:20

    November 25th, 2009 @ 08:34 PM

  2. Ian White
    Ian White
    • Assigned user set to Ian White

    Thanks for the bug report.

    Just wondering, how does your app behave if you use an empty string? Do you depend on .nil? rather than .blank? (which is the more common case to test against, since most AR attrs come via forms, and "" is the only way of specifying a 'nil' attribute)

    December 1st, 2009 @ 05:14 PM

  3. Ian White
    Ian White
    • State changed from new to open

    This should be easy to fix, I'll sort it out now

    December 1st, 2009 @ 05:26 PM

  4. miriam
    miriam

    Hi Ian -- thanks for fixing this!

    In my app I can't use an empty string and nil interchangeably here. If a user submits a value for token, it must be non-blank. If it's blank it should fail validation. However the app is allowed to set the token to nil under certain circumstances. So to make validations work for these two cases I have :allow_nil => true, rather than :allow_blank, and token can never have the value '' even though it can be nil.

    hope that made sense...

    December 1st, 2009 @ 05:41 PM

  5. Ian White
  6. Ian White
    Ian White
    • State changed from open to resolved

    Hi, yes your use case makes sense.

    Pickle 0.2.1 should sort you out. Reopen this ticket if you have probs.

    Cheers,
    Ian

    December 1st, 2009 @ 05:47 PM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.