rspec-rails: Scaffold generator generates gets error on rails4.

➜  testrspec git:(master) rake routes
    Prefix Verb   URI Pattern                Controller#Action
    robots GET    /robots(.:format)          robots#index
           POST   /robots(.:format)          robots#create
 new_robot GET    /robots/new(.:format)      robots#new
edit_robot GET    /robots/:id/edit(.:format) robots#edit
     robot GET    /robots/:id(.:format)      robots#show
           PATCH  /robots/:id(.:format)      robots#update
           PUT    /robots/:id(.:format)      robots#update
           DELETE /robots/:id(.:format)      robots#destroy
1) RobotsController GET #show assigns the requested robot as @robot
     Failure/Error: get :show, params: {id: robot.to_param}

     ActionController::UrlGenerationError:
       No route matches {:action=>"show", :controller=>"robots", :params=>{:id=>"1"}}
     # ./spec/controllers/robots_controller_spec.rb:52:in `block (3 levels) in <top (required)>'

source

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

It turns out that the test should read

  describe "GET #show" do
    it "assigns the requested user as @user" do
      user = User.create! valid_attributes
      get :show, id: user.to_param, session: valid_session
      expect(assigns(:user)).to eq(user)
    end
  end

Note that the get line has had params: {id: user.to_param} changed to just id: user.to_param. Was this changed at some point and the scaffold files not updated?