The page url is something like /people?search=name
while I used current_path
method of capybara it returned /people
only.
current_path.should == people_path(:search => 'name')
But it fails saying
expected: "/people?search=name"
got: "/people"
How we can make it pass? Is there is any way to do this?
Best Answer
I've updated this answer to reflect modern conventions in capybara. I think this is ideal since this is the accepted answer, and what many people are being referred to when looking for a solution. With that said, the correct way to check the current path is to use the
has_current_path?
matcher provided by Capybara, as documented here: Click HereExample usage:
As you can see in the documentation, other options are available. If the current page is
/people?search=name
but you only care that it's on the/people
page regardless of the param, you can send theonly_path
option:Additionally, if you want to compare the entire URL:
Credit to Tom Walpole for pointing out this method.