gpt4 book ai didi

ruby-on-rails - Rails 使用 Rspec 进行测试 ---> ActionView::MissingTemplate:

转载 作者:行者123 更新时间:2023-12-04 03:42:41 25 4
gpt4 key购买 nike

我正在尝试在我的 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 中的 Controller 方法:
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 ,自 views are stubbed by default 起测试 Controller 时模板必须存在.

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

关于ruby-on-rails - Rails 使用 Rspec 进行测试 ---> ActionView::MissingTemplate:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9829762/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com