Revise assert_raise to handle any kind of Exception #1

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
3 participants

Ruby's default rescue only handles StandardError subclasses. This is a problem when testing for exceptions that don't inherit from StandardError. The standard timeout library is one such offender: Timeout::Error inherits from Interrupt.

This is causing a test in redis-rb to fail, which is what led me here (see packagethief/redis-rb@b5dd841).

I'm not sure about packagethief@958519a. Prior to this change, these tests were failing due to differences in backtrace formatting (./test/fixtures/failure.rb vs. test/fixtures/failure.rb). If they weren't failing for anyone else, just ignore; it's possible that it's version specific (I tested using 1.8.7 p253).

packagethief added some commits Dec 22, 2010

Revise assert_raise to rescue any kind of Exception; the default only…
… covers StandardError and subclasses

This is a problem when testing for exceptions that don't inherit from StandardError.
Ruby's timeout library is a notable offender: Timeout::Error < Interrupt.

pravi commented Sep 21, 2011

I think I also got this error, I'm building a deb package for cutest and running its own tests fail for me.

pravi@savannah:/media/forge/debian/diaspora/ruby-cutest-1.1.3$ cutest test/run.rb 
.

Cutest::AssertionFailed: "\e[01;36m\n\nCutest::AssertionFailed: \e[1;33mexpression returned false\n\n\e[00m\e[00m- assert false\e[01;30m ./test/fixtures/failure.rb +2\n\e[00m\n" != "\e[01;36m\n\nCutest::AssertionFailed: \e[1;33mexpression returned false\n\n\e[00m- assert false\e[01;30m test/fixtures/failure.rb +2\n\e[00m\n"

- assert_equal(stdout, expected) ./test/run.rb +32
pravi@savannah:/media/forge/debian/diaspora/ruby-cutest-1.1.3$ echo $?
1
pravi@savannah:/media/forge/debian/diaspora/ruby-cutest-1.1.3$ 

pravi commented Sep 21, 2011

This patch doesn't apply any more! test fails with both 1.8.7 and 1.9.2 versions or ruby.

Tested with versions
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]

packagethief, can you re-base your changes to current cutest revision?

pravi commented Jan 6, 2012

hi can anyone rebase this patch to current version?

Owner

djanowski commented May 30, 2014

My sincerest apologies for not attending to this issue before. If you're trying to fix assert_raise under a timeout condition, can you please add a test for such a case? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment