If I have something like <%= link_to "Help", help_path %>
in the view file, how do I test the following using rspec?
help_path
.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
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
Your file could look like this:
require 'spec_helper'
feature "Help" do
scenario "creation" do
visit help_path # access your help path
page.should have_content("Help") # verify content
end
end
If you need some help with testing with Capybara you could find some here: Railscasts #257 Request Specs and Capybara or Capybara repo at Github
Use have_tag
matcher. Here is a cheatsheet.
response.should have_tag("a[href$=#{help_path}]", :text => "Help")
P.S. Did you read rails guides?
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