lib/spec/rails/matchers/render_template.rb in rspec-rails-1.1.11 vs lib/spec/rails/matchers/render_template.rb in rspec-rails-1.1.12

- old
+ new

@@ -8,13 +8,23 @@ @controller = controller @expected = expected end def matches?(response) - if response.respond_to?(:rendered_file) @actual = response.rendered_file + elsif response.respond_to?(:rendered) + case template = response.rendered[:template] + when nil + unless response.rendered[:partials].empty? + @actual = path_and_file(response.rendered[:partials].keys.first).join("/_") + end + when ActionView::Template + @actual = template.path + when String + @actual = template + end else @actual = response.rendered_template.to_s end return false if @actual.blank? given_controller_path, given_file = path_and_file(@actual) @@ -51,34 +61,44 @@ def current_controller_path @controller.class.to_s.underscore.gsub(/_controller$/,'') end end - + # :call-seq: - # response.should render_template(path) - # response.should_not render_template(path) + # response.should render_template(template) + # response.should_not render_template(template) # - # Passes if the specified template is rendered by the response. - # Useful in controller specs (integration or isolation mode). + # For use in controller code examples (integration or isolation mode). # - # <code>path</code> can include the controller path or not. It - # can also include an optional extension (no extension assumes .rhtml). + # 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') + # + # <code>template</code> 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') # - # #rjs + # # 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 + # # partials # response.should render_template('_a_partial') # response.should render_template('same_controller/_a_partial') # response.should render_template('other_controller/_a_partial') def render_template(path) RenderTemplate.new(path.to_s, @controller)