aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMike McQuaid2017-02-26 13:41:52 +0000
committerGitHub2017-02-26 13:41:52 +0000
commit689765443e4ef5a47b85c4191f19e3ef3baea08f (patch)
tree1b138443839e5be70feb329136e4e6ac80874981 /Library
parent765ece86c869b756a6ece173757394708ee73b88 (diff)
parentcc9d76cf227b4762431c710998727fb4f6f01dad (diff)
downloadbrew-689765443e4ef5a47b85c4191f19e3ef3baea08f.tar.bz2
Merge pull request #2201 from reitermarkus/spec-update-report
Convert `cmd/update-report` test to spec.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/test/cmd/update-report_spec.rb127
-rw-r--r--Library/Homebrew/test/update_report_test.rb135
2 files changed, 127 insertions, 135 deletions
diff --git a/Library/Homebrew/test/cmd/update-report_spec.rb b/Library/Homebrew/test/cmd/update-report_spec.rb
new file mode 100644
index 000000000..3665e3c78
--- /dev/null
+++ b/Library/Homebrew/test/cmd/update-report_spec.rb
@@ -0,0 +1,127 @@
+require "cmd/update-report"
+require "formula_versions"
+require "yaml"
+
+describe Reporter do
+ def perform_update(fixture_name = "")
+ allow(Formulary).to receive(:factory).and_return(double(pkg_version: "1.0"))
+ allow(FormulaVersions).to receive(:new).and_return(double(formula_at_revision: "2.0"))
+
+ diff = YAML.load_file("#{TEST_FIXTURE_DIR}/updater_fixture.yaml")[fixture_name]
+ allow(subject).to receive(:diff).and_return(diff || "")
+
+ hub.add(subject) if subject.updated?
+ end
+
+ let(:reporter_class) do
+ Class.new(described_class) do
+ def initialize(tap)
+ @tap = tap
+
+ ENV["HOMEBREW_UPDATE_BEFORE#{repo_var}"] = "12345678"
+ ENV["HOMEBREW_UPDATE_AFTER#{repo_var}"] = "abcdef00"
+
+ super(tap)
+ end
+ end
+ end
+ subject { reporter_class.new(tap) }
+ let(:tap) { CoreTap.new }
+ let(:hub) { ReporterHub.new }
+
+ specify "without revision variable" do
+ ENV.delete_if { |k, _v| k.start_with? "HOMEBREW_UPDATE" }
+
+ expect {
+ described_class.new(tap)
+ }.to raise_error(Reporter::ReporterRevisionUnsetError)
+ end
+
+ specify "without any changes" do
+ perform_update
+ expect(hub).to be_empty
+ end
+
+ specify "without Formula changes" do
+ perform_update("update_git_diff_output_without_formulae_changes")
+
+ expect(hub.select_formula(:M)).to be_empty
+ expect(hub.select_formula(:A)).to be_empty
+ expect(hub.select_formula(:D)).to be_empty
+ end
+
+ specify "with Formula changes" do
+ perform_update("update_git_diff_output_with_formulae_changes")
+
+ expect(hub.select_formula(:M)).to eq(%w[xar yajl])
+ expect(hub.select_formula(:A)).to eq(%w[antiword bash-completion ddrescue dict lua])
+ end
+
+ specify "with removed Formulae" do
+ perform_update("update_git_diff_output_with_removed_formulae")
+
+ expect(hub.select_formula(:D)).to eq(%w[libgsasl])
+ end
+
+ specify "with changed file type" do
+ perform_update("update_git_diff_output_with_changed_filetype")
+
+ expect(hub.select_formula(:M)).to eq(%w[elixir])
+ expect(hub.select_formula(:A)).to eq(%w[libbson])
+ expect(hub.select_formula(:D)).to eq(%w[libgsasl])
+ end
+
+ specify "with renamed Formula" do
+ allow(tap).to receive(:formula_renames).and_return("cv" => "progress")
+ perform_update("update_git_diff_output_with_formula_rename")
+
+ expect(hub.select_formula(:A)).to be_empty
+ expect(hub.select_formula(:D)).to be_empty
+ expect(hub.select_formula(:R)).to eq([["cv", "progress"]])
+ end
+
+ context "when updating a Tap other than the core Tap" do
+ let(:tap) { Tap.new("foo", "bar") }
+
+ before(:each) do
+ (tap.path/"Formula").mkpath
+ end
+
+ after(:each) do
+ tap.path.parent.rmtree
+ end
+
+ specify "with restructured Tap" do
+ perform_update("update_git_diff_output_with_restructured_tap")
+
+ expect(hub.select_formula(:A)).to be_empty
+ expect(hub.select_formula(:D)).to be_empty
+ expect(hub.select_formula(:R)).to be_empty
+ end
+
+ specify "with renamed Formula and restructured Tap" do
+ allow(tap).to receive(:formula_renames).and_return("xchat" => "xchat2")
+ perform_update("update_git_diff_output_with_formula_rename_and_restructuring")
+
+ expect(hub.select_formula(:A)).to be_empty
+ expect(hub.select_formula(:D)).to be_empty
+ expect(hub.select_formula(:R)).to eq([%w[foo/bar/xchat foo/bar/xchat2]])
+ end
+
+ specify "with simulated 'homebrew/php' restructuring" do
+ perform_update("update_git_diff_simulate_homebrew_php_restructuring")
+
+ expect(hub.select_formula(:A)).to be_empty
+ expect(hub.select_formula(:D)).to be_empty
+ expect(hub.select_formula(:R)).to be_empty
+ end
+
+ specify "with Formula changes" do
+ perform_update("update_git_diff_output_with_tap_formulae_changes")
+
+ expect(hub.select_formula(:A)).to eq(%w[foo/bar/lua])
+ expect(hub.select_formula(:M)).to eq(%w[foo/bar/git])
+ expect(hub.select_formula(:D)).to be_empty
+ end
+ end
+end
diff --git a/Library/Homebrew/test/update_report_test.rb b/Library/Homebrew/test/update_report_test.rb
deleted file mode 100644
index 32c3e36d0..000000000
--- a/Library/Homebrew/test/update_report_test.rb
+++ /dev/null
@@ -1,135 +0,0 @@
-require "testing_env"
-require "cmd/update-report"
-require "formula_versions"
-require "yaml"
-
-class ReportTests < Homebrew::TestCase
- class ReporterMock < ::Reporter
- attr_accessor :diff
-
- def initialize(tap)
- @tap = tap
- ENV["HOMEBREW_UPDATE_BEFORE#{repo_var}"] = "12345678"
- ENV["HOMEBREW_UPDATE_AFTER#{repo_var}"] = "abcdef12"
- super(tap)
- end
- end
-
- def fixture(name)
- self.class.fixture_data[name] || ""
- end
-
- def self.fixture_data
- @fixture_data ||= YAML.load_file("#{TEST_FIXTURE_DIR}/updater_fixture.yaml")
- end
-
- def setup
- super
- @tap = CoreTap.new
- @reporter = ReporterMock.new(@tap)
- @hub = ReporterHub.new
- end
-
- def perform_update(fixture_name = "")
- Formulary.stubs(:factory).returns(stub(pkg_version: "1.0"))
- FormulaVersions.stubs(:new).returns(stub(formula_at_revision: "2.0"))
- @reporter.diff = fixture(fixture_name)
- @hub.add(@reporter) if @reporter.updated?
- end
-
- def test_update_report_without_revision_var
- ENV.delete_if { |k, _v| k.start_with? "HOMEBREW_UPDATE" }
- assert_raises(Reporter::ReporterRevisionUnsetError) { Reporter.new(@tap) }
- end
-
- def test_update_homebrew_without_any_changes
- perform_update
- assert_empty @hub
- end
-
- def test_update_homebrew_without_formulae_changes
- perform_update("update_git_diff_output_without_formulae_changes")
- assert_empty @hub.select_formula(:M)
- assert_empty @hub.select_formula(:A)
- assert_empty @hub.select_formula(:D)
- end
-
- def test_update_homebrew_with_formulae_changes
- perform_update("update_git_diff_output_with_formulae_changes")
- assert_equal %w[xar yajl], @hub.select_formula(:M)
- assert_equal %w[antiword bash-completion ddrescue dict lua], @hub.select_formula(:A)
- end
-
- def test_update_homebrew_with_removed_formulae
- perform_update("update_git_diff_output_with_removed_formulae")
- assert_equal %w[libgsasl], @hub.select_formula(:D)
- end
-
- def test_update_homebrew_with_changed_filetype
- perform_update("update_git_diff_output_with_changed_filetype")
- assert_equal %w[elixir], @hub.select_formula(:M)
- assert_equal %w[libbson], @hub.select_formula(:A)
- assert_equal %w[libgsasl], @hub.select_formula(:D)
- end
-
- def test_update_homebrew_with_formula_rename
- @tap.stubs(:formula_renames).returns("cv" => "progress")
- perform_update("update_git_diff_output_with_formula_rename")
- assert_empty @hub.select_formula(:A)
- assert_empty @hub.select_formula(:D)
- assert_equal [["cv", "progress"]], @hub.select_formula(:R)
- end
-
- def test_update_homebrew_with_restructured_tap
- tap = Tap.new("foo", "bar")
- @reporter = ReporterMock.new(tap)
- tap.path.join("Formula").mkpath
-
- perform_update("update_git_diff_output_with_restructured_tap")
- assert_empty @hub.select_formula(:A)
- assert_empty @hub.select_formula(:D)
- assert_empty @hub.select_formula(:R)
- ensure
- tap.path.parent.rmtree
- end
-
- def test_update_homebrew_with_formula_rename_and_restructuring
- tap = Tap.new("foo", "bar")
- @reporter = ReporterMock.new(tap)
- tap.path.join("Formula").mkpath
- tap.stubs(:formula_renames).returns("xchat" => "xchat2")
-
- perform_update("update_git_diff_output_with_formula_rename_and_restructuring")
- assert_empty @hub.select_formula(:A)
- assert_empty @hub.select_formula(:D)
- assert_equal [%w[foo/bar/xchat foo/bar/xchat2]], @hub.select_formula(:R)
- ensure
- tap.path.parent.rmtree
- end
-
- def test_update_homebrew_simulate_homebrew_php_restructuring
- tap = Tap.new("foo", "bar")
- @reporter = ReporterMock.new(tap)
- tap.path.join("Formula").mkpath
-
- perform_update("update_git_diff_simulate_homebrew_php_restructuring")
- assert_empty @hub.select_formula(:A)
- assert_empty @hub.select_formula(:D)
- assert_empty @hub.select_formula(:R)
- ensure
- tap.path.parent.rmtree
- end
-
- def test_update_homebrew_with_tap_formulae_changes
- tap = Tap.new("foo", "bar")
- @reporter = ReporterMock.new(tap)
- tap.path.join("Formula").mkpath
-
- perform_update("update_git_diff_output_with_tap_formulae_changes")
- assert_equal %w[foo/bar/lua], @hub.select_formula(:A)
- assert_equal %w[foo/bar/git], @hub.select_formula(:M)
- assert_empty @hub.select_formula(:D)
- ensure
- tap.path.parent.rmtree
- end
-end