Method: Spec::Rails::Matchers#render_template

Defined in:
lib/spec/rails/matchers/render_template.rb

#render_template(path) ⇒ Object

:call-seq:

response.should render_template(template)
response.should_not render_template(template)

For use in controller code examples (integration or isolation mode).

Passes if the specified template (view file) is rendered by the response. This file can be any view file, including a partial. However if it is a partial it must be rendered directly i.e. you can’t detect that a partial has been rendered as part of a view using render_template. For that you should use a message expectation (mock) instead:

controller.should_receive(:render).with(:partial => 'path/to/partial')

template can include the controller path. It can also include an optional extension, which you only need to use when there is ambiguity.

Note that partials must be spelled with the preceding underscore.

Examples

response.should render_template('list')
response.should render_template('same_controller/list')
response.should render_template('other_controller/list')

# with extensions
response.should render_template('list.rjs')
response.should render_template('list.haml')
response.should render_template('same_controller/list.rjs')
response.should render_template('other_controller/list.rjs')

# partials
response.should render_template('_a_partial')
response.should render_template('same_controller/_a_partial')
response.should render_template('other_controller/_a_partial')


123
124
125
# File 'lib/spec/rails/matchers/render_template.rb', line 123

def render_template(path)
  RenderTemplate.new(path.to_s, @controller)
end