Note that there are some explanatory texts on larger screens.

plurals
  1. PORSpec test fails with "No route matches" for resources route
    primarykey
    data
    text
    <h2>Context</h2> <p>I'm running into a very weird test failure that I can't explain based on my code. When I run the spec test provided below, it will display the following error:</p> <p>Failures:</p> <p>1) GroupsController GET 'index' returns http success Failure/Error: get 'index' ActionController::UrlGenerationError: No route matches {:action=>"index", :controller=>"groups"} # ./spec/controllers/groups_controller_spec.rb:14:in `block (3 levels) in '</p> <h2>Test case</h2> <p>The test case for the controller and routes set in RSpec looks like this:</p> <pre><code>describe GroupsController do before :each do @group = FactoryGirl.create(:group) @user = FactoryGirl.create(:user) sign_in @user end describe "GET 'index'" do it "returns http success" do get 'index' response.should be_success end end end </code></pre> <h2>Controller under test</h2> <p>I've written a very basic skeleton for my controller based on the test. Currently it doesn't do a whole lot of stuff.</p> <pre><code>class GroupsController &lt; ApplicationController before_filter :authenticate_user! def index @groups = current_user.groups end end </code></pre> <h2>Routes configured to reach the controller</h2> <p>The routes.rb file looks like this:</p> <pre><code>NerdCooking::Application.routes.draw do resources :groups devise_for :users root :to =&gt; "home#welcome" end </code></pre> <h2>Routes</h2> <pre><code> groups GET /groups(.:format) groups#index POST /groups(.:format) groups#create new_group GET /groups/new(.:format) groups#new edit_group GET /groups/:id/edit(.:format) groups#edit group GET /groups/:id(.:format) groups#show PATCH /groups/:id(.:format) groups#update PUT /groups/:id(.:format) groups#update DELETE /groups/:id(.:format) groups#destroy </code></pre> <h2>Question</h2> <p>I have tried changing the route to get "groups" => "groups#index" instead of the resources route and that works, but it's not something I want since I want to use this as a RESTful service as well.</p> <p>What am I doing wrong here? </p> <p>Update: Added the routes related to groups.</p>
    singulars
    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