Saturday, 28 September 2013

rspec-rails: testing a controller action that renders a partial

rspec-rails: testing a controller action that renders a partial

I have a UsersController that has index and new actions. I use haml, the
index haml file contains the following code:
= link_to 'Add User', new_user_path, { :remote => true, 'data-toggle' =>
'modal',
'data-target' => '#modal-window', 'class' => 'btn btn-primary pull-right' }
So when the user clicks 'Add User' the _new.html.haml partial is presented
to the user as a modal. It works great.
Now in my controller spec I am trying to do the following:
describe "new action" do
before do
get new_user_path
end
# specs for 'new' action go here
end
However that gives an error
Failure/Error: get 'new'
ActionView::MissingTemplate:
Missing template users/new, application/new with {:locale=>[:en],
:formats=>[:html], :handlers=>[:erb, :builder, :coffee, :haml]}.
Searched in:
*
"#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007faa44b03218>"
Presumably because it can't find new.html.haml which of course doesn't
exist because the file is a partial named _new.html.haml. What is the
correct syntax for getting the partial? If not, how can I test the new
action?

No comments:

Post a Comment