Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSpec should have_link fails despite link existence

I have a RSpec test that keeps failing.

subject { page }
visit user_path(user)
it { should have_link('Settings', href: edit_user_path(user)) }

But when I load the page myself I can see that the link is working well. Any ideas ? No spelling mistake as well.

Possible to see the page that RSpec loaded in the test?

like image 595
revolver Avatar asked Jul 11 '12 02:07

revolver


1 Answers

Your visit user_path(user) isn't executing in the right context.

Try either:

subject { page }
it do
  visit user_path(user) 
  should have_link('Settings', href: edit_user_path(user))
end

Or:

subject { page }
before { visit user_path(user) }
it { should have_link('Settings', href: edit_user_path(user)) }

If you would like to see the html, you can use a save_and_open_page statement.

like image 192
Tanzeeb Khalili Avatar answered Sep 24 '22 08:09

Tanzeeb Khalili