[Ironruby-core] assert_throws Problem

Ivan Porto Carrero ivan at flanders.co.nz
Tue Jul 7 14:44:08 EDT 2009

you have to wrap that in a lambda

lambda { PrimeService.new.is_prime -2 }.assert_throws System::Exception

you can't assert code that has already been executed. Basically anything
that asserts exceptions needs to be able to execute the code later because,
and this is true for any language, in  the end the code looks a little like

class Proc

def assert_throws( expected_exception)
  rescue expected_exception
     return true
  return false


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

On Tue, Jul 7, 2009 at 8:27 PM, Mohammad Azam <lists at ruby-forum.com> wrote:

> Hi,
> I want to say that whatever exception is thrown just pass the test.
> class When_a_negative_number_is_passed_to_the_prime_service < TestCase
> def test_should_throw_an_exception
> primeService = PrimeService.new
> primeService.IsPrime(-2)
> assert_throws System::Exception
> end
> end
> The exception thrown from the C# side is ArgumentException
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090707/0eacd1eb/attachment.html>

More information about the Ironruby-core mailing list