#15 ✓resolved
miriam

'nil' not recognized as value in capture_field regex

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

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

Comments and changes to this ticket

  • miriam

    miriam November 25th, 2009 @ 08:34 PM

    • 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

  • Ian White

    Ian White December 1st, 2009 @ 05:14 PM

    • 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)

  • Ian White

    Ian White December 1st, 2009 @ 05:26 PM

    • State changed from “new” to “open”

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

  • miriam

    miriam December 1st, 2009 @ 05:41 PM

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

  • Ian White
  • Ian White

    Ian White December 1st, 2009 @ 05:47 PM

    • 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

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Assign tickets to <b>Ian White</b>, so I get notified

People watching this ticket

Referenced by

Pages