Hi,
Any good examples out there (I couldn’t find any) of assert_throws? I
would love to know also why its first argument is a symbol…
Thanks
Mike
Hi,
Any good examples out there (I couldn’t find any) of assert_throws? I
would love to know also why its first argument is a symbol…
Thanks
Mike
On Jan 1, 2006, at 11:42 AM, asplake wrote:
Hi,
Any good examples out there (I couldn’t find any) of assert_throws? I
would love to know also why its first argument is a symbol…
I’m guessing you might be looking for Exception handling assertions.
If so, you want:
assert_raised()
assert_nothing_raised()
assert_throws() is related to catch()/throw(), useful in Ruby for
breaking out of nested constructs.
I hope that helps.
James Edward G. II
“asplake” [email protected] writes:
Hi,
Any good examples out there (I couldn’t find any) of assert_throws? I
would love to know also why its first argument is a symbol…
#assert_throw checks for a Kernel#throw, which takes a Symbol.
Perhaps you were after #assert_raise ?
require ‘test/unit’
def f
throw :x
end
def g
raise
end
class T < Test::Unit::TestCase
def test_a
assert_throws(:x){f} # pass
assert_throws(:y){f} # fail
end
def test_b
assert_raise(RuntimeError ){g} # pass
assert_raise(ArgumentError){g} # fail
end
end
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs