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?
The problem is that you’re using
getwhen you should be usingvisit.Switch:
to:
That will let you click links with
click_linketc. To parse the response, you’ll need to change:to:
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
getandvisitsee this answer and this post. (This is a common point of confusion.).