aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Library/Homebrew/extend/ARGV.rb3
-rw-r--r--Library/Homebrew/test/audit_test.rb49
-rw-r--r--Library/Homebrew/test/dev-cmd/audit_spec.rb61
-rw-r--r--Library/Homebrew/test/formula_installer_bottle_spec.rb81
-rw-r--r--Library/Homebrew/test/formula_installer_bottle_test.rb78
-rw-r--r--Library/Homebrew/test/spec_helper.rb21
6 files changed, 154 insertions, 139 deletions
diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb
index 0825b13a7..8cc2ccbc0 100644
--- a/Library/Homebrew/extend/ARGV.rb
+++ b/Library/Homebrew/extend/ARGV.rb
@@ -133,9 +133,8 @@ module HomebrewArgvExtension
end
end
- # self documenting perhaps?
def include?(arg)
- @n=index arg
+ !(@n = index(arg)).nil?
end
def next
diff --git a/Library/Homebrew/test/audit_test.rb b/Library/Homebrew/test/audit_test.rb
index 66e5af567..b8f01602c 100644
--- a/Library/Homebrew/test/audit_test.rb
+++ b/Library/Homebrew/test/audit_test.rb
@@ -4,55 +4,6 @@ require "pathname"
require "formulary"
require "dev-cmd/audit"
-class FormulaTextTests < Homebrew::TestCase
- def setup
- super
- @dir = mktmpdir
- end
-
- def formula_text(name, body = nil, options = {})
- path = Pathname.new "#{@dir}/#{name}.rb"
- path.open("w") do |f|
- f.write <<-EOS.undent
- class #{Formulary.class_s(name)} < Formula
- #{body}
- end
- #{options[:patch]}
- EOS
- end
- FormulaText.new path
- end
-
- def test_simple_valid_formula
- ft = formula_text "valid", 'url "http://www.example.com/valid-1.0.tar.gz"'
-
- refute ft.data?, "The formula should not have DATA"
- refute ft.end?, "The formula should not have __END__"
- assert ft.trailing_newline?, "The formula should have a trailing newline"
-
- assert ft =~ /\burl\b/, "The formula should match 'url'"
- assert_nil ft.line_number(/desc/), "The formula should not match 'desc'"
- assert_equal 2, ft.line_number(/\burl\b/)
- assert ft.include?("Valid"), "The formula should include \"Valid\""
- end
-
- def test_trailing_newline
- ft = formula_text "newline"
- assert ft.trailing_newline?, "The formula must have a trailing newline"
- end
-
- def test_has_data
- ft = formula_text "data", "patch :DATA"
- assert ft.data?, "The formula must have DATA"
- end
-
- def test_has_end
- ft = formula_text "end", "", patch: "__END__\na patch here"
- assert ft.end?, "The formula must have __END__"
- assert_equal "class End < Formula\n \nend", ft.without_patch
- end
-end
-
class FormulaAuditorTests < Homebrew::TestCase
def setup
super
diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb
new file mode 100644
index 000000000..397e6912d
--- /dev/null
+++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb
@@ -0,0 +1,61 @@
+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
+
+describe FormulaText do
+ let(:dir) { @dir = Pathname.new(Dir.mktmpdir) }
+
+ after(:each) do
+ dir.rmtree unless @dir.nil?
+ end
+
+ def formula_text(name, body = nil, options = {})
+ path = dir/"#{name}.rb"
+
+ path.write <<-EOS.undent
+ class #{Formulary.class_s(name)} < Formula
+ #{body}
+ end
+ #{options[:patch]}
+ EOS
+
+ described_class.new(path)
+ end
+
+ specify "simple valid Formula" do
+ ft = formula_text "valid", <<-EOS.undent
+ url "http://www.example.com/valid-1.0.tar.gz"
+ EOS
+
+ expect(ft).not_to have_data
+ expect(ft).not_to have_end
+ expect(ft).to have_trailing_newline
+
+ expect(ft =~ /\burl\b/).to be_truthy
+ expect(ft.line_number(/desc/)).to be nil
+ expect(ft.line_number(/\burl\b/)).to eq(2)
+ expect(ft).to include("Valid")
+ end
+
+ specify "#trailing_newline?" do
+ ft = formula_text "newline"
+ expect(ft).to have_trailing_newline
+ end
+
+ specify "#data?" do
+ ft = formula_text "data", <<-EOS.undent
+ patch :DATA
+ EOS
+
+ expect(ft).to have_data
+ end
+
+ specify "#end?" do
+ ft = formula_text "end", "", patch: "__END__\na patch here"
+ expect(ft).to have_end
+ expect(ft.without_patch).to eq("class End < Formula\n \nend")
+ end
+end
diff --git a/Library/Homebrew/test/formula_installer_bottle_spec.rb b/Library/Homebrew/test/formula_installer_bottle_spec.rb
new file mode 100644
index 000000000..8409e1ac7
--- /dev/null
+++ b/Library/Homebrew/test/formula_installer_bottle_spec.rb
@@ -0,0 +1,81 @@
+require "formula"
+require "formula_installer"
+require "keg"
+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
+ matcher :be_poured_from_bottle do
+ match(&:poured_from_bottle)
+ end
+
+ def temporarily_install_bottle(formula)
+ expect(formula).not_to be_installed
+ expect(formula).to be_bottled
+ expect(formula).to pour_bottle
+
+ shutup do
+ described_class.new(formula).install
+ end
+
+ keg = Keg.new(formula.prefix)
+
+ expect(formula).to be_installed
+
+ begin
+ expect(Tab.for_keg(keg)).to be_poured_from_bottle
+
+ yield formula
+ ensure
+ keg.unlink
+ keg.uninstall
+ formula.clear_cache
+ formula.bottle.clear_cache
+ end
+
+ expect(keg).not_to exist
+ expect(formula).not_to be_installed
+ end
+
+ specify "basic bottle install" do
+ allow(DevelopmentTools).to receive(:installed?).and_return(false)
+
+ temporarily_install_bottle(TestballBottle.new) do |f|
+ # Copied directly from formula_installer_spec.rb
+ # as we expect the same behavior.
+
+ # Test that things made it into the Keg
+ expect(f.bin).to be_a_directory
+
+ expect(f.libexec).to be_a_directory
+
+ expect(f.prefix/"main.c").not_to exist
+
+ # Test that things made it into the Cellar
+ keg = Keg.new f.prefix
+ keg.link
+
+ bin = HOMEBREW_PREFIX/"bin"
+ expect(bin).to be_a_directory
+ end
+ end
+
+ specify "build tools error" do
+ allow(DevelopmentTools).to receive(:installed?).and_return(false)
+
+ # Testball doesn't have a bottle block, so use it to test this behavior
+ formula = Testball.new
+
+ expect(formula).not_to be_installed
+ expect(formula).not_to be_bottled
+
+ expect {
+ FormulaInstaller.new(formula).install
+ }.to raise_error(BuildToolsError)
+
+ expect(formula).not_to be_installed
+ end
+end
diff --git a/Library/Homebrew/test/formula_installer_bottle_test.rb b/Library/Homebrew/test/formula_installer_bottle_test.rb
deleted file mode 100644
index 6a891f159..000000000
--- a/Library/Homebrew/test/formula_installer_bottle_test.rb
+++ /dev/null
@@ -1,78 +0,0 @@
-require "testing_env"
-require "formula"
-require "formula_installer"
-require "keg"
-require "tab"
-require "test/support/fixtures/testball"
-require "test/support/fixtures/testball_bottle"
-
-class InstallBottleTests < Homebrew::TestCase
- def temporary_bottle_install(formula)
- refute_predicate formula, :installed?
- assert_predicate formula, :bottled?
- assert_predicate formula, :pour_bottle?
-
- installer = FormulaInstaller.new(formula)
-
- shutup { installer.install }
-
- keg = Keg.new(formula.prefix)
-
- assert_predicate formula, :installed?
-
- begin
- assert_predicate Tab.for_keg(keg), :poured_from_bottle
-
- yield formula
- ensure
- keg.unlink
- keg.uninstall
- formula.clear_cache
- formula.bottle.clear_cache
- end
-
- refute_predicate keg, :exist?
- refute_predicate formula, :installed?
- end
-
- def test_a_basic_bottle_install
- DevelopmentTools.stubs(:installed?).returns(false)
-
- temporary_bottle_install(TestballBottle.new) do |f|
- # Copied directly from test_formula_installer.rb as we expect
- # the same behavior
-
- # Test that things made it into the Keg
- assert_predicate f.bin, :directory?
-
- assert_predicate f.libexec, :directory?
-
- refute_predicate f.prefix+"main.c", :exist?
-
- # Test that things make it into the Cellar
- keg = Keg.new f.prefix
- keg.link
-
- bin = HOMEBREW_PREFIX+"bin"
- assert_predicate bin, :directory?
- end
- end
-
- def test_build_tools_error
- DevelopmentTools.stubs(:installed?).returns(false)
-
- # Testball doesn't have a bottle block, so use it to test this behavior
- formula = Testball.new
-
- refute_predicate formula, :installed?
- refute_predicate formula, :bottled?
-
- installer = FormulaInstaller.new(formula)
-
- assert_raises(BuildToolsError) do
- installer.install
- end
-
- refute_predicate formula, :installed?
- end
-end
diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb
index 9a4dbe026..193de6b8f 100644
--- a/Library/Homebrew/test/spec_helper.rb
+++ b/Library/Homebrew/test/spec_helper.rb
@@ -31,22 +31,23 @@ TEST_DIRECTORIES = [
RSpec.configure do |config|
config.order = :random
+
config.include(Test::Helper::Shutup)
config.include(Test::Helper::Fixtures)
config.include(Test::Helper::Formula)
- config.before(:each) do |example|
- if example.metadata[:needs_macos]
- skip "Not on macOS." unless OS.mac?
- end
- if example.metadata[:needs_official_cmd_taps]
- skip "Needs official command Taps." unless ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"]
- end
+ config.before(:each, :needs_official_cmd_taps) do
+ skip "Needs official command Taps." unless ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"]
+ end
- if example.metadata[:needs_python]
- skip "Python not installed." unless which("python")
- end
+ config.before(:each, :needs_macos) do
+ skip "Not on macOS." unless OS.mac?
+ end
+
+ config.before(:each, :needs_python) do
+ skip "Python not installed." unless which("python")
end
+
config.around(:each) do |example|
begin
TEST_DIRECTORIES.each(&:mkpath)