Reputation: 343
I'm trying to make a test in rails using Rspec + Capybara + FactoryGirl.
In my page the user can click a link that is generated like this:
<a href="<%= email_path(emails: booking.dummy_user.email) %>" title="<%= t(".send_email") %>" id="send_email_dummy_<%= booking.dummy_user.id %>" >
<span class="icon-envelope"></span>
</a>
In my test I'm doing :
click_link "send_email_dummy_" + dummy_user.id.to_s
current_path.should eq(email_path(locale: "en", emails: dummy_user.email))
However instead of the test passing it is returning:
expected: "/en/email?emails=student%40email.com"
got: "/en/email"
I printed the page generated by the test and the link is correctly generated:
<a href="/en/email?emails=student%40email.com" title="Send Email" id="send_email_dummy_1" >
<span class="icon-envelope"></span>
</a>
Anyone has any idea why this might be happening?
Upvotes: 1
Views: 714
Reputation: 49880
Don't use eq
with current_path or current_url in Capybara, you'll regret it as soon as you start using a driver that supports JS and things become asynchronous. Instead use the have_current_path
matcher
page.should have_current_path(email_path(locale: "en", emails: dummy_user.email))
by default that will include the path with query parameters in the match (which you want in your case). If you don't want them included you can do
page.should have_current_path(email_path(locale: "en", emails: dummy_user.email), only_path: true)
and if you want to compare the whole url you can do
page.should have_current_path(email_path(locale: "en", emails: dummy_user.email), url: true)
Upvotes: 2