2012-10-25 3 views
9

新しいテストでは、いくつかのコントローラテストをパスするのに苦労しています。Rspecコントローラのエラーが<"index">であると予想していますが、レンダリングするのは<"">です。

def login_user 
    before(:each) do 
     @request.env["devise.mapping"] = Devise.mappings[:user] 
     @current_user = FactoryGirl.create(:user) 
     @current_user.roles << Role.first 
     sign_in @current_user 
     User.current_user = @current_user 
     @user = @current_user 
     @ability = Ability.new(@current_user) 
    end 
    end 
:私はこれを持って、私のコントローラマクロで

require 'spec_helper' 

    describe NasController do 

    render_views 
    login_user 

    describe "GET #nas" do 
     it "populates an array of devices" do 
     @location = FactoryGirl.create(:location) 
     @location.users << @current_user 
     @nas = FactoryGirl.create(:nas, location_id: @location.id)  
     get :index 
     assigns(:nas).should eq([@nas]) 
     end 

     it "renders the :index view" do 
     response.should render_template(:index) 
     end 
    end 

expecting <"index"> but rendering with <""> 

私は私のコントローラの仕様の一つで、次のしている:

次コントローラーのテストでエラーが発生します

私はdeviseとcancanを使用しており、そのガイドに従っています。テスト。ユーザーが以前にサインインしていて、インデックス操作を表示できると思います。

テストをパスするにはどうすればよいですか?

- UPDATE 1 -

コントローラーコード:

class NasController < ApplicationController 
    before_filter :authenticate_user! 
    load_and_authorize_resource 

    respond_to :js 

    def index 

    if params[:location_id] 
     ... 
    else 
    @nas = Nas.accessible_by(current_ability).page(params[:page]).order(sort_column + ' ' + sort_direction) 

    respond_to do |format| 
     format.html # show.html.erb 
    end  
    end 
    end 

答えて

14

私はあなたが

it "renders the :index view" do 
    get :index 
    response.should render_template(:index) 
end 

it "renders the :index view" do 
    response.should render_template(:index) 
end 

を変更した場合、それが動作するはずだと思います。

アップデート:私たちは同じ問題を抱えている場合、私は私の最後でこのエラーを修正するために管理し、ないアイデアこの

it "renders the :index view" do 
    @location = FactoryGirl.create(:location) 
    @location.users << @current_user 
    @nas = FactoryGirl.create(:nas, location_id: @location.id) 
    get :index 
    response.should render_template(:index) 
end 
+0

こんにちは。それでも失敗します。先に試してみた - また、場所の作成を繰り返してみました。それを取得しないでください。同じテストが別のコントローラに渡されます。 – simonmorley

+0

nazテーブルが空の場合にインデックスを起動できないコントローラの中の何かがありますか? –

+0

いいえ、私はdeviseとcancanの両方のフィルタを削除しようとしました。 findを@nas = Nas.allに置き換えてください。挫折! – simonmorley

1

を試してみてください。

私の設定では、各応答形式(html、js、jsonなど)をループし、その形式で仕様をテストするコントローラマクロがありました。馬鹿のように、私は実際に私の仕様のいくつかのために存在感のあるjson応答テンプレートを実際には持っていませんでした。テンプレートを実際に見つけることができない場合、これがエラーを投げることに気付きませんでした。それが私の問題でした。

以下のように指定してください。正しいフォルダにindex.htmlという名前のモックテンプレートを書き込んで、同じエラーが発生するかどうか確認してください。

get :index, :format => "html" 
+0

提案していただきありがとうございます。試してみましたが、これは私のためには機能しません。別のコントローラーで動作させ、違いを見ることができるかどうか見ていきます。 – simonmorley

+0

少なくとも私の場合は、「js」が必要な場合を除いて、これはまさに問題でした。 – Karen

関連する問題

 関連する問題