Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test you are on a page with Cucumber and Capybara

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?

like image 641
Paul Odeon Avatar asked Nov 30 '22 13:11

Paul Odeon


1 Answers

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

assert page.current_path == admin_root_path
like image 182
Benj Avatar answered Dec 10 '22 13:12

Benj