This post originated from an RSS feed registered with Ruby Buzz
by Vincent Woo.
Original Post: RSpec + Rails 2.2 = Neglected Rescue Handlers
Feed Title: Undefined Range
Feed URL: http://www.undefinedrange.com/categories/ruby-on-rails.rss
Feed Description: Interesting things I experience with Ruby on Rails.
Upgrading a Rails project to version 2.2 broke controller specs and I couldn’t figure out why. The problem i was facing was that the default Rails exception rescuing would not work in the test environment.
I’m seeing alot of something like the following with ‘rake spec’:
ActiveRecord::RecordNotFound in 'PagesController responding to GET show should not find the record'
ActiveRecord::RecordNotFound
An exception is raised during the page request as expected but it prematurely ends the spec instead of going through the rescue handlers I’ve setup through rescue_from(). I had no idea if this new behavior is expected or a regression. Sure I could do…
...but I wasn’t looking forward to updating the spec suite to conform. Also, it wouldn’t be testing the rescue handler behaviors. Initially, searching via the almighty Google yield no answers. Stepping through code execution using rdebug revealed that RSpec modifies Rails to not rescue exceptions as it normally would. However, the modification also includes a simple way to revert to the default behavior. Score! So now I’m doing:
before(:each) do
controller.use_rails_error_handling!
end