aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/formula_assertions.rb
diff options
context:
space:
mode:
authorMisty De Meo2017-06-29 17:38:44 -0700
committerMisty De Meo2017-06-29 17:40:04 -0700
commit5b464babf8982acbb6e6d193c9b6016820c69b9b (patch)
tree7df7f40cc69789c0cbda7c82e8d09364e05c8156 /Library/Homebrew/formula_assertions.rb
parent1503c9fcb2509d099dea8fa0f1ae36b9044152f5 (diff)
downloadbrew-5b464babf8982acbb6e6d193c9b6016820c69b9b.tar.bz2
Define a custom assertion failure error for cross-version compat
Fixes #2840.
Diffstat (limited to 'Library/Homebrew/formula_assertions.rb')
-rw-r--r--Library/Homebrew/formula_assertions.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/Library/Homebrew/formula_assertions.rb b/Library/Homebrew/formula_assertions.rb
index f81087a3d..49198cf43 100644
--- a/Library/Homebrew/formula_assertions.rb
+++ b/Library/Homebrew/formula_assertions.rb
@@ -3,6 +3,19 @@ module Homebrew
require "test/unit/assertions"
include ::Test::Unit::Assertions
+ # Custom name here for cross-version compatibility.
+ # In Ruby 2.0, Test::Unit::Assertions raise a MiniTest::Assertion,
+ # but they raise Test::Unit::AssertionFailedError in 2.3.
+ # If neither is defined, this might be a completely different
+ # version of Ruby.
+ if defined?(MiniTest::Assertion)
+ AssertionFailed = MiniTest::Assertion
+ elsif defined?(Test::Unit::AssertionFailedError)
+ AssertionFailed = Test::Unit::AssertionFailedError
+ else
+ raise NameError, "Unable to find an assertion class for this version of Ruby (#{RUBY_VERSION})"
+ end
+
# Returns the output of running cmd, and asserts the exit status
def shell_output(cmd, result = 0)
ohai cmd