2012-03-22 49 views
6

我想测试的东西非常简单,RSEC在我的Rails应用程序。Rails的使用Rspec的测试---> ::的ActionView MissingTemplate:

这是符合规格的试验片的代码/控制器/ 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 

这是在控制器/ movies_controller.rb控制器方法:

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

尝试在更新结束投入redirect_to的movie_path所以它不会尝试去寻找电影/更新 – Bijan 2012-03-22 20:48:33

+0

在一个有一个类似的问题项目,最糟糕的部分是它在单个spec文件上调用rspec时不显示! – 2012-04-21 19:20:54

回答

9

the doc,模板必须当你因为views are stubbed by default测试控制器存在。

所以,你的控制器可能是干净的,但渲染文件必须存在(即使它不编译)。

-1

因为你没有在你的更新操作重定向,轨道将使用默认的惯例来渲染什么看法,所以它会尝试使用“应用程序/视图/电影/ update.html.erb”来渲染你可能没有的视图。通常在更新后,您要重定向到显示类型视图。检查出是一个典型的更新动作看起来像在这里:

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

相关问题