test/bundle: add additional test coverage.
Add missing test coverage, requires, fix a TODO and remove `needs_macos` from a cask test.
This commit is contained in:
parent
f9baac24a2
commit
cf8835eff7
@ -67,8 +67,7 @@ module Homebrew
|
||||
else
|
||||
Formula[@full_name].version
|
||||
end.to_s
|
||||
version_path = Pathname.new(@version_file)
|
||||
version_path.write("#{version}\n")
|
||||
File.write(@version_file, "#{version}\n")
|
||||
|
||||
puts "Wrote #{@name} version #{version} to #{@version_file}" if verbose
|
||||
end
|
||||
|
@ -260,6 +260,40 @@ RSpec.describe Homebrew::Bundle::BrewInstaller do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when the version_file option is provided" do
|
||||
before do
|
||||
Homebrew::Bundle.reset!
|
||||
|
||||
allow_any_instance_of(described_class).to receive(:install_change_state!).and_return(true)
|
||||
allow_any_instance_of(described_class).to receive(:installed?).and_return(true)
|
||||
allow_any_instance_of(described_class).to receive(:linked?).and_return(true)
|
||||
end
|
||||
|
||||
let(:version_file) { "version.txt" }
|
||||
let(:version) { "1.0" }
|
||||
|
||||
context "when formula versions are changed and specified by the environment" do
|
||||
before do
|
||||
allow_any_instance_of(described_class).to receive(:changed?).and_return(false)
|
||||
ENV["HOMEBREW_BUNDLE_EXEC_FORMULA_VERSION_#{formula_name.upcase}"] = version
|
||||
end
|
||||
|
||||
it "writes the version to the file" do
|
||||
expect(File).to receive(:write).with(version_file, "#{version}\n")
|
||||
described_class.preinstall(formula_name, version_file:)
|
||||
described_class.install(formula_name, version_file:)
|
||||
end
|
||||
end
|
||||
|
||||
context "when using the latest formula" do
|
||||
it "writes the version to the file" do
|
||||
expect(File).to receive(:write).with(version_file, "#{version}\n")
|
||||
described_class.preinstall(formula_name, version_file:)
|
||||
described_class.install(formula_name, version_file:)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when a formula isn't installed" do
|
||||
|
@ -3,6 +3,7 @@
|
||||
require "bundle"
|
||||
require "bundle/commands/check"
|
||||
require "bundle/brew_checker"
|
||||
require "bundle/cask_checker"
|
||||
require "bundle/mac_app_store_checker"
|
||||
require "bundle/vscode_extension_checker"
|
||||
require "bundle/brew_installer"
|
||||
@ -56,11 +57,23 @@ RSpec.describe Homebrew::Bundle::Commands::Check do
|
||||
end
|
||||
|
||||
context "when formulae are not installed" do
|
||||
it "raises an error" do
|
||||
let(:verbose) { true }
|
||||
|
||||
it "raises an error and outputs to stdout" do
|
||||
allow(Homebrew::Bundle::CaskDumper).to receive(:casks).and_return([])
|
||||
allow(Homebrew::Bundle::BrewInstaller).to receive(:upgradable_formulae).and_return([])
|
||||
allow_any_instance_of(Pathname).to receive(:read).and_return("brew 'abc'")
|
||||
expect { do_check }.to raise_error(SystemExit)
|
||||
expect { do_check }.to raise_error(SystemExit).and \
|
||||
output(/brew bundle can't satisfy your Brewfile's dependencies/).to_stdout
|
||||
end
|
||||
|
||||
it "partially outputs when HOMEBREW_BUNDLE_CHECK_ALREADY_OUTPUT_FORMULAE_ERRORS is set" do
|
||||
allow(Homebrew::Bundle::CaskDumper).to receive(:casks).and_return([])
|
||||
allow(Homebrew::Bundle::BrewInstaller).to receive(:upgradable_formulae).and_return([])
|
||||
allow_any_instance_of(Pathname).to receive(:read).and_return("brew 'abc'")
|
||||
ENV["HOMEBREW_BUNDLE_CHECK_ALREADY_OUTPUT_FORMULAE_ERRORS"] = "abc"
|
||||
expect { do_check }.to raise_error(SystemExit).and \
|
||||
output("Satisfy missing dependencies with `brew bundle install`.\n").to_stdout
|
||||
end
|
||||
|
||||
it "does not raise error on skippable formula" do
|
||||
|
@ -27,19 +27,16 @@ RSpec.describe Homebrew::Bundle::Skipper do
|
||||
end
|
||||
end
|
||||
|
||||
context "with an unbottled formula on ARM", :needs_macos do
|
||||
context "with an unbottled formula on ARM" do
|
||||
let(:entry) { Homebrew::Bundle::Dsl::Entry.new(:brew, "mysql") }
|
||||
|
||||
# TODO: remove OpenStruct usage
|
||||
# rubocop:todo Style/OpenStructUse
|
||||
it "returns true" do
|
||||
allow(Hardware::CPU).to receive(:arm?).and_return(true)
|
||||
allow_any_instance_of(Formula).to receive(:stable).and_return(OpenStruct.new(bottled?: false,
|
||||
bottle_defined?: true))
|
||||
allow(Homebrew).to receive(:default_prefix?).and_return(true)
|
||||
stub_formula_loader formula("mysql") { url "mysql-1.0" }
|
||||
|
||||
expect(skipper.skip?(entry)).to be true
|
||||
end
|
||||
# rubocop:enable Style/OpenStructUse
|
||||
end
|
||||
|
||||
context "with an unlisted cask", :needs_macos do
|
||||
|
Loading…
x
Reference in New Issue
Block a user