diff options
| author | Markus Reiter | 2017-03-05 20:43:53 +0100 |
|---|---|---|
| committer | GitHub | 2017-03-05 20:43:53 +0100 |
| commit | d0c5aec9ea80f418c222eb99fe71cbe1e10927d2 (patch) | |
| tree | dcfa0e060eced70ef8872d55087fb4c8b027c959 /Library/Homebrew/cask | |
| parent | 43bfaa19f1007776e1809a130568e765adc9a7e8 (diff) | |
| parent | b9c9f0f6872fc3e83e4987559ee3b3c5fa2509a5 (diff) | |
| download | brew-d0c5aec9ea80f418c222eb99fe71cbe1e10927d2.tar.bz2 | |
Merge pull request #2267 from reitermarkus/move-cask-spec-helpers
Move Cask test helpers to `test/support`.
Diffstat (limited to 'Library/Homebrew/cask')
4 files changed, 4 insertions, 130 deletions
diff --git a/Library/Homebrew/cask/spec/spec_helper.rb b/Library/Homebrew/cask/spec/spec_helper.rb index ca0b69d33..0b3a120ca 100644 --- a/Library/Homebrew/cask/spec/spec_helper.rb +++ b/Library/Homebrew/cask/spec/spec_helper.rb @@ -4,10 +4,12 @@ require "test/spec_helper" # add Homebrew-Cask to load path $LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.join("cask", "lib").to_s) -Pathname.glob(HOMEBREW_LIBRARY_PATH.join("cask", "spec", "support", "**", "*.rb")).each(&method(:require)) - require "hbc" +require "test/support/helper/cask/fake_system_command" +require "test/support/helper/cask/install_helper" +require "test/support/helper/cask/never_sudo_system_command" + HOMEBREW_CASK_DIRS = [ :appdir, :caskroom, diff --git a/Library/Homebrew/cask/spec/support/fake_system_command.rb b/Library/Homebrew/cask/spec/support/fake_system_command.rb deleted file mode 100644 index b9390d482..000000000 --- a/Library/Homebrew/cask/spec/support/fake_system_command.rb +++ /dev/null @@ -1,77 +0,0 @@ -def sudo(*args) - %w[/usr/bin/sudo -E --] + args.flatten -end - -module Hbc - class FakeSystemCommand - def self.responses - @responses ||= {} - end - - def self.expectations - @expectations ||= {} - end - - def self.system_calls - @system_calls ||= Hash.new(0) - end - - def self.clear - @responses = nil - @expectations = nil - @system_calls = nil - end - - def self.stubs_command(command, response = "") - responses[command] = response - end - - def self.expects_command(command, response = "", times = 1) - stubs_command(command, response) - expectations[command] = times - end - - def self.expect_and_pass_through(command, times = 1) - pass_through = ->(cmd, opts) { Hbc::SystemCommand.run(cmd, opts) } - expects_command(command, pass_through, times) - end - - def self.verify_expectations! - expectations.each do |command, times| - unless system_calls[command] == times - raise("expected #{command.inspect} to be run #{times} times, but got #{system_calls[command]}") - end - end - end - - def self.run(command_string, options = {}) - command = Hbc::SystemCommand.new(command_string, options).command - puts command - unless responses.key?(command) - raise("no response faked for #{command.inspect}, faked responses are: #{responses.inspect}") - end - system_calls[command] += 1 - - response = responses[command] - if response.respond_to?(:call) - response.call(command_string, options) - else - Hbc::SystemCommand::Result.new(command, response, "", 0) - end - end - - def self.run!(command, options = {}) - run(command, options.merge(must_succeed: true)) - end - end -end - -RSpec.configure do |config| - config.after(:each) do - begin - Hbc::FakeSystemCommand.verify_expectations! - ensure - Hbc::FakeSystemCommand.clear - end - end -end diff --git a/Library/Homebrew/cask/spec/support/install_helper.rb b/Library/Homebrew/cask/spec/support/install_helper.rb deleted file mode 100644 index d91b9ea57..000000000 --- a/Library/Homebrew/cask/spec/support/install_helper.rb +++ /dev/null @@ -1,42 +0,0 @@ -module InstallHelper - module_function - - require "test/support/helper/shutup" - extend Test::Helper::Shutup - - def self.install_without_artifacts(cask) - Hbc::Installer.new(cask).tap do |i| - shutup do - i.download - i.extract_primary_container - end - end - end - - def self.install_without_artifacts_with_caskfile(cask) - Hbc::Installer.new(cask).tap do |i| - shutup do - i.download - i.extract_primary_container - i.save_caskfile - end - end - end - - def install_without_artifacts(cask) - Hbc::Installer.new(cask).tap do |i| - shutup do - i.download - i.extract_primary_container - end - end - end - - def install_with_caskfile(cask) - Hbc::Installer.new(cask).tap do |i| - shutup do - i.save_caskfile - end - end - end -end diff --git a/Library/Homebrew/cask/spec/support/never_sudo_system_command.rb b/Library/Homebrew/cask/spec/support/never_sudo_system_command.rb deleted file mode 100644 index eb8b677f2..000000000 --- a/Library/Homebrew/cask/spec/support/never_sudo_system_command.rb +++ /dev/null @@ -1,9 +0,0 @@ -require "hbc/system_command" - -module Hbc - class NeverSudoSystemCommand < SystemCommand - def self.run(command, options = {}) - super(command, options.merge(sudo: false)) - end - end -end |
