John
John

Reputation: 13705

Setting path in Cucumber

I am setting up a cucumber scenario for setting up a valid user where my last step is:

"Then I should be taken to the show user page"

which I define as:

Then /I should be taken to the show user page/ do
  @user = User.last
  if current_path.respond_to? :should
    current_path.should == path_to(user_path(@user))
  else
    assert_equal path_to(user_path(@user)), current_path
  end
  visit(user_path(@user))
end

After getting an error "Can't find mapping from "/users/49" to a path." I attempted to define the path as:

when /^users\/(.+)$/ do |user|
  user_path(user.to_i)
end

But this yields the error:

syntax error, unexpected keyword_do, expecting keyword_then or ',' or ';' or '\n' when /^landlords/(.+)$/ do |landlord|

I am relatively new to rails and web development and completely new to cucumber and TDD. Also new to regex. Any help would be appreciated!

Thanks,

John

Upvotes: 3

Views: 787

Answers (2)

Andy Waite
Andy Waite

Reputation: 11076

The reason for the "unexpected keyword_do" error is because you have when instead of When, i.e. Ruby is interpreting it as a case-style statement. But as Jon M points, you don't need that anyway.

Upvotes: 0

Jon M
Jon M

Reputation: 11705

It looks like user_path(@user) is giving you the path you need, so wrapping that in path_to is causing the error as it tries to do the same thing.

I think getting rid of the path_to call might help:

current_path.should == user_path(@user)

Upvotes: 3

Related Questions