The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
RSpec + Rails 2.2 = Neglected Rescue Handlers

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Vincent Woo

Posts: 30
Nickname: vwoo
Registered: Sep, 2008

Vincent Woo is a Ruby on Rails enthusiast.
RSpec + Rails 2.2 = Neglected Rescue Handlers Posted: Dec 4, 2008 9:50 PM
Reply to this message Reply

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.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Vincent Woo
Latest Posts From Undefined Range

Advertisement

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…

lambda{do_get}.should raise_error(ActiveRecord::RecordNotFound)

...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

With that solved, I now know which search terms to use and, lo and behold, Google reveals that somebody had the same problem and already figured it out. Google, why had you forsaken me earlier?

Also, there is more context if you’re interested.

Read: RSpec + Rails 2.2 = Neglected Rescue Handlers

Topic: Indentation = 3 Previous Topic   Next Topic Topic: The OTI Brotherhood

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use