[rspec-users] Trying to spec ExceptionNotifiable behavior

Luis Lavena luislavena at gmail.com
Tue Jan 22 18:58:55 EST 2008


Hello List.

I'm trying to overwrite part of ExceptionNotifiable
(ExceptionNotification plugin) to render customized error 500 pages
based on browser agents.

For this, I've created a fake controller that inherits directly from
ActionController::Base:

class FooExceptionController < ActionController::Base
  include ExceptionNotifiable

  # this action should not fail, used for controller.expect_render(...) checking
  def ok_action
    render(:file => "#{RAILS_ROOT}/public/ok.html")
  end

  # this action should raise an unexpected exception
  def fail_action
    raise StandardError.new("manually raised exception")
  end
end

I'm running with RSpec 1.0.8 (pistoned as plugin) and respective
REL_1_0_8 rspec_on_rails
All the specs are ran with 'script/spec -R -c spec'

This is my spec:

describe FooExceptionController, "dealing with exceptions" do
  it "should succeed on a good action" do
    get 'ok_action'
    response.should be_success
  end

  it "should render the action ok_action" do
    controller.expect_render(:file => "#{RAILS_ROOT}/public/ok.html")
    get 'ok_action'
  end

  # Why we are getting the exception here?
  # shouldn't be rspec passing it to rails to process it?
  it "should fail on fail_action" do
    lambda {
      get 'fail_action'
    }.should raise_error(StandardError, /manually raised exception/)
  end

  it "should render error template" do
    controller.expect_render(:file => "#{RAILS_ROOT}/public/500.html")
    get 'fail_action'
  end
end

==

First spec "should render the action ok_action" works ok, and the
controller render expectation do its work.

The second spec, isn't right. I'm not trying to get the Exception to
catch it on Rspec, but actully let ExceptionNotifier do its job and
actually expect rendering of RAILS_ROOT/public/500.html, as shown in
the third spec.

Anyway, both 1 and 2, pass, but third fails with "manually raised
exception" on the output:

StandardError in 'FooExceptionController dealing with exceptions
should render error template'
manually raised exception

I've looked all over, for 1.0.8 and 1.1.2, but the only reference I
could find is use_rails_error_handling! in rdoc, but no Spec::Runner
configuration option or before behavior that could be change.
(http://rspec.info/rdoc-rails/classes/ActionController/Rescue.html#M000007)

What I'm doing wrong? What I'm missing?

Thanks in advance for your time.
Regards,
-- 
Luis Lavena
Multimedia systems
-
A common mistake that people make when trying to design
something completely foolproof is to underestimate
the ingenuity of complete fools.
Douglas Adams


More information about the rspec-users mailing list