4

In The training wheels came off post by Aslak Hellesoy he says he has removed web_steps.rb and paths.rb from more recent versions of cucumber.

I can understand using the Capybara api instead of web_steps.rb, but how would you now test that you are on a specific page?

This is how I used to do it with paths.rb:

#admin_authentication.feature Then I should be on the admin home page # paths.rb when /the admin home page/ admin_root_path # web_steps.rb Then /^(?:|I )should be on (.+)$/ do |page_name| current_path = URI.parse(current_url).path if current_path.respond_to? :should current_path.should == path_to(page_name) else assert_equal path_to(page_name), current_path end end 

As a secondary question, should we be doing this at all?

2 Answers 2

13

I simply do like this, see if it works for you:

assert page.current_path == admin_root_path 
Sign up to request clarification or add additional context in comments.

4 Comments

This answer did work for me, although I won't be using it because it isn't user focussed
@Paul, you was asking about Capybara and this is a Capybara code in my answer. Capybara is not "user focussed", Cucumber is. I thing you are confusing them here
Sorry for the confusion...my fault!
I used to "assert" like this but after changing my menu to work with Turbolinks this does not work. Now I'm taking a more user's perspective approach removing some of these brittle details
8

Ordinarily, you should not test the page path in a Cucumber step. Cucumber scenarios are meant to be written from the user's perspective. The user is ordinarily only interested in the page's content, so the test should check the page content rather than the particular URL or controller.

Instead of writing a scenario from the developer's perspective like this:

Scenario: Administrator should be on the admin home page When I log in as an administrator Then I should be on the admin home page 

Write it from the user's perspective like this:

Scenario: Administrator should have super-user tools When I log in as an administrator Then I should see the disable-abusive-user button 

1 Comment

I think this answer is more in keeping with the spirit of Cucumber and the training wheels article

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.