diff options
| author | Jack Nagel | 2013-02-06 18:51:35 -0600 |
|---|---|---|
| committer | Jack Nagel | 2013-02-06 19:04:43 -0600 |
| commit | 45158034740e259b0cec619c25f34d528685b78e (patch) | |
| tree | 3529b9ae5311dfb550424b07922d2f9615db0ebf /Library | |
| parent | a75dd6e8a8308e3e83d8285c4aa6ff9b3d149cc2 (diff) | |
| download | brew-45158034740e259b0cec619c25f34d528685b78e.tar.bz2 | |
Add tests for raise monkey patch
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/debrew/raise_plus.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_raise_plus.rb | 45 |
2 files changed, 47 insertions, 0 deletions
diff --git a/Library/Homebrew/debrew/raise_plus.rb b/Library/Homebrew/debrew/raise_plus.rb index 74f59aa46..29bf4106a 100644 --- a/Library/Homebrew/debrew/raise_plus.rb +++ b/Library/Homebrew/debrew/raise_plus.rb @@ -11,6 +11,8 @@ end module RaisePlus alias :original_raise :raise + private + def raise(*args) exception = case when args.size == 0 diff --git a/Library/Homebrew/test/test_raise_plus.rb b/Library/Homebrew/test/test_raise_plus.rb new file mode 100644 index 000000000..d56a23fe6 --- /dev/null +++ b/Library/Homebrew/test/test_raise_plus.rb @@ -0,0 +1,45 @@ +require 'testing_env' +require 'debrew/raise_plus' + +class RaisePlusTests < Test::Unit::TestCase + include RaisePlus + + def test_raises_runtime_error_when_no_args + assert_raises(RuntimeError) { raise } + end + + def test_raises_runtime_error_with_string_arg + raise "foo" + rescue Exception => e + assert_kind_of RuntimeError, e + assert_equal "foo", e.to_s + end + + def test_raises_given_exception_with_new_to_s + a = Exception.new("foo") + raise a, "bar" + rescue Exception => e + assert_equal "bar", e.to_s + end + + def test_raises_same_instance + a = Exception.new("foo") + raise a + rescue Exception => e + assert_same e, a + end + + def test_raises_exception_class + assert_raises(StandardError) { raise StandardError } + end + + def test_raises_type_error_for_bad_args + assert_raises(TypeError) { raise 1 } + end + + def test_raise_is_private + assert_raises(NoMethodError) do + Object.new.extend(RaisePlus).raise(RuntimeError) + end + end +end |
