Reputation: 225
I'm trying to write a test that clicks a link but when I run the test, Capybara returns the following error:
"no link with title, id or text 'New Mwod post' found
so I put a 'debugger' and printed the response. The body contained the following:
<a href=\"/mwod_posts/new\">New Mwod post</a>
the test has the following code:
describe "GET /mwod_posts/new" do
it "creates a new mwod post" do
FactoryGirl.create(:mwod_tag)
get mwod_posts_path
debugger
response.status.should be(200)
click_link "New Mwod post"
end
end
Any ideas why capybara can't click the link?
Upvotes: 2
Views: 1124
Reputation: 27384
The problem is that you're using get
when you should be using visit
.
Switch:
get mwod_posts_path
to:
visit mwod_posts_path
That will let you click links with click_link
etc. To parse the response, you'll need to change:
response.status.should be(200)
to:
page.response_code.should be(200)
I haven't actually confirmed that this works, but discussion elsewhere would seem to indicate you can check response codes this way from page
. Although, as noted in that discussion, this is not something you should really be doing in integration tests.
For more see on the difference between get
and visit
see this answer and this post. (This is a common point of confusion.).
Upvotes: 1