2012-03-22 22 views
6

RailsでRsecを使って非常に単純なものをテストしようとしています。Rspecを使ってRailsでテストする---> ActionView :: MissingTemplate:

これはこれは、コントローラ/ movies_controller.rbにおけるコントローラのメソッドであるスペック/コントローラ/ movies_controller_spec.rbのコードのテストピース

describe MoviesController do 
    describe 'update' do               
     it 'should call the model method to look up the movie to update' do           
     Movie.should_receive(:find).with("3")   
     put :update, {:id => "3"}            
    end 
    end 

です:

def update 
    Movie.find(params[:id]) 
end 

そして、私はこの問題を取得します:

1) MoviesController update should call the model method to look up the movie to update Failure/Error: post :update, {:id => "3"} ActionView::MissingTemplate: Missing template movies/update, application/update with {:handlers=>[:erb, :builder, :coffee, :haml], :formats=>[:html], :locale=>[:en, :en]}. Searched in: * "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0xa65b300>" # ./spec/controllers/movies_controller_spec.rb:8:in `block (3 levels) in <top (required)>' 

私のルートは次のようになります。

movies GET /movies(.:format)   {:action=>"index", :controller=>"movies"} 
      POST /movies(.:format)   {:action=>"create", :controller=>"movies"} 
new_movie GET /movies/new(.:format)  {:action=>"new", :controller=>"movies"} 
edit_movie GET /movies/:id/edit(.:format) {:action=>"edit", :controller=>"movies"} 
    movie GET /movies/:id(.:format)  {:action=>"show", :controller=>"movies"} 
      PUT /movies/:id(.:format)  {:action=>"update", :controller=>"movies"} 
      DELETE /movies/:id(.:format)  {:action=>"destroy", :controller=>"movies"} 

誰でも私を助けて、私がこのような簡単な例で何が間違っているのか教えてください。

+0

それは/映画を見てみてください – Bijan

+0

を更新1で同様の問題を抱えていないので、更新の最後にredirect_toのmovie_pathに入れてみてくださいプロジェクトでは、最悪の部分は、単一のspecファイルでrspecを呼び出すときに表示されないことです! –

答えて

9

the docによると、コントローラーをテストするときには、views are stubbed by default以降のテンプレートが存在する必要があります。

コントローラーはクリーンかもしれませんが、レンダリングファイルは(コンパイルされていなくても)存在する必要があります。

-1

あなたの更新アクションにリダイレクトがないので、railsはどのビューをレンダリングするのにデフォルトの規約を使用しますので、 'app/views/movies/update.html.erb'を使って試してみますおそらく持っていないビューをレンダリングします。通常、更新後、表示タイプのビューにリダイレクトします。典型的な更新アクションがここでどのように見えるかをチェックしてください:

http://guides.rubyonrails.org/getting_started.html#editing-posts

関連する問題