diff options
Diffstat (limited to 'Library/Homebrew/cask/test/support')
6 files changed, 98 insertions, 84 deletions
diff --git a/Library/Homebrew/cask/test/support/cleanup.rb b/Library/Homebrew/cask/test/support/cleanup.rb index 0cb9c02fa..c31a74be2 100644 --- a/Library/Homebrew/cask/test/support/cleanup.rb +++ b/Library/Homebrew/cask/test/support/cleanup.rb @@ -1,12 +1,10 @@ -module Hbc::CleanupHooks - def after_teardown - super - Hbc.installed.each do |cask| - Hbc::Installer.new(cask).purge_versioned_files +module MiniTest + class Spec + def after_teardown + super + Hbc.installed.each do |cask| + Hbc::Installer.new(cask).purge_versioned_files + end end end end - -class MiniTest::Spec - include Hbc::CleanupHooks -end diff --git a/Library/Homebrew/cask/test/support/fake_dirs.rb b/Library/Homebrew/cask/test/support/fake_dirs.rb index 89612f850..f8e36bbbb 100644 --- a/Library/Homebrew/cask/test/support/fake_dirs.rb +++ b/Library/Homebrew/cask/test/support/fake_dirs.rb @@ -24,6 +24,8 @@ module FakeDirHooks end end -class MiniTest::Spec - include FakeDirHooks +module MiniTest + class Spec + include FakeDirHooks + end end diff --git a/Library/Homebrew/cask/test/support/fake_fetcher.rb b/Library/Homebrew/cask/test/support/fake_fetcher.rb index a49a89f7f..43483751f 100644 --- a/Library/Homebrew/cask/test/support/fake_fetcher.rb +++ b/Library/Homebrew/cask/test/support/fake_fetcher.rb @@ -1,20 +1,22 @@ -class Hbc::FakeFetcher - def self.fake_response_for(url, response) - @responses[url] = response - end +module Hbc + class FakeFetcher + def self.fake_response_for(url, response) + @responses[url] = response + end - def self.head(url) - @responses ||= {} - raise("no response faked for #{url.inspect}") unless @responses.key?(url) - @responses[url] - end + def self.head(url) + @responses ||= {} + raise("no response faked for #{url.inspect}") unless @responses.key?(url) + @responses[url] + end - def self.init - @responses = {} - end + def self.init + @responses = {} + end - def self.clear - @responses = {} + def self.clear + @responses = {} + end end end @@ -30,6 +32,8 @@ module FakeFetcherHooks end end -class MiniTest::Spec - include FakeFetcherHooks +module MiniTest + class Spec + include FakeFetcherHooks + end end diff --git a/Library/Homebrew/cask/test/support/fake_system_command.rb b/Library/Homebrew/cask/test/support/fake_system_command.rb index e19330fd0..97efd0761 100644 --- a/Library/Homebrew/cask/test/support/fake_system_command.rb +++ b/Library/Homebrew/cask/test/support/fake_system_command.rb @@ -1,61 +1,63 @@ -class Hbc::FakeSystemCommand - def self.responses - @responses ||= {} - end +module Hbc + class FakeSystemCommand + def self.responses + @responses ||= {} + end - def self.expectations - @expectations ||= {} - end + def self.expectations + @expectations ||= {} + end - def self.system_calls - @system_calls ||= Hash.new(0) - end + def self.system_calls + @system_calls ||= Hash.new(0) + end - def self.clear - @responses = nil - @expectations = nil - @system_calls = nil - end + def self.clear + @responses = nil + @expectations = nil + @system_calls = nil + end - def self.stubs_command(command, response = "") - responses[command] = response - 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.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.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]}") + 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 - end - def self.run(command_string, options = {}) - command = Hbc::SystemCommand.new(command_string, options).command - unless responses.key?(command) - raise("no response faked for #{command.inspect}, faked responses are: #{responses.inspect}") - end - system_calls[command] += 1 + def self.run(command_string, options = {}) + command = Hbc::SystemCommand.new(command_string, options).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) + response = responses[command] + if response.respond_to?(:call) + response.call(command_string, options) + else + Hbc::SystemCommand::Result.new(command, response, "", 0) + end end - end - def self.run!(command, options = {}) - run(command, options.merge(must_succeed: true)) + def self.run!(command, options = {}) + run(command, options.merge(must_succeed: true)) + end end end @@ -68,6 +70,8 @@ module FakeSystemCommandHooks end end -class MiniTest::Spec - include FakeSystemCommandHooks +module MiniTest + class Spec + include FakeSystemCommandHooks + end end diff --git a/Library/Homebrew/cask/test/support/never_sudo_system_command.rb b/Library/Homebrew/cask/test/support/never_sudo_system_command.rb index 50f510a7a..8a370df44 100644 --- a/Library/Homebrew/cask/test/support/never_sudo_system_command.rb +++ b/Library/Homebrew/cask/test/support/never_sudo_system_command.rb @@ -1,5 +1,7 @@ -class Hbc::NeverSudoSystemCommand < Hbc::SystemCommand - def self.run(command, options = {}) - super(command, options.merge(sudo: false)) +module Hbc + class NeverSudoSystemCommand < SystemCommand + def self.run(command, options = {}) + super(command, options.merge(sudo: false)) + end end end diff --git a/Library/Homebrew/cask/test/support/shared_examples.rb b/Library/Homebrew/cask/test/support/shared_examples.rb index e846af404..594ca81c1 100644 --- a/Library/Homebrew/cask/test/support/shared_examples.rb +++ b/Library/Homebrew/cask/test/support/shared_examples.rb @@ -5,14 +5,18 @@ MiniTest::Spec.class_eval do end end -module MiniTest::Spec::SharedExamples - def shared_examples_for(desc, &block) - MiniTest::Spec.shared_examples[desc] = block - end +module MiniTest + class Spec + module SharedExamples + def shared_examples_for(desc, &block) + MiniTest::Spec.shared_examples[desc] = block + end - def it_behaves_like(desc, *args, &block) - instance_exec(*args, &MiniTest::Spec.shared_examples[desc]) - instance_eval(&block) if block_given? + def it_behaves_like(desc, *args, &block) + instance_exec(*args, &MiniTest::Spec.shared_examples[desc]) + instance_eval(&block) if block_given? + end + end end end |
