[rspec-devel] [ rspec-Bugs-11536 ] controller.should render_template must be defined after the action

noreply at rubyforge.org noreply at rubyforge.org
Sun Nov 18 22:19:17 EST 2007


Bugs item #11536, was opened at 2007-06-12 22:25
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=11536&group_id=797

Category: rails plugin
Group: None
>Status: Closed
Resolution: None
Priority: 3
Submitted By: courtenay 3 (court3nay)
Assigned to: Nobody (None)
Summary: controller.should render_template must be defined after the action

Initial Comment:
this fails:

  it "should render index.rhtml" do
    response.should render_template(:index)
    do_get
  end

this works:

  it "should render index.rhtml" do
    do_get
    response.should render_template(:index)
  end

Here's my patch; it doesn't "feel" right to me, since there's no other error handling in that file.

Index: lib/spec/rails/matchers/render_template.rb
===================================================================
--- lib/spec/rails/matchers/render_template.rb  (revision 1429)
+++ lib/spec/rails/matchers/render_template.rb  (working copy)
@@ -9,6 +9,9 @@
         end
       
         def matches?(response)
+          unless response.respond_to?:rendered_file
+            raise "The response has not yet rendered or is not a Response object. This matcher (render_template) must be defined after the controller action is called."
+          end
           @actual = response.rendered_file(!expected.include?('/'))
           actual == expected
         end


----------------------------------------------------------------------

Comment By: Chad Humphries (spicycode)
Date: 2007-11-19 03:18

Message:
Moved to http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/49-11536-controller-should-render_template-must-be-defined-after-the-action#ticket-49-2

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2007-09-12 07:22

Message:
It's a bit too late for that Bryan. We're committed to not changing these. We could alias it, but I'd prefer to avoid going down that path. I think we need to figure out a way to give the right feedback when it's used incorrectly.

----------------------------------------------------------------------

Comment By: Bryan Helmkamp (brynary)
Date: 2007-09-12 07:14

Message:
Perhaps the matcher should be renamed from render_file to have_rendered_file. Thoughts?

If this sounds good, I'll write a patch.

----------------------------------------------------------------------

Comment By: courtenay 3 (court3nay)
Date: 2007-06-12 22:34

Message:
the patch doesn't actually work like I intended, but I can't see a way of checking 
that the order is correct

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=11536&group_id=797


More information about the rspec-devel mailing list