aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/test
diff options
context:
space:
mode:
authorMarkus Reiter2016-09-24 13:52:43 +0200
committerMarkus Reiter2016-09-24 16:00:58 +0200
commitb86c8efb79b3ed835d552c4d7416640ef10caf21 (patch)
tree7e1edc8a8f339e4d2781f43576d40c9c79aebcdc /Library/Homebrew/cask/test
parent687f0fcf721c8e36f32570ed72d0988a6eaf986f (diff)
downloadbrew-b86c8efb79b3ed835d552c4d7416640ef10caf21.tar.bz2
Cask: Use nested classes and modules.
Diffstat (limited to 'Library/Homebrew/cask/test')
-rw-r--r--Library/Homebrew/cask/test/cask/cli/create_test.rb22
-rw-r--r--Library/Homebrew/cask/test/cask/cli/edit_test.rb26
-rw-r--r--Library/Homebrew/cask/test/cask/cli/home_test.rb22
-rw-r--r--Library/Homebrew/cask/test/support/cleanup.rb16
-rw-r--r--Library/Homebrew/cask/test/support/fake_dirs.rb6
-rw-r--r--Library/Homebrew/cask/test/support/fake_fetcher.rb36
-rw-r--r--Library/Homebrew/cask/test/support/fake_system_command.rb98
-rw-r--r--Library/Homebrew/cask/test/support/never_sudo_system_command.rb8
-rw-r--r--Library/Homebrew/cask/test/support/shared_examples.rb18
-rw-r--r--Library/Homebrew/cask/test/test_helper.rb4
10 files changed, 142 insertions, 114 deletions
diff --git a/Library/Homebrew/cask/test/cask/cli/create_test.rb b/Library/Homebrew/cask/test/cask/cli/create_test.rb
index cf3cf28a3..efca1a506 100644
--- a/Library/Homebrew/cask/test/cask/cli/create_test.rb
+++ b/Library/Homebrew/cask/test/cask/cli/create_test.rb
@@ -1,17 +1,21 @@
require "test_helper"
# monkeypatch for testing
-class Hbc::CLI::Create
- def self.exec_editor(*command)
- editor_commands << command
- end
+module Hbc
+ class CLI
+ class Create
+ def self.exec_editor(*command)
+ editor_commands << command
+ end
- def self.reset!
- @editor_commands = []
- end
+ def self.reset!
+ @editor_commands = []
+ end
- def self.editor_commands
- @editor_commands ||= []
+ def self.editor_commands
+ @editor_commands ||= []
+ end
+ end
end
end
diff --git a/Library/Homebrew/cask/test/cask/cli/edit_test.rb b/Library/Homebrew/cask/test/cask/cli/edit_test.rb
index ebec5f414..3f385eb33 100644
--- a/Library/Homebrew/cask/test/cask/cli/edit_test.rb
+++ b/Library/Homebrew/cask/test/cask/cli/edit_test.rb
@@ -1,17 +1,21 @@
require "test_helper"
# monkeypatch for testing
-class Hbc::CLI::Edit
- def self.exec_editor(*command)
- editor_commands << command
- end
-
- def self.reset!
- @editor_commands = []
- end
-
- def self.editor_commands
- @editor_commands ||= []
+module Hbc
+ class CLI
+ class Edit
+ def self.exec_editor(*command)
+ editor_commands << command
+ end
+
+ def self.reset!
+ @editor_commands = []
+ end
+
+ def self.editor_commands
+ @editor_commands ||= []
+ end
+ end
end
end
diff --git a/Library/Homebrew/cask/test/cask/cli/home_test.rb b/Library/Homebrew/cask/test/cask/cli/home_test.rb
index 28fd2a391..78302abd1 100644
--- a/Library/Homebrew/cask/test/cask/cli/home_test.rb
+++ b/Library/Homebrew/cask/test/cask/cli/home_test.rb
@@ -1,17 +1,21 @@
require "test_helper"
# monkeypatch for testing
-class Hbc::CLI::Home
- def self.system(*command)
- system_commands << command
- end
+module Hbc
+ class CLI
+ class Home
+ def self.system(*command)
+ system_commands << command
+ end
- def self.reset!
- @system_commands = []
- end
+ def self.reset!
+ @system_commands = []
+ end
- def self.system_commands
- @system_commands ||= []
+ def self.system_commands
+ @system_commands ||= []
+ end
+ end
end
end
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
diff --git a/Library/Homebrew/cask/test/test_helper.rb b/Library/Homebrew/cask/test/test_helper.rb
index 4d795bffe..47c1b4cdb 100644
--- a/Library/Homebrew/cask/test/test_helper.rb
+++ b/Library/Homebrew/cask/test/test_helper.rb
@@ -159,7 +159,9 @@ require "tempfile"
FileUtils.mkdir_p Hbc.homebrew_prefix.join("bin")
# Common superclass for test Casks for when we need to filter them out
-class Hbc::TestCask < Hbc::Cask; end
+module Hbc
+ class TestCask < Cask; end
+end
# jack in some optional utilities
FileUtils.ln_s "/usr/local/bin/cabextract", Hbc.homebrew_prefix.join("bin/cabextract")