diff --git a/test/cask/system_command_test.rb b/test/cask/system_command_test.rb new file mode 100644 index 0000000000000..8e17e12609eac --- /dev/null +++ b/test/cask/system_command_test.rb @@ -0,0 +1,62 @@ +require 'test_helper' + +describe Cask::SystemCommand do + describe "when the exit code is 0" do + result = nil + + before do + command = '/usr/bin/true' + options = { + :must_succeed => false + } + result = Cask::SystemCommand.run(command, options) + end + + it "says the command was successful" do + result.success?.must_equal(true) + end + + it "says the exit status is 0" do + result.exit_status.must_equal(0) + end + end + + describe "when the exit code is 1" do + before do + # See: https://bugs.ruby-lang.org/issues/1287 + skip("Ruby 1.8.7 doesn’t see exit statuses") if TestHelper.ruby18? + end + + describe "and the command must succeed" do + it "throws an error" do + lambda { + command = '/usr/bin/false' + options = { + :must_succeed => true + } + result = Cask::SystemCommand.run(command, options) + }.must_raise(CaskCommandFailedError) + end + end + + describe "and the command does not have to succeed" do + result = nil + + before do + command = '/usr/bin/false' + options = { + :must_succeed => false + } + result = Cask::SystemCommand.run(command, options) + end + + it "says the command failed" do + result.success?.must_equal(false) + end + + it "says the exit status is 1" do + result.exit_status.must_equal(1) + end + end + end +end diff --git a/test/syntax_test.rb b/test/syntax_test.rb index 2fdc14e637f6d..75d8de0c47dc6 100644 --- a/test/syntax_test.rb +++ b/test/syntax_test.rb @@ -18,8 +18,7 @@ # Reason for this hack is unknown. Travis appears to freeze, # but only in one section of the build matrix. - skip if ENV.key?('TRAVIS_JOB_ID') and - RUBY_VERSION.match(%r{^1\.8}) + skip if ENV.key?('TRAVIS_JOB_ID') and TestHelper.ruby18? args = flags + [ '--', file ] shutup do diff --git a/test/test_helper.rb b/test/test_helper.rb index 7d1f092327512..e1aa05e414fae 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -111,6 +111,10 @@ def self.install_without_artifacts(cask) end end end + + def self.ruby18? + RUBY_VERSION.match(%r{^1\.8}) + end end require 'support/fake_fetcher'