Ryan Bates
2007-May-23 20:48 UTC
[rspec-users] Rails Rendering diagnostics.rhtml in Controller Spec
Forgive me if this isn''t the proper list. It''s specific to the rSpec Rails plugin. The problem is, some controller actions are rendering the "diagnostics.rhtml" template when I''m expecting it to render something else in a controller spec. I''m assuming this is the template that displays the error message and a stack trace when an error is raised in the development environment. Is there anyway to see the error through rspec instead of the controller just rendering the diagnostics.rhtml template? I''m surprised this would even be rendered in the test environment. Thanks, Ryan
aslak hellesoy
2007-May-23 20:54 UTC
[rspec-users] Rails Rendering diagnostics.rhtml in Controller Spec
On 5/23/07, Ryan Bates <bates.ryan at gmail.com> wrote:> Forgive me if this isn''t the proper list. It''s specific to the rSpec > Rails plugin. > > The problem is, some controller actions are rendering the > "diagnostics.rhtml" template when I''m expecting it to render something > else in a controller spec. I''m assuming this is the template that > displays the error message and a stack trace when an error is raised > in the development environment. >class ActionController::Base def rescue_action(e) raise; end end> Is there anyway to see the error through rspec instead of the > controller just rendering the diagnostics.rhtml template? I''m > surprised this would even be rendered in the test environment. >Would it be a good idea to make this the default behaviour when running specs? Does vanilla Rails do that? Aslak> Thanks, > > Ryan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
David Chelimsky
2007-May-23 21:08 UTC
[rspec-users] Rails Rendering diagnostics.rhtml in Controller Spec
On 5/23/07, Ryan Bates <bates.ryan at gmail.com> wrote:> Forgive me if this isn''t the proper list. It''s specific to the rSpec > Rails plugin.This is the place. Welcome!> > The problem is, some controller actions are rendering the > "diagnostics.rhtml" template when I''m expecting it to render something > else in a controller spec. I''m assuming this is the template that > displays the error message and a stack trace when an error is raised > in the development environment. > > Is there anyway to see the error through rspec instead of the > controller just rendering the diagnostics.rhtml template? I''m > surprised this would even be rendered in the test environment.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 This used to be implicit, but we removed it because it overrode your own definition of rescue_action. 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 Cheers, David
David Chelimsky
2007-May-23 21:36 UTC
[rspec-users] Rails Rendering diagnostics.rhtml in Controller Spec
On 5/23/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:> On 5/23/07, Ryan Bates <bates.ryan at gmail.com> wrote: > > Forgive me if this isn''t the proper list. It''s specific to the rSpec > > Rails plugin. > > > > The problem is, some controller actions are rendering the > > "diagnostics.rhtml" template when I''m expecting it to render something > > else in a controller spec. I''m assuming this is the template that > > displays the error message and a stack trace when an error is raised > > in the development environment. > > > > class ActionController::Base > def rescue_action(e) raise; end > end > > > Is there anyway to see the error through rspec instead of the > > controller just rendering the diagnostics.rhtml template? I''m > > surprised this would even be rendered in the test environment. > > > > Would it be a good idea to make this the default behaviour when running specs?No. We used to, but changed it in response to a bug report (http://rubyforge.org/tracker/?func=detail&group_id=797&aid=9767&atid=3149)> > Does vanilla Rails do that?Not exactly. It puts it explicitly in generated controller specs. So by default, yes, but implicitly, no.> > Aslak > > > Thanks, > > > > Ryan > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Ryan Bates
2007-May-23 22:03 UTC
[rspec-users] Rails Rendering diagnostics.rhtml in Controller Spec
> 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; endThanks, 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
Ryan Bates
2007-May-23 22:21 UTC
[rspec-users] Rails Rendering diagnostics.rhtml in Controller Spec
I got it working by placing this in the spec_helper.rb: --- Spec::Runner.configure do |config| config.before(:each) do unless @controller_class_name.blank? @controller_class_name.constantize.class_eval do define_method :rescue_action do |e| raise e end end end end end --- I''m sure accessing the @controller_class_name instance variable directly like that isn''t a good thing, but it seems to work. If anyone knows of a better way please reply. :) Thanks again, Ryan
David Chelimsky
2007-May-23 22:26 UTC
[rspec-users] Rails Rendering diagnostics.rhtml in Controller Spec
On 5/23/07, Ryan Bates <bates.ryan at gmail.com> wrote:> I got it working by placing this in the spec_helper.rb: > > --- > Spec::Runner.configure do |config| > config.before(:each) do > unless @controller_class_name.blank? > @controller_class_name.constantize.class_eval do > define_method :rescue_action do |e| > raise e > end > end > end > end > endNice job getting it working. We probably need something that would support this: Spec::Runner.configure do |config| config.define_controller_rescue_action {|e| raise e} end I''m not in love w/ exactly that - but something like that. Any suggestions?> --- > > I''m sure accessing the @controller_class_name instance variable > directly like that isn''t a good thing, but it seems to work. If anyone > knows of a better way please reply. :)> > Thanks again, > > Ryan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Ryan Bates
2007-May-23 23:20 UTC
[rspec-users] Rails Rendering diagnostics.rhtml in Controller Spec
> I''m not in love w/ exactly that - but something like that. Any suggestions?Maybe call it "override_controller_rescue_action!" and have it default to that block? -- Spec::Runner.configure do |config| config.override_controller_rescue_action! end -- A block could then be optionally passed to change its behavior if you don''t want to simply raise the exception. You may also want to have it alias the old rescue_action method in case someone wants to call it? Hmm. Whatever the case, I do think there should be an easy way to do this and maybe mention something in the comments in the config file. I imagine the majority of Rails projects would want to set this? Ryan
David Chelimsky
2007-May-28 20:06 UTC
[rspec-users] Rails Rendering diagnostics.rhtml in Controller Spec
On 5/23/07, Ryan Bates <bates.ryan at gmail.com> wrote:> > I''m not in love w/ exactly that - but something like that. Any suggestions? > > Maybe call it "override_controller_rescue_action!" and have it default > to that block?For better or worse, I ended up calling it raise_controller_errors, and didn''t provide a re-definition hook. I think this makes things more friendly. You can say this for one behaviour: describe SomeController do raise_controller_errors ... end or this for all: #in spec_helper.rb Spec::Runner.configure do |config| config.before(:each, :behaviour_type => :controller) do raise_controller_errors end end This config gets set up for you by default when you say "script/generate rspec". Cheers, David> > -- > Spec::Runner.configure do |config| > config.override_controller_rescue_action! > end > -- > > A block could then be optionally passed to change its behavior if you > don''t want to simply raise the exception. You may also want to have it > alias the old rescue_action method in case someone wants to call it? > Hmm. > > Whatever the case, I do think there should be an easy way to do this > and maybe mention something in the comments in the config file. I > imagine the majority of Rails projects would want to set this? > > Ryan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >