Rails using Rspec for testing ---> ActionView :: MissingTemplate:

I am trying to check something very simple with Rsec in my Rails application.

This is a test piece of code in 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 

This is the controller method in the / movies _controller.rb controllers:

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

And I get this problem:

 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)>' 

My routes look like this:

  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"} 

Can someone help me and tell me what the hell am I doing wrong with such a simple example?

+6
source share
2 answers

According to the document , a template should exist when you test your controller with views are stubbed by default .

Thus, your controller may be clean, but a render file must exist (even if it does not compile).

+9
source

Since you don't have redirects in your update action, rails is going to use the default convention for what kind of rendering, so that it tries to use "app / views / movies / update.html.erb" to render a view that you probably don't you have. Usually after updating you want to redirect to view type of view. See what a typical update action looks like here:

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

-1
source

Source: https://habr.com/ru/post/911444/


All Articles