Nuo Yan

Problem Solved

Recent Posts

Tags

News


  • Follow me on twitter: @nuoyan
    Make a donation to this Blog by PayPal. Thanks!






    Nuo is currently a Software Development Engineer in a Seattle-based software company.




    Locations of visitors to this page

    The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my school or employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.


Community

Email Notifications

Archives

April 2009 - Posts

Testing exceptions with RSpec

I'm new to ruby and rspec. I wrote a ruby function and wanted to check whether it throws an exception or not in a certain situation with rspec, but I realized should_raise function no longer worked in the rspec version I was using (1.2.2). I tried to find information on the Internet and I found that I should use raise_error.

However, when I wrote something like:

it "description" do
    ObjectName.new("parameterName").should raise_error
end

It did not work. Finally I learned the correct way - using lambda:

it "description" do
    lambda{
ObjectName.new("parameterName")}.should raise_error
end

Wanted to post this here and hope it can be helpful for people in the similar need.

 

Posted: Mon, Apr 20 2009 15:54 by Nuo Yan | with 2 comment(s) |
Filed under: