Use scoped RSpec matchers.

This commit is contained in:
Markus Reiter 2017-05-09 23:00:51 +02:00
parent ea8be174f6
commit 3cdf8f938a
21 changed files with 90 additions and 90 deletions

View File

@ -22,12 +22,12 @@ class BuildEnvironment
def userpaths? def userpaths?
@settings.include? :userpaths @settings.include? :userpaths
end end
end
module BuildEnvironmentDSL module DSL
def env(*settings) def env(*settings)
@env ||= BuildEnvironment.new @env ||= BuildEnvironment.new
@env.merge(settings) @env.merge(settings)
end
end end
end end

View File

@ -1997,7 +1997,7 @@ class Formula
# The methods below define the formula DSL. # The methods below define the formula DSL.
class << self class << self
include BuildEnvironmentDSL include BuildEnvironment::DSL
# The reason for why this software is not linked (by default) to # The reason for why this software is not linked (by default) to
# {::HOMEBREW_PREFIX}. # {::HOMEBREW_PREFIX}.

View File

@ -159,7 +159,7 @@ class Requirement
end end
class << self class << self
include BuildEnvironmentDSL include BuildEnvironment::DSL
attr_reader :env_proc, :build attr_reader :env_proc, :build
attr_rw :fatal, :default_formula attr_rw :fatal, :default_formula

View File

@ -1,20 +1,20 @@
require "open3" 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 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 context "brew" do
subject { HOMEBREW_LIBRARY_PATH.parent.parent/"bin/brew" } subject { HOMEBREW_LIBRARY_PATH.parent.parent/"bin/brew" }
it { is_expected.to have_valid_bash_syntax } it { is_expected.to have_valid_bash_syntax }

View File

@ -1,9 +1,9 @@
require "formula_installer" require "formula_installer"
require "hooks/bottles" require "hooks/bottles"
RSpec::Matchers.alias_matcher :pour_bottle, :be_pour_bottle
describe Homebrew::Hooks::Bottles do describe Homebrew::Hooks::Bottles do
alias_matcher :pour_bottle, :be_pour_bottle
subject { FormulaInstaller.new formula } subject { FormulaInstaller.new formula }
let(:formula) do let(:formula) do

View File

@ -1,8 +1,8 @@
require "build_environment" require "build_environment"
RSpec::Matchers.alias_matcher :use_userpaths, :be_userpaths
describe BuildEnvironment do describe BuildEnvironment do
alias_matcher :use_userpaths, :be_userpaths
let(:env) { described_class.new } let(:env) { described_class.new }
describe "#<<" do describe "#<<" do
@ -38,29 +38,29 @@ describe BuildEnvironment do
expect(env).not_to use_userpaths expect(env).not_to use_userpaths
end end
end end
end
describe BuildEnvironmentDSL do describe BuildEnvironment::DSL do
subject { double.extend(described_class) } subject { double.extend(described_class) }
context "single argument" do context "single argument" do
before(:each) do before(:each) do
subject.instance_eval do subject.instance_eval do
env :userpaths env :userpaths
end
end end
its(:env) { is_expected.to use_userpaths }
end end
its(:env) { is_expected.to use_userpaths } context "multiple arguments" do
end before(:each) do
subject.instance_eval do
context "multiple arguments" do env :userpaths, :std
before(:each) do end
subject.instance_eval do
env :userpaths, :std
end end
end
its(:env) { is_expected.to be_std } its(:env) { is_expected.to be_std }
its(:env) { is_expected.to use_userpaths } its(:env) { is_expected.to use_userpaths }
end
end end
end end

View File

@ -1,10 +1,10 @@
require "build_options" require "build_options"
require "options" require "options"
RSpec::Matchers.alias_matcher :be_built_with, :be_with
RSpec::Matchers.alias_matcher :be_built_without, :be_without
describe BuildOptions do describe BuildOptions do
alias_matcher :be_built_with, :be_with
alias_matcher :be_built_without, :be_without
subject { described_class.new(args, opts) } subject { described_class.new(args, opts) }
let(:bad_build) { described_class.new(bad_args, opts) } let(:bad_build) { described_class.new(bad_args, opts) }
let(:args) { Options.create(%w[--with-foo --with-bar --without-qux]) } let(:args) { Options.create(%w[--with-foo --with-bar --without-qux]) }

View File

@ -1,8 +1,8 @@
require "compilers" require "compilers"
RSpec::Matchers.alias_matcher :fail_with, :be_fails_with
describe CompilerFailure do describe CompilerFailure do
alias_matcher :fail_with, :be_fails_with
describe "::create" do describe "::create" do
it "creates a failure when given a symbol" do it "creates a failure when given a symbol" do
failure = described_class.create(:clang) failure = described_class.create(:clang)

View File

