Search code examples
ruby-on-railstestingcapybararspec-rails

What is the difference between visit and current_path and use of .should in rails?


Then /^I should be on the free signup page$/ do
  *current_path.should == free_signup_path* 
end

Then /^I should be on the free signup page$/ do
   *visit free_signup_path* 
end

What is the difference between these two ?


Solution

  • #visit tells the browser to go to a new url and will initiate a get request to the app being tested. #current_path lets you read the current location the browser is at.

    Note: you should stop using current_path.should == some_path, when verifying the current path, and instead use page.should have_current_path(some_path). The have_current_path matcher includes waiting behavior and will help make tests less flaky with JS capable drivers