Testing links using rspec?

rspec, ruby-on-rails, ruby-on-rails-3

Solution

If you are using capybara then

my_link = find(:css, "a:contains('Help')")
my_link.click

and get page status, should be 200 or simply check


my_link.href

But also you could simply add routes specs to your integration specs in rspec. Like this to be always sure this routes exists

describe HelpController do

  it "should have proper routes" do
    {:get => "/halp/772/parser/18/edit" }.should be_routable
    {:post => "/halp/772/parser" }.should be_routable
    {:delete => "/halp/772/parser/18" }.should be_routable          
  end

end

Problem

If I have something like `<%= link_to "Help", help_path %>` in the view file, how do I test the following using rspec? - It goes to `help_path`. - The content reads "Help". I am currently using capybara. edit While answers below can work, I think I found a simpler way of doing this. ``` describe "some link on whatever page" do subject { page } before { visit whatever_path } it { should have_link('Help', href: help_path) } end ```

Original source