2012-03-27 9 views
0

Ich kann nicht herausfinden, warum mein Test fehlschlägt. Ich denke, es hat mit der Löschmethode zu tun, die ich verwende. Aus welchen Gründen auch immer kann ich den Link nicht für die Löschaktion erhalten. Der Code für die Site funktioniert, aber ich kann nicht scheinen, dass Rspec auf das, was mit der Site passiert, abbildet. Irgendwelche Ideen?Was ist die passende Rspec Syntax

Ausblick:

<li> 
     <%= link_to hunt.name, hunt %> 
     <% if current_user && current_user.admin? %> 
     | <%= link_to "edit", edit_hunt_path(hunt) %> 
     | <%= link_to "delete", hunt, :method => :delete, :confirm => "You sure?", 
            :title => "Delete #{hunt.name}" %>  
     <% end %> 
    </li> 

Rspec Test:

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 => "[email protected]", :admin => true) 
      test_sign_in(admin) 
     end 
     ... 
     it "should show delete link" do 
      get 'index' 
      Hunt.paginate(:page => 1).each do |hunt| 
      response.should have_selector('a', :href => hunt_path(@hunt) , :content => 'delete') 
      end 
     end    
    end 
    end 

Rspec Ausgang:

1) HuntsController GET 'index' for users who are admins should show delete link 
    Failure/Error: response.should have_selector('a', :href => hunt_path(@hunt) , :content => 'delete') 
    ActionController::RoutingError: 
     No route matches {:action=>"show", :controller=>"hunts"} 
    # ./spec/controllers/hunts_controller_spec.rb:64:in `block (5 levels) in <top (required)>' 
    # ./spec/controllers/hunts_controller_spec.rb:63:in `block (4 levels) in <top (required)>' 

Und hier ist der Ausgang des Laufens "Rake Routen":

 users GET /users(.:format)      {:action=>"index", :controller=>"users"} 
       POST /users(.:format)      {:action=>"create", :controller=>"users"} 
    new_user GET /users/new(.:format)     {:action=>"new", :controller=>"users"} 
    edit_user GET /users/:id/edit(.:format)    {:action=>"edit", :controller=>"users"} 
     user GET /users/:id(.:format)     {:action=>"show", :controller=>"users"} 
       PUT /users/:id(.:format)     {:action=>"update", :controller=>"users"} 
       DELETE /users/:id(.:format)     {:action=>"destroy", :controller=>"users"} 
     hunts GET /hunts(.:format)      {:action=>"index", :controller=>"hunts"} 
       POST /hunts(.:format)      {:action=>"create", :controller=>"hunts"} 
    new_hunt GET /hunts/new(.:format)     {:action=>"new", :controller=>"hunts"} 
    edit_hunt GET /hunts/:id/edit(.:format)    {:action=>"edit", :controller=>"hunts"} 
     hunt GET /hunts/:id(.:format)     {:action=>"show", :controller=>"hunts"} 
       PUT /hunts/:id(.:format)     {:action=>"update", :controller=>"hunts"} 
       DELETE /hunts/:id(.:format)     {:action=>"destroy", :controller=>"hunts"} 
    sessions POST /sessions(.:format)     {:action=>"create", :controller=>"sessions"} 
    new_session GET /sessions/new(.:format)    {:action=>"new", :controller=>"sessions"} 
     session DELETE /sessions/:id(.:format)    {:action=>"destroy", :controller=>"sessions"} 
        /hunts(.:format)      {:controller=>"hunts", :action=>"index"} 
     signup  /signup(.:format)      {:controller=>"users", :action=>"new"} 
     signin  /signin(.:format)      {:controller=>"sessions", :action=>"new"} 
     signout  /signout(.:format)      {:controller=>"sessions", :action=>"destroy"} 
     contact  /contact(.:format)      {:controller=>"pages", :action=>"contact"} 
     about  /about(.:format)      {:controller=>"pages", :action=>"about"} 
     help  /help(.:format)      {:controller=>"pages", :action=>"help"} 
     root  /         {:controller=>"pages", :action=>"home"} 
        /:controller(/:action(/:id(.:format))) 
+0

Was ist der Rest des Fehlers? (Sie haben nur die ersten 3 Zeilen der rspec-Ausgabe gepostet) –

+0

OK, ich habe meinen Beitrag mit der vollständigen Fehlermeldung aktualisiert. –

+0

Schön! Das hat es getan. Vielen Dank! –

Antwort

1

Nicht genau, warum das passiert. Aber das Protokoll besagt, dass die Ansicht, die einen Link zu machen versucht, die Punkte hunts#show

http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

Beispiele wie das erste Glied in der Ansicht hat:

<%= link_to hunt.name, hunt %> 

Ich gehe davon aus, dass der link_to nicht zu Jagt ID und entkommt mit einem RoutingError. hunt könnte Null sein?

So oder so, Ben sagt ersetzt die vorhergehende Zeile mit:

<%= link_to hunt.name, hunt_path(hunt) %> 

dies behoben.