Check that you are on the page with Cucumber and Capybara

Aslak Hellesoy stepped down from Learning Wheels , he says that he removed web_steps.rb and paths.rb from more recent versions of the cucumber.

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

Here's how I did 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 issue, should we do this at all?

+4
source share
2 answers

As a rule, you should not check the page path at the cucumber stage. Cucumber scripts are designed to be written from a user's perspective. The user is usually only interested in the contents of the page, so the test should check the contents of the page, not a specific URL or controller.

Instead of writing a script from a developer's point of view as follows:

 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 down from the user's point of view as follows:

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

I just do it, see if this works for you:

 assert page.current_path == admin_root_path 
+13
source

All Articles