Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing difference between #step and #steps #171

Closed
farcaller opened this issue Nov 9, 2011 · 15 comments
Closed

Confusing difference between #step and #steps #171

farcaller opened this issue Nov 9, 2011 · 15 comments

Comments

@farcaller
Copy link

having a scenario:

Scenario: successfully log in with existing account using login
  Given there is user "testuser" registered with email "test@user.net"
  When I sign in with "testuser" and password "helloworld"
  Then I should see account menu for "test@user.net"
  And I should see a flash message stating that login is successful

And steps:

When /^I click on link "([^"]*)"$/ do |link|
  click_on link
end

When /^I fill in "([^"]*)" with "([^"]*)"$/ do |field, data|
  fill_in field, :with => data
end

When /^I click on button "([^"]*)"$/ do |button|
  click_button button
end

The following step works:

When /^I register with username "([^"]*)" and email "([^"]*)"$/ do |username, email|
  step %Q{I click on link "Sign up"}
  step %Q{I fill in "Username" with "#{username}"}
  step %Q{I fill in "Email" with "#{email}"}
  step %Q{I fill in "Password" with "123456"}
  step %Q{I fill in "Confirm Password" with "123456"}
  step %Q{I click on button "Sign up"}
end

But this one fails:

When /^I register with username "([^"]*)" and email "([^"]*)"$/ do |username, email|
  steps %Q{
    I click on link "Sign up"
    I fill in "Username" with "#{username}"
    I fill in "Email" with "#{email}"
    I fill in "Password" with "123456"
    I fill in "Confirm Password" with "123456"
    I click on button "Sign up"
  }
end

with errors like:

When I register with username "testuser" and email "test@user.net"       # features/step_definitions/user_steps.rb:4
  Lexing error on line 2: '    I click on link "Sign up"'. See http://wiki.github.com/cucumber/gherkin/lexingerror for more information. (Gherkin::Lexer::LexingError)
  ./features/step_definitions/user_steps.rb:12:in `/^I register with username "([^"]*)" and email "([^"]*)"$/'
  features/user_registers.feature:12:in `When I register with username "testuser" and email "test@user.net"'
@msassak
Copy link
Member

msassak commented Nov 9, 2011

I'm pretty sure this is failing because #steps parses its input with Gherkin but #step invokes the given step definition directly. If that's the case this behavior is definitely surprising. Renaming #step to #invoke might reduce confusion.

@aslakhellesoy
Copy link
Contributor

That's right. This will work:

steps %Q{
  When I click on link "Sign up"
  And I fill in "Username" with "#{username}"
  And I fill in "Email" with "#{email}"
  And I fill in "Password" with "123456"
  And I fill in "Confirm Password" with "123456"
  And I click on button "Sign up"
}

@mattwynne - what do you think? Rename #step to #invoke? I can cut a release tomorrow and update the book to reference that. (We'd keep #step for a while and issue a deprecation warning if people use it).

@farcaller
Copy link
Author

Uhh.. Yup, that's a good point. Then I have two issues (got When/And missing at some point).

Consider this:

When /^I sign in with "([^"]*)" and password "([^"]*)"$/ do |username, password|
  steps %Q{
    When I click on link "Sign in"
    And I fill in "Username or email" with "#{username}"
    And I fill in "Password" with "#{password}"
    And I click on button "Sign in"
  }
end

Although it looks valid, it fails randomly with

When I register with username "testuser" and email "test@user.net"       # features/step_definitions/user_steps.rb:4
  Lexing error on line 4: 'controller/metal/implicit_render.rb:4:in `send_action''. See http://wiki.github.com/cucumber/gherkin/lexingerror for more information. (Gherkin::Lexer::LexingError)
  ./features/step_definitions/user_steps.rb:12:in `/^I register with username "([^"]*)" and email "([^"]*)"$/'
  features/user_registers.feature:12:in `When I register with username "testuser" and email "test@user.net"'

...

When I register with username "testuser" and email "other@user.net"  # features/step_definitions/user_steps.rb:4
  Lexing error on line 7: '= //label[contains(normalize-space(string(.)), 'Passwo'. See http://wiki.github.com/cucumber/gherkin/lexingerror for more information. (Gherkin::Lexer::LexingError)
  ./features/step_definitions/user_steps.rb:12:in `/^I register with username "([^"]*)" and email "([^"]*)"$/'
  features/user_registers.feature:19:in `When I register with username "testuser" and email "other@user.net"'

@aslakhellesoy
Copy link
Contributor

Randomly? You mean it will work sometimes and fail other times without any edits in-between?

@farcaller
Copy link
Author

I mean that I have /I sign in with "([^"])" and password "([^"])/ in several scenarios of one feature, and lexing error is different each time (as shown above) in one cucumber run.

@aslakhellesoy
Copy link
Contributor

Can you isolate it to one scenario? Then do this:

gherkin = %Q{...}
Kernel.puts gherkin
steps(gherkin)

And show us what gherkin is printed for the scenario where you get lexing error.

@farcaller
Copy link
Author

Given

When /^I sign in with "([^"]*)" and password "([^"]*)"$/ do |username, password|
  gherkin = %Q{
    When I click on link "Sign in"
    And I fill in "Username or email" with "#{username}"
    And I fill in "Password" with "#{password}"
    And I click on button "Sign in"
  }

  Kernel.puts "    ---"
  Kernel.puts gherkin
  Kernel.puts "    +++"
  steps(gherkin)
end

I have the following failures:

Given there is user "testuser" registered with email "test@user.net" # features/step_definitions/user_steps.rb:27
---

When I click on link "Sign in"
And I fill in "Username or email" with "testuser"
And I fill in "Password" with "helloworld"
And I click on button "Sign in"

+++
When I sign in with "testuser" and password "helloworld"             # features/step_definitions/user_steps.rb:36
  Lexing error on line 4: 'Z?'. See http://wiki.github.com/cucumber/gherkin/lexingerror for more information. (Gherkin::Lexer::LexingError)
  ./features/step_definitions/user_steps.rb:47:in `/^I sign in with "([^"]*)" and password "([^"]*)"$/'
  features/user_logs_in.feature:11:in `When I sign in with "testuser" and password "helloworld"'

and

Given there is user "testuser" registered with email "test@user.net" # features/step_definitions/user_steps.rb:27
---

When I click on link "Sign in"
And I fill in "Username or email" with "test@user.net"
And I fill in "Password" with "helloworld"
And I click on button "Sign in"

+++
When I sign in with "test@user.net" and password "helloworld"        # features/step_definitions/user_steps.rb:36
  Lexing error on line 4: 'eware/callbacks.rb:29:in `block in call''. See http://wiki.github.com/cucumber/gherkin/lexingerror for more information. (Gherkin::Lexer::LexingError)
  ./features/step_definitions/user_steps.rb:47:in `/^I sign in with "([^"]*)" and password "([^"]*)"$/'
  features/user_logs_in.feature:17:in `When I sign in with "test@user.net" and password "hello world"'

and one successful:

Given there is no user "testuser" registered                     # features/step_definitions/user_steps.rb:1
---

When I click on link "Sign in"
And I fill in "Username or email" with "testuser"
And I fill in "Password" with "helloworld"
And I click on button "Sign in"

+++
When I sign in with "testuser" and password "helloworld"         # features/step_definitions/user_steps.rb:36
Then I should see login error                                    # features/step_definitions/user_steps.rb:59

and another successful:

Given I navigate to index page                             # features/step_definitions/web_steps.rb:1
---

When I click on link "Sign in"
And I fill in "Username or email" with "testuser"
And I fill in "Password" with "helloworld"
And I click on button "Sign in"

+++
And I am logged in as "testuser" and password "helloworld" # features/step_definitions/user_steps.rb:69

Where "I am logged in" is defined as:

Given /^I am logged in as "([^"]*)" and password "([^"]*)"$/ do |username, password|
  step %Q{there is user "#{username}" registered with email "test@user.net"}
  step %Q{I sign in with "#{username}" and password "#{password}"}
end

@farcaller
Copy link
Author

Actually yes, it does fail randomly. After re-run:

Given there is user "testuser" registered with email "test@user.net" # features/step_definitions/user_steps.rb:27
When I register with username "hello" and email "test@user.net"      # features/step_definitions/user_steps.rb:4
  Lexing error on line 4: 'er/.rvm/gems/ruby-1.9.3-p0@rails3/gems/haml-3.1.3/lib/haml/helpers/action_view_mods.rb:180:in `block in form_for_with_haml''. See http://wiki.github.com/cucumber/gherkin/lexingerror for more information. (Gherkin::Lexer::LexingError)
  ./features/step_definitions/user_steps.rb:12:in `/^I register with username "([^"]*)" and email "([^"]*)"$/'
  features/user_registers.feature:24:in `When I register with username "hello" and email "test@user.net"'
Then I should see registration error                                 # features/step_definitions/user_steps.rb:31

(that was successful a moment ago).

Seem to be memory corruption issue here.

@msassak
Copy link
Member

msassak commented Nov 9, 2011

I see you're using MRI 1.9.3--can you run this with 1.9.2 and see what happens?

@aslakhellesoy
Copy link
Contributor

Can you confirm that your ruby file is saved with UTF-8 encoding? And what OS are you on?

@mattwynne
Copy link
Member

On 9 Nov 2011, at 10:26, Aslak Hellesøy wrote:

@mattwynne - what do you think? Rename #step to #invoke? I can cut a release tomorrow and update the book to reference that. (We'd keep #step for a while and issue a deprecation warning if people use it).

Sounds good to me.

@farcaller
Copy link
Author

broken on MRI 1.9.3, also crashes jruby 1.6.5. Seem to work ok on MRI 1.9.2

@msassak
Copy link
Member

msassak commented Nov 10, 2011

That's a separate bug in Gherkin then. I created an issue for it here: cucumber/gherkin#142 and renamed this one to accurately reflect its content.

@tsemana
Copy link

tsemana commented Feb 8, 2013

The related issue opened under Gherkin is closed. Suggest this issue be closed as well.

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants