Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a route for testing purposes?
    primarykey
    data
    text
    <p>I'm writing tests with rspec for my application controller in my rails app (written in Rails 4) and I'm running into a problem where it doesn't recognize the route for the HTTP request I'm sending. I know there's a way to do this using MyApp::Application.routes but I'm not able to get it working.</p> <pre><code>#application_controller_spec.rb require 'spec_helper' class TestController &lt; ApplicationController def index; end end describe TestController do before(:each) do @first_user = FactoryGirl.create(:user) # this is to ensure that all before_filters are run controller.stub(:first_time_user) controller.stub(:current_user) end describe 'first_time_user' do before(:each) do controller.unstub(:first_time_user) end context 'is in db' do before(:each) do @user = FactoryGirl.create(:user) controller.stub(:current_user).and_return(@user) end it 'should not redirect' do get :index response.should_not be_redirect end end context 'is not in db' do context 'session[:cas_user] does not exist' do it 'should return nil' do get :index expect(assigns(:current_user)).to eq(nil) end end it "should redirect_to new_user_path" do controller.stub(:current_user, redirect: true).and_return(nil) get :index response.should be_redirect end end end </code></pre> <p>The error I'm getting right now is</p> <pre><code>No route matches {:action=&gt;"index", :controller=&gt;"test"} </code></pre> <p>I would add the test#index route to config/routes.rb, but it doesn't recognize the Test Controller, so I want to do something like</p> <pre><code>MyApp::Application.routes.append do controller :test do get 'test/index' =&gt; :index end end </code></pre> <p>but I'm not sure where to add this or if this even works in rspec. Any help would be great!</p>
    singulars
    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.
 

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