rspec索引示例有效但不显示示例

时间:2012-06-01 21:59:25

标签: ruby testing rspec controller routes

$ rake spec

  1) GroupsController GET show show one group's name & description
     Failure/Error: get :show
     ActionController::RoutingError:
       No route matches {:controller=>"groups", :action=>"show"}
     # ./spec/controllers/groups_controller_spec.rb:16:in `block (3 levels) in <top (required)>'

Finished in 0.26379 seconds
2 examples, 1 failure


cat controllers/groups_controller_spec.rb 
require 'spec_helper'

describe GroupsController do

  describe "GET index" do
    it "assigns all groups to @groups" do
      group = FactoryGirl.create(:group)
      get :index
      assigns(:groups).should eq([group])
    end
  end

  describe "GET show" do
    it "show one group's name & description" do
      group = FactoryGirl.create(:group)
      get :show
      assigns(:group).should eq([group])
    end
  end

end

$ rake routes
(in /home/durrantm/Dropnot/webs/rails_v3/linker)
      ladmin_login        /ladmin/login(.:format)       {:controller=>"ladmin", :action=>"login"}
     ladmin_logout        /ladmin/logout(.:format)      {:controller=>"ladmin", :action=>"logout"}
             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"}
order_links_groups POST   /groups/order_links(.:format) {:action=>"order_links", :controller=>"groups"}
            groups GET    /groups(.:format)             {:action=>"index", :controller=>"groups"}
                   POST   /groups(.:format)             {:action=>"create", :controller=>"groups"}
         new_group GET    /groups/new(.:format)         {:action=>"new", :controller=>"groups"}
        edit_group GET    /groups/:id/edit(.:format)    {:action=>"edit", :controller=>"groups"}
             group GET    /groups/:id(.:format)         {:action=>"show", :controller=>"groups"}
                   PUT    /groups/:id(.:format)         {:action=>"update", :controller=>"groups"}
                   DELETE /groups/:id(.:format)         {:action=>"destroy", :controller=>"groups"}
            search        /search(.:format)             {:action=>"index", :controller=>"links"}
   advanced_search        /advanced_search(.:format)    {:action=>"advanced_search", :controller=>"links"}
      groups_links GET    /links/groups(.:format)       {:action=>"groups", :controller=>"links"}
             links GET    /links(.:format)              {:action=>"index", :controller=>"links"}
                   POST   /links(.:format)              {:action=>"create", :controller=>"links"}
          new_link GET    /links/new(.:format)          {:action=>"new", :controller=>"links"}
         edit_link GET    /links/:id/edit(.:format)     {:action=>"edit", :controller=>"links"}
              link GET    /links/:id(.:format)          {:action=>"show", :controller=>"links"}
                   PUT    /links/:id(.:format)          {:action=>"update", :controller=>"links"}
                   DELETE /links/:id(.:format)          {:action=>"destroy", :controller=>"links"}
              root        /(.:format)                   {:controller=>"links", :action=>"index"}

1 个答案:

答案 0 :(得分:3)

你需要传递一个id。

get :show, id: group.id

assigns(:group).should eq(group)