From 3cdf8f938a7cc31e366c49f8f5134a51bdcfdc7f Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 9 May 2017 23:00:51 +0200 Subject: [PATCH] Use scoped RSpec matchers. --- Library/Homebrew/build_environment.rb | 10 ++--- Library/Homebrew/formula.rb | 2 +- Library/Homebrew/requirement.rb | 2 +- Library/Homebrew/test/bash_spec.rb | 28 +++++++------- Library/Homebrew/test/bottle_hooks_spec.rb | 4 +- .../Homebrew/test/build_environment_spec.rb | 38 +++++++++---------- Library/Homebrew/test/build_options_spec.rb | 6 +-- .../Homebrew/test/compiler_failure_spec.rb | 4 +- Library/Homebrew/test/dependable_spec.rb | 4 +- .../test/dependency_collector_spec.rb | 4 +- Library/Homebrew/test/dependency_spec.rb | 6 +-- Library/Homebrew/test/dev-cmd/audit_spec.rb | 8 ++-- .../test/formula_installer_bottle_spec.rb | 4 +- .../Homebrew/test/formula_installer_spec.rb | 6 +-- Library/Homebrew/test/formula_spec.rb | 24 ++++++------ .../test/os/mac/dependency_collector_spec.rb | 4 +- Library/Homebrew/test/requirement_spec.rb | 6 +-- Library/Homebrew/test/sandbox_spec.rb | 4 +- Library/Homebrew/test/software_spec_spec.rb | 6 +-- Library/Homebrew/test/tab_spec.rb | 4 +- Library/Homebrew/test/tap_spec.rb | 6 +-- 21 files changed, 90 insertions(+), 90 deletions(-) diff --git a/Library/Homebrew/build_environment.rb b/Library/Homebrew/build_environment.rb index e3299fb943..dc28b22939 100644 --- a/Library/Homebrew/build_environment.rb +++ b/Library/Homebrew/build_environment.rb @@ -22,12 +22,12 @@ class BuildEnvironment def userpaths? @settings.include? :userpaths end -end -module BuildEnvironmentDSL - def env(*settings) - @env ||= BuildEnvironment.new - @env.merge(settings) + module DSL + def env(*settings) + @env ||= BuildEnvironment.new + @env.merge(settings) + end end end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 1b3b718da6..720f484396 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1997,7 +1997,7 @@ class Formula # The methods below define the formula DSL. class << self - include BuildEnvironmentDSL + include BuildEnvironment::DSL # The reason for why this software is not linked (by default) to # {::HOMEBREW_PREFIX}. diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index 6c20e7917b..cac8c6232e 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -159,7 +159,7 @@ class Requirement end class << self - include BuildEnvironmentDSL + include BuildEnvironment::DSL attr_reader :env_proc, :build attr_rw :fatal, :default_formula diff --git a/Library/Homebrew/test/bash_spec.rb b/Library/Homebrew/test/bash_spec.rb index 1b0f150664..5526078100 100644 --- a/Library/Homebrew/test/bash_spec.rb +++ b/Library/Homebrew/test/bash_spec.rb @@ -1,20 +1,20 @@ require "open3" -RSpec::Matchers.define :have_valid_bash_syntax do - match do |file| - stdout, stderr, status = Open3.capture3("/bin/bash", "-n", file) - - @actual = [file, stderr] - - stdout.empty? && status.success? - end - - failure_message do |(file, stderr)| - "expected that #{file} is a valid Bash file:\n#{stderr}" - end -end - describe "Bash" do + matcher :have_valid_bash_syntax do + match do |file| + stdout, stderr, status = Open3.capture3("/bin/bash", "-n", file) + + @actual = [file, stderr] + + stdout.empty? && status.success? + end + + failure_message do |(file, stderr)| + "expected that #{file} is a valid Bash file:\n#{stderr}" + end + end + context "brew" do subject { HOMEBREW_LIBRARY_PATH.parent.parent/"bin/brew" } it { is_expected.to have_valid_bash_syntax } diff --git a/Library/Homebrew/test/bottle_hooks_spec.rb b/Library/Homebrew/test/bottle_hooks_spec.rb index 05c6ea7f08..913e3ffbaf 100644 --- a/Library/Homebrew/test/bottle_hooks_spec.rb +++ b/Library/Homebrew/test/bottle_hooks_spec.rb @@ -1,9 +1,9 @@ require "formula_installer" require "hooks/bottles" -RSpec::Matchers.alias_matcher :pour_bottle, :be_pour_bottle - describe Homebrew::Hooks::Bottles do + alias_matcher :pour_bottle, :be_pour_bottle + subject { FormulaInstaller.new formula } let(:formula) do diff --git a/Library/Homebrew/test/build_environment_spec.rb b/Library/Homebrew/test/build_environment_spec.rb index 5a3cec4527..58bec6d1fd 100644 --- a/Library/Homebrew/test/build_environment_spec.rb +++ b/Library/Homebrew/test/build_environment_spec.rb @@ -1,8 +1,8 @@ require "build_environment" -RSpec::Matchers.alias_matcher :use_userpaths, :be_userpaths - describe BuildEnvironment do + alias_matcher :use_userpaths, :be_userpaths + let(:env) { described_class.new } describe "#<<" do @@ -38,29 +38,29 @@ describe BuildEnvironment do expect(env).not_to use_userpaths end end -end -describe BuildEnvironmentDSL do - subject { double.extend(described_class) } + describe BuildEnvironment::DSL do + subject { double.extend(described_class) } - context "single argument" do - before(:each) do - subject.instance_eval do - env :userpaths + context "single argument" do + before(:each) do + subject.instance_eval do + env :userpaths + end end + + its(:env) { is_expected.to use_userpaths } end - its(:env) { is_expected.to use_userpaths } - end - - context "multiple arguments" do - before(:each) do - subject.instance_eval do - env :userpaths, :std + context "multiple arguments" do + before(:each) do + subject.instance_eval do + env :userpaths, :std + end end - end - its(:env) { is_expected.to be_std } - its(:env) { is_expected.to use_userpaths } + its(:env) { is_expected.to be_std } + its(:env) { is_expected.to use_userpaths } + end end end diff --git a/Library/Homebrew/test/build_options_spec.rb b/Library/Homebrew/test/build_options_spec.rb index 5acc12f30a..1e6c9ea35f 100644 --- a/Library/Homebrew/test/build_options_spec.rb +++ b/Library/Homebrew/test/build_options_spec.rb @@ -1,10 +1,10 @@ require "build_options" require "options" -RSpec::Matchers.alias_matcher :be_built_with, :be_with -RSpec::Matchers.alias_matcher :be_built_without, :be_without - describe BuildOptions do + alias_matcher :be_built_with, :be_with + alias_matcher :be_built_without, :be_without + subject { described_class.new(args, opts) } let(:bad_build) { described_class.new(bad_args, opts) } let(:args) { Options.create(%w[--with-foo --with-bar --without-qux]) } diff --git a/Library/Homebrew/test/compiler_failure_spec.rb b/Library/Homebrew/test/compiler_failure_spec.rb index b4fab0b270..47b35d3bc9 100644 --- a/Library/Homebrew/test/compiler_failure_spec.rb +++ b/Library/Homebrew/test/compiler_failure_spec.rb @@ -1,8 +1,8 @@ require "compilers" -RSpec::Matchers.alias_matcher :fail_with, :be_fails_with - describe CompilerFailure do + alias_matcher :fail_with, :be_fails_with + describe "::create" do it "creates a failure when given a symbol" do failure = described_class.create(:clang) diff --git a/Library/Homebrew/test/dependable_spec.rb b/Library/Homebrew/test/dependable_spec.rb index b646b7634e..172305aa0e 100644 --- a/Library/Homebrew/test/dependable_spec.rb +++ b/Library/Homebrew/test/dependable_spec.rb @@ -1,8 +1,8 @@ require "dependable" -RSpec::Matchers.alias_matcher :be_a_build_dependency, :be_build - describe Dependable do + alias_matcher :be_a_build_dependency, :be_build + subject { double(tags: tags).extend(described_class) } let(:tags) { ["foo", "bar", :build] } diff --git a/Library/Homebrew/test/dependency_collector_spec.rb b/Library/Homebrew/test/dependency_collector_spec.rb index 82d1179395..c25ea9cf92 100644 --- a/Library/Homebrew/test/dependency_collector_spec.rb +++ b/Library/Homebrew/test/dependency_collector_spec.rb @@ -1,8 +1,8 @@ require "dependency_collector" -RSpec::Matchers.alias_matcher :be_a_build_requirement, :be_build - describe DependencyCollector do + alias_matcher :be_a_build_requirement, :be_build + def find_dependency(name) subject.deps.find { |dep| dep.name == name } end diff --git a/Library/Homebrew/test/dependency_spec.rb b/Library/Homebrew/test/dependency_spec.rb index 4af779cc38..4f1e8d474c 100644 --- a/Library/Homebrew/test/dependency_spec.rb +++ b/Library/Homebrew/test/dependency_spec.rb @@ -1,9 +1,9 @@ require "dependency" -RSpec::Matchers.alias_matcher :be_a_build_dependency, :be_build -RSpec::Matchers.alias_matcher :be_a_runtime_dependency, :be_run - describe Dependency do + alias_matcher :be_a_build_dependency, :be_build + alias_matcher :be_a_runtime_dependency, :be_run + describe "::new" do it "accepts a single tag" do dep = described_class.new("foo", %w[bar]) diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index b07ffaadca..97cc0f152e 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -1,10 +1,6 @@ require "dev-cmd/audit" require "formulary" -RSpec::Matchers.alias_matcher :have_data, :be_data -RSpec::Matchers.alias_matcher :have_end, :be_end -RSpec::Matchers.alias_matcher :have_trailing_newline, :be_trailing_newline - module Count def self.increment @count ||= 0 @@ -13,6 +9,10 @@ module Count end describe FormulaText do + alias_matcher :have_data, :be_data + alias_matcher :have_end, :be_end + alias_matcher :have_trailing_newline, :be_trailing_newline + let(:dir) { mktmpdir } def formula_text(name, body = nil, options = {}) diff --git a/Library/Homebrew/test/formula_installer_bottle_spec.rb b/Library/Homebrew/test/formula_installer_bottle_spec.rb index 8409e1ac78..824cdb36db 100644 --- a/Library/Homebrew/test/formula_installer_bottle_spec.rb +++ b/Library/Homebrew/test/formula_installer_bottle_spec.rb @@ -5,9 +5,9 @@ require "tab" require "test/support/fixtures/testball" require "test/support/fixtures/testball_bottle" -RSpec::Matchers.alias_matcher :pour_bottle, :be_pour_bottle - describe FormulaInstaller do + alias_matcher :pour_bottle, :be_pour_bottle + matcher :be_poured_from_bottle do match(&:poured_from_bottle) end diff --git a/Library/Homebrew/test/formula_installer_spec.rb b/Library/Homebrew/test/formula_installer_spec.rb index efe2bf5a25..d309a17da0 100644 --- a/Library/Homebrew/test/formula_installer_spec.rb +++ b/Library/Homebrew/test/formula_installer_spec.rb @@ -5,10 +5,10 @@ require "tab" require "test/support/fixtures/testball" require "test/support/fixtures/testball_bottle" -RSpec::Matchers.define_negated_matcher :need_bottle, :be_bottle_unneeded -RSpec::Matchers.alias_matcher :have_disabled_bottle, :be_bottle_disabled - describe FormulaInstaller do + define_negated_matcher :need_bottle, :be_bottle_unneeded + alias_matcher :have_disabled_bottle, :be_bottle_disabled + matcher :be_poured_from_bottle do match(&:poured_from_bottle) end diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index 1f98ca525b..5991e72d8e 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -1,19 +1,19 @@ require "test/support/fixtures/testball" require "formula" -RSpec::Matchers.alias_matcher :follow_installed_alias, :be_follow_installed_alias -RSpec::Matchers.alias_matcher :have_any_version_installed, :be_any_version_installed -RSpec::Matchers.alias_matcher :need_migration, :be_migration_needed - -RSpec::Matchers.alias_matcher :have_changed_installed_alias_target, :be_installed_alias_target_changed -RSpec::Matchers.alias_matcher :supersede_an_installed_formula, :be_supersedes_an_installed_formula -RSpec::Matchers.alias_matcher :have_changed_alias, :be_alias_changed - -RSpec::Matchers.alias_matcher :have_option_defined, :be_option_defined -RSpec::Matchers.alias_matcher :have_test_defined, :be_test_defined -RSpec::Matchers.alias_matcher :pour_bottle, :be_pour_bottle - describe Formula do + alias_matcher :follow_installed_alias, :be_follow_installed_alias + alias_matcher :have_any_version_installed, :be_any_version_installed + alias_matcher :need_migration, :be_migration_needed + + alias_matcher :have_changed_installed_alias_target, :be_installed_alias_target_changed + alias_matcher :supersede_an_installed_formula, :be_supersedes_an_installed_formula + alias_matcher :have_changed_alias, :be_alias_changed + + alias_matcher :have_option_defined, :be_option_defined + alias_matcher :have_test_defined, :be_test_defined + alias_matcher :pour_bottle, :be_pour_bottle + describe "::new" do let(:klass) do Class.new(described_class) do diff --git a/Library/Homebrew/test/os/mac/dependency_collector_spec.rb b/Library/Homebrew/test/os/mac/dependency_collector_spec.rb index 21b15cd992..688149021c 100644 --- a/Library/Homebrew/test/os/mac/dependency_collector_spec.rb +++ b/Library/Homebrew/test/os/mac/dependency_collector_spec.rb @@ -1,8 +1,8 @@ require "dependency_collector" -RSpec::Matchers.alias_matcher :need_tar_xz_dependency, :be_tar_needs_xz_dependency - describe DependencyCollector do + alias_matcher :need_tar_xz_dependency, :be_tar_needs_xz_dependency + after(:each) do described_class.clear_cache end diff --git a/Library/Homebrew/test/requirement_spec.rb b/Library/Homebrew/test/requirement_spec.rb index 959041cf4b..71372aa69e 100644 --- a/Library/Homebrew/test/requirement_spec.rb +++ b/Library/Homebrew/test/requirement_spec.rb @@ -1,10 +1,10 @@ require "extend/ENV" require "requirement" -RSpec::Matchers.alias_matcher :have_a_default_formula, :be_a_default_formula -RSpec::Matchers.alias_matcher :be_a_build_requirement, :be_a_build - describe Requirement do + alias_matcher :have_a_default_formula, :be_a_default_formula + alias_matcher :be_a_build_requirement, :be_a_build + subject { klass.new } let(:klass) { Class.new(described_class) } diff --git a/Library/Homebrew/test/sandbox_spec.rb b/Library/Homebrew/test/sandbox_spec.rb index 0d349f6eb5..eafec4dd46 100644 --- a/Library/Homebrew/test/sandbox_spec.rb +++ b/Library/Homebrew/test/sandbox_spec.rb @@ -1,8 +1,8 @@ require "sandbox" -RSpec::Matchers.define_negated_matcher :not_matching, :matching - describe Sandbox do + define_negated_matcher :not_matching, :matching + let(:dir) { mktmpdir } let(:file) { dir/"foo" } diff --git a/Library/Homebrew/test/software_spec_spec.rb b/Library/Homebrew/test/software_spec_spec.rb index 5fd4f598a9..e6eaeb2048 100644 --- a/Library/Homebrew/test/software_spec_spec.rb +++ b/Library/Homebrew/test/software_spec_spec.rb @@ -1,9 +1,9 @@ require "software_spec" -RSpec::Matchers.alias_matcher :have_defined_resource, :be_resource_defined -RSpec::Matchers.alias_matcher :have_defined_option, :be_option_defined - describe SoftwareSpec do + alias_matcher :have_defined_resource, :be_resource_defined + alias_matcher :have_defined_option, :be_option_defined + let(:owner) { double(name: "some_name", full_name: "some_name", tap: "homebrew/core") } describe "#resource" do diff --git a/Library/Homebrew/test/tab_spec.rb b/Library/Homebrew/test/tab_spec.rb index 1b0836c93f..93ae42ce49 100644 --- a/Library/Homebrew/test/tab_spec.rb +++ b/Library/Homebrew/test/tab_spec.rb @@ -1,9 +1,9 @@ require "tab" require "formula" -RSpec::Matchers.alias_matcher :be_built_with, :be_with - describe Tab do + alias_matcher :be_built_with, :be_with + matcher :be_poured_from_bottle do match do |actual| actual.poured_from_bottle == true diff --git a/Library/Homebrew/test/tap_spec.rb b/Library/Homebrew/test/tap_spec.rb index 50e4522af4..27b5e0c4b5 100644 --- a/Library/Homebrew/test/tap_spec.rb +++ b/Library/Homebrew/test/tap_spec.rb @@ -1,9 +1,9 @@ -RSpec::Matchers.alias_matcher :have_formula_file, :be_formula_file -RSpec::Matchers.alias_matcher :have_custom_remote, :be_custom_remote - describe Tap do include FileUtils + alias_matcher :have_formula_file, :be_formula_file + alias_matcher :have_custom_remote, :be_custom_remote + subject { described_class.new("Homebrew", "foo") } let(:path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" } let(:formula_file) { path/"Formula/foo.rb" }