From cfed07734c3eae46afc69d572fe2cc8bc68f0945 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 11 Feb 2017 18:46:56 +0100 Subject: [PATCH] Convert Homebrew::Hooks::Bottles test to spec. --- Library/Homebrew/test/bottle_hooks_spec.rb | 50 ++++++++++++++++++++++ Library/Homebrew/test/bottle_hooks_test.rb | 49 --------------------- 2 files changed, 50 insertions(+), 49 deletions(-) create mode 100644 Library/Homebrew/test/bottle_hooks_spec.rb delete mode 100644 Library/Homebrew/test/bottle_hooks_test.rb diff --git a/Library/Homebrew/test/bottle_hooks_spec.rb b/Library/Homebrew/test/bottle_hooks_spec.rb new file mode 100644 index 0000000000..05c6ea7f08 --- /dev/null +++ b/Library/Homebrew/test/bottle_hooks_spec.rb @@ -0,0 +1,50 @@ +require "formula_installer" +require "hooks/bottles" + +RSpec::Matchers.alias_matcher :pour_bottle, :be_pour_bottle + +describe Homebrew::Hooks::Bottles do + subject { FormulaInstaller.new formula } + + let(:formula) do + double( + bottle: nil, + local_bottle_path: nil, + bottle_disabled?: false, + some_random_method: true, + ) + end + + after(:each) do + described_class.reset_hooks + end + + describe "#setup_formula_has_bottle" do + context "given a block which evaluates to true" do + before(:each) do + described_class.setup_formula_has_bottle(&:some_random_method) + end + + it { is_expected.to pour_bottle } + end + + context "given a block which evaluates to false" do + before(:each) do + described_class.setup_formula_has_bottle { |f| !f.some_random_method } + end + + it { is_expected.not_to pour_bottle } + end + end + + describe "#setup_pour_formula_bottle" do + before(:each) do + described_class.setup_formula_has_bottle { true } + described_class.setup_pour_formula_bottle(&:some_random_method) + end + + it "does not raise an error" do + expect { subject.pour }.not_to raise_error + end + end +end diff --git a/Library/Homebrew/test/bottle_hooks_test.rb b/Library/Homebrew/test/bottle_hooks_test.rb deleted file mode 100644 index fd890192fb..0000000000 --- a/Library/Homebrew/test/bottle_hooks_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require "testing_env" -require "formula_installer" -require "hooks/bottles" - -class BottleHookTests < Homebrew::TestCase - class FormulaDouble - def bottle; end - def local_bottle_path; end - - def bottle_disabled? - false - end - - def some_random_method - true - end - end - - def setup - super - @fi = FormulaInstaller.new FormulaDouble.new - end - - def test_has_bottle - Homebrew::Hooks::Bottles.setup_formula_has_bottle(&:some_random_method) - assert_predicate @fi, :pour_bottle? - end - - def test_has_no_bottle - Homebrew::Hooks::Bottles.setup_formula_has_bottle do |f| - !f.some_random_method - end - refute_predicate @fi, :pour_bottle? - end - - def test_pour_formula_bottle - Homebrew::Hooks::Bottles.setup_formula_has_bottle do |_f| - true - end - - Homebrew::Hooks::Bottles.setup_pour_formula_bottle(&:some_random_method) - @fi.pour - end - - def teardown - Homebrew::Hooks::Bottles.reset_hooks - super - end -end