I am trying to test something very simple with Rsec on my Rails app.
This is the 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 controllers/movies_controller.rb:
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:
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"}
Could anyone please help me and tell me what the hell I am doing wrong in such a simple example?
According to the doc, the template must exist when you test your controller since views are stubbed by default.
So your controller may be clean, but the rendering file must exist (even if it doesn't compile).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With