@ -1,8 +1,8 @@
require "dependable" require "dependable"
RSpec::Matchers.alias_matcher :be_a_build_dependency, :be_build
describe Dependable do describe Dependable do
alias_matcher :be_a_build_dependency, :be_build
subject { double(tags: tags).extend(described_class) } subject { double(tags: tags).extend(described_class) }
let(:tags) { ["foo", "bar", :build] } let(:tags) { ["foo", "bar", :build] }

View File

@ -1,8 +1,8 @@
require "dependency_collector" require "dependency_collector"
RSpec::Matchers.alias_matcher :be_a_build_requirement, :be_build
describe DependencyCollector do describe DependencyCollector do
alias_matcher :be_a_build_requirement, :be_build
def find_dependency(name) def find_dependency(name)
subject.deps.find { |dep| dep.name == name } subject.deps.find { |dep| dep.name == name }
end end

View File

@ -1,9 +1,9 @@
require "dependency" 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 describe Dependency do
alias_matcher :be_a_build_dependency, :be_build
alias_matcher :be_a_runtime_dependency, :be_run
describe "::new" do describe "::new" do
it "accepts a single tag" do it "accepts a single tag" do
dep = described_class.new("foo", %w[bar]) dep = described_class.new("foo", %w[bar])

View File

@ -1,10 +1,6 @@
require "dev-cmd/audit" require "dev-cmd/audit"
require "formulary" 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 module Count
def self.increment def self.increment
@count ||= 0 @count ||= 0
@ -13,6 +9,10 @@ module Count
end end
describe FormulaText do 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 } let(:dir) { mktmpdir }
def formula_text(name, body = nil, options = {}) def formula_text(name, body = nil, options = {})

View File

@ -5,9 +5,9 @@ require "tab"
require "test/support/fixtures/testball" require "test/support/fixtures/testball"
require "test/support/fixtures/testball_bottle" require "test/support/fixtures/testball_bottle"
RSpec::Matchers.alias_matcher :pour_bottle, :be_pour_bottle
describe FormulaInstaller do describe FormulaInstaller do
alias_matcher :pour_bottle, :be_pour_bottle
matcher :be_poured_from_bottle do matcher :be_poured_from_bottle do
match(&:poured_from_bottle) match(&:poured_from_bottle)
end end

View File

@ -5,10 +5,10 @@ require "tab"
require "test/support/fixtures/testball" require "test/support/fixtures/testball"
require "test/support/fixtures/testball_bottle" 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 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 matcher :be_poured_from_bottle do
match(&:poured_from_bottle) match(&:poured_from_bottle)
end end

View File

@ -1,19 +1,19 @@
require "test/support/fixtures/testball" require "test/support/fixtures/testball"
require "formula" 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 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 describe "::new" do
let(:klass) do let(:klass) do
Class.new(described_class) do Class.new(described_class) do

View File

@ -1,8 +1,8 @@
require "dependency_collector" require "dependency_collector"
RSpec::Matchers.alias_matcher :need_tar_xz_dependency, :be_tar_needs_xz_dependency
describe DependencyCollector do describe DependencyCollector do
alias_matcher :need_tar_xz_dependency, :be_tar_needs_xz_dependency
after(:each) do after(:each) do
described_class.clear_cache described_class.clear_cache
end end

View File

@ -1,10 +1,10 @@
require "extend/ENV" require "extend/ENV"
require "requirement" 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 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 } subject { klass.new }
let(:klass) { Class.new(described_class) } let(:klass) { Class.new(described_class) }

View File

@ -1,8 +1,8 @@
require "sandbox" require "sandbox"
RSpec::Matchers.define_negated_matcher :not_matching, :matching
describe Sandbox do describe Sandbox do
define_negated_matcher :not_matching, :matching
let(:dir) { mktmpdir } let(:dir) { mktmpdir }
let(:file) { dir/"foo" } let(:file) { dir/"foo" }

View File

@ -1,9 +1,9 @@
require "software_spec" 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 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") } let(:owner) { double(name: "some_name", full_name: "some_name", tap: "homebrew/core") }
describe "#resource" do describe "#resource" do

View File

@ -1,9 +1,9 @@
require "tab" require "tab"
require "formula" require "formula"
RSpec::Matchers.alias_matcher :be_built_with, :be_with
describe Tab do describe Tab do
alias_matcher :be_built_with, :be_with
matcher :be_poured_from_bottle do matcher :be_poured_from_bottle do
match do |actual| match do |actual|
actual.poured_from_bottle == true actual.poured_from_bottle == true

View File

@ -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 describe Tap do
include FileUtils include FileUtils
alias_matcher :have_formula_file, :be_formula_file
alias_matcher :have_custom_remote, :be_custom_remote
subject { described_class.new("Homebrew", "foo") } subject { described_class.new("Homebrew", "foo") }
let(:path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" } let(:path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" }
let(:formula_file) { path/"Formula/foo.rb" } let(:formula_file) { path/"Formula/foo.rb" }