Note that there are some explanatory texts on larger screens.

plurals
  1. POAdjusting rspec routing tests for nested routes
    primarykey
    data
    text
    <p>When building my app, I generated scaffolds, which created standard Rspec tests. I'd like to use these tests for coverage, but they seem to be failing due to nested routes:</p> <p>When I run the test, this is its feedback:</p> <pre><code>Failures: 1) ListItemsController routing routes to #index Failure/Error: get("/list_items").should route_to("list_items#index") No route matches "/list_items" # ./spec/routing/list_items_routing_spec.rb:7:in `block (3 levels) in &lt;top (required)&gt;' Finished in 0.25616 seconds 1 example, 1 failure </code></pre> <p>How do I tell Rspec that there are nested routes?</p> <p>Here are the abridged files:</p> <p>list_items_routing_spec.rb:</p> <pre><code>require "spec_helper" describe ListItemsController do describe "routing" do it "routes to #index" do get("/list_items").should route_to("list_items#index") end end </code></pre> <p>list_items_controller_spec.rb:</p> <pre><code>describe ListItemsController do # This should return the minimal set of attributes required to create a valid # ListItem. As you add validations to ListItem, be sure to # adjust the attributes here as well. let(:valid_attributes) { { "list_id" =&gt; "1", "project_id" =&gt; "1" } } # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in # ListItemsController. Be sure to keep this updated too. let(:valid_session) { {} } describe "GET index" do it "assigns all list_items as @list_items" do list_item = ListItem.create! valid_attributes get :index, project_id: 2, {}, valid_session assigns(:list_items).should eq([list_item]) end end </code></pre> <p>routes.rb:</p> <pre><code> resources :projects do member do match "list_items" end end </code></pre> <p>Notes: - I've tried changing the rpec tests themselves to include a project_id, and that didn't help. - I'm using Factory Girl for fixture generation (not sure if this is relevant)</p> <p>Thanks for your help!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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