0

Rails アプリ (Rails 4 で記述) でアプリケーション コントローラーの rspec を使用してテストを書いていますが、送信している HTTP 要求のルートを認識しないという問題が発生しています。MyApp::Application.routes を使用してこれを行う方法があることは知っていますが、機能させることができません。

#application_controller_spec.rb

require 'spec_helper'


class TestController < 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

私が今得ているエラーは

No route matches {:action=>"index", :controller=>"test"}

test#index ルートを config/routes.rb に追加しますが、テスト コントローラーを認識しないため、次のようにします。

MyApp::Application.routes.append do
  controller :test do
    get 'test/index' => :index
  end
end

しかし、これをどこに追加するか、またはこれがrspecで機能するかどうかはわかりません。どんな助けでも素晴らしいでしょう!

4

1 に答える 1