Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the appropriate Rspec syntax
    primarykey
    data
    text
    <p>I can't figure out why my test is failing. I think it has to do with the delete method I'm using. For whatever reason, I can't get the link right for the delete action. The code for the site works, but I can't seem to have Rspec to map onto what's happening with the site. Any ideas?</p> <p>View:</p> <pre><code> &lt;li&gt; &lt;%= link_to hunt.name, hunt %&gt; &lt;% if current_user &amp;&amp; current_user.admin? %&gt; | &lt;%= link_to "edit", edit_hunt_path(hunt) %&gt; | &lt;%= link_to "delete", hunt, :method =&gt; :delete, :confirm =&gt; "You sure?", :title =&gt; "Delete #{hunt.name}" %&gt; &lt;% end %&gt; &lt;/li&gt; </code></pre> <p>Rspec test:</p> <pre><code>require 'spec_helper' describe HuntsController do render_views describe "GET 'index'" do ... describe "for users who are admins" do before(:each) do admin = FactoryGirl.create(:user, :email =&gt; "admin@example.com", :admin =&gt; true) test_sign_in(admin) end ... it "should show delete link" do get 'index' Hunt.paginate(:page =&gt; 1).each do |hunt| response.should have_selector('a', :href =&gt; hunt_path(@hunt) , :content =&gt; 'delete') end end end end </code></pre> <p>Rspec output:</p> <pre><code> 1) HuntsController GET 'index' for users who are admins should show delete link Failure/Error: response.should have_selector('a', :href =&gt; hunt_path(@hunt) , :content =&gt; 'delete') ActionController::RoutingError: No route matches {:action=&gt;"show", :controller=&gt;"hunts"} # ./spec/controllers/hunts_controller_spec.rb:64:in `block (5 levels) in &lt;top (required)&gt;' # ./spec/controllers/hunts_controller_spec.rb:63:in `block (4 levels) in &lt;top (required)&gt;' </code></pre> <p>And here's the output of running "rake routes": </p> <pre><code> users GET /users(.:format) {:action=&gt;"index", :controller=&gt;"users"} POST /users(.:format) {:action=&gt;"create", :controller=&gt;"users"} new_user GET /users/new(.:format) {:action=&gt;"new", :controller=&gt;"users"} edit_user GET /users/:id/edit(.:format) {:action=&gt;"edit", :controller=&gt;"users"} user GET /users/:id(.:format) {:action=&gt;"show", :controller=&gt;"users"} PUT /users/:id(.:format) {:action=&gt;"update", :controller=&gt;"users"} DELETE /users/:id(.:format) {:action=&gt;"destroy", :controller=&gt;"users"} hunts GET /hunts(.:format) {:action=&gt;"index", :controller=&gt;"hunts"} POST /hunts(.:format) {:action=&gt;"create", :controller=&gt;"hunts"} new_hunt GET /hunts/new(.:format) {:action=&gt;"new", :controller=&gt;"hunts"} edit_hunt GET /hunts/:id/edit(.:format) {:action=&gt;"edit", :controller=&gt;"hunts"} hunt GET /hunts/:id(.:format) {:action=&gt;"show", :controller=&gt;"hunts"} PUT /hunts/:id(.:format) {:action=&gt;"update", :controller=&gt;"hunts"} DELETE /hunts/:id(.:format) {:action=&gt;"destroy", :controller=&gt;"hunts"} sessions POST /sessions(.:format) {:action=&gt;"create", :controller=&gt;"sessions"} new_session GET /sessions/new(.:format) {:action=&gt;"new", :controller=&gt;"sessions"} session DELETE /sessions/:id(.:format) {:action=&gt;"destroy", :controller=&gt;"sessions"} /hunts(.:format) {:controller=&gt;"hunts", :action=&gt;"index"} signup /signup(.:format) {:controller=&gt;"users", :action=&gt;"new"} signin /signin(.:format) {:controller=&gt;"sessions", :action=&gt;"new"} signout /signout(.:format) {:controller=&gt;"sessions", :action=&gt;"destroy"} contact /contact(.:format) {:controller=&gt;"pages", :action=&gt;"contact"} about /about(.:format) {:controller=&gt;"pages", :action=&gt;"about"} help /help(.:format) {:controller=&gt;"pages", :action=&gt;"help"} root / {:controller=&gt;"pages", :action=&gt;"home"} /:controller(/:action(/:id(.:format))) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload