加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 使用Rspec测试的Rails —> ActionView :: M

发布时间:2020-12-16 23:31:50 所属栏目:百科 来源:网络整理
导读:我试图在Rails应用程序上使用Rsec测试一些非常简单的东西. 这是spec / controllers / movies_controller_spec.rb中的测试代码段 describe MoviesController do describe 'update' do it 'should call the model method to look up the movie to update' do M
我试图在Rails应用程序上使用Rsec测试一些非常简单的东西.

这是spec / controllers / 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

这是controllers / 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"}

谁能帮助我,告诉我在这么简单的例子中我到底做错了什么?

解决方法

根据 the doc,测试控制器时模板必须存在,因为默认情况下视图是存根的.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读