[rspec-users] Rails Rendering diagnostics.rhtml in Controller Spec

Ryan Bates bates.ryan at gmail.com
Wed May 23 18:03:00 EDT 2007


> Try overriding rescue_action as is done in rails controller tests:
>
> # Re-raise errors caught by the controller.
> class MyController; def rescue_action(e) raise e end; end

Thanks, that makes perfect sense. Strangely it's not working when I
place it at the top of a controller spec:

---
require File.dirname(__FILE__) + '/../spec_helper'
class ArticlesController; def rescue_action(e) raise e end; end

describe ArticlesController do
  #...
end
---

I get this error:

---
  You have to declare the controller name in controller specs. For example:
    describe "The ExampleController" do
      controller_name "example" #invokes the ExampleController
    end
---

Placing it at the end of the spec file seems to work though.



> If you want to do this for every controller, assuming you're on 1.0,
> you can do this in spec/spec_helper.rb
>
> Spec::Runner.configure do |config|
>   config.before(:each) do
>     controller.class.class_eval do
>       define_method :rescue_action do |e|
>         raise e
>       end
>     end
>   end
> end
>

This doesn't have any effect for me. It still renders the
diagnostics.rhtml template with that in the spec_helper. I'm running
1.0.

Ryan


More information about the rspec-users mailing list