In the old syntax of rspec I could do something like this:
It "should have the right URL" do
get :show, :id => @user
response.should have_selector('td>a', :content => user_path(@user),
:href => user_path(@user))
end
In the new sintax we can do this:
It "should have the right URL" do
visit user_path(@user)
expect(page).to have_link user_path(@user), href: user_path(@user)
end
But, in the new syntax of rspec and using capybara, how can I say where the link should be? In the first example I say that it's in 'td>a', what about the second example?
Thanks!
Editing:
If I try this:
It "should have the right URL" do
expect(page).to have_selector('td>a', :content => user_path(@user),
:href => user_path(@user))
I get the following error:
1) UsersController GET 'show' should have the right URL
Failure/Error: expect(page).to have_selector(:content => user_path(@user),
ArgumentError:
invalid keys :content, :href, should be one of :text, :visible, :between, :count, :maximum, :minimum, :exact, :match, :wait
Maybe you also upgraded your capybara gem?
Try:
It "should have the right URL" do
expect(page).to have_selector("td>a[href='#{user_path(@user)}']",
:text=> user_path(@user))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With