[rspec-users] Links in view specs

Ashley Moran work at ashleymoran.me.uk
Tue Jan 16 08:02:43 EST 2007


Hi

I have this simple view (used by the Gap controller):

   <h1>Gap#index</h1>
   <%= link_to "Get a GAP quote", :action => "get_quote" %>

And this spec:

   context "A rendered gap/index" do
     setup do
       render 'gap/index'
     end

     specify "should have a link to the get_quote page" do
       response.should_have_tag 'a', :attributes => { :href => /\/gap 
\/get_quote/ }
     end
   end

But is fails because it actually links like this:
    <a href="/view_spec/get_quote">
not
   <a href="/gap/get_quote">

What's the cleanest way to test links without integrating it into the  
controller?  For now I'm doing...
   response.should_have_tag 'a', :attributes => { :href => /\/ 
get_quote$/ }

  Sorry if this is a FAQ, can't see any posts on the list about it.

Ta
Ashley


More information about the rspec-users mailing list