Merge pull request #17007 from Homebrew/remote-tap-tests

Clean up args_parse tests
This commit is contained in:
Mike McQuaid 2024-04-02 20:49:53 +01:00 committed by GitHub
commit f0e442d88f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 36 additions and 32 deletions

View File

@ -1,23 +1,25 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.describe "brew bundle", :integration_test do require "cmd/shared_examples/args_parse"
describe "check" do
it "checks if a Brewfile's dependencies are satisfied", :needs_network do
setup_remote_tap "homebrew/bundle"
HOMEBREW_REPOSITORY.cd do RSpec.describe "Homebrew::Cmd::BundleCmd", :integration_test, :needs_network do
system "git", "init" before { setup_remote_tap "homebrew/bundle" }
system "git", "commit", "--allow-empty", "-m", "This is a test commit"
end
mktmpdir do |path| it_behaves_like "parseable arguments", command_name: "bundle"
FileUtils.touch "#{path}/Brewfile"
path.cd do it "checks if a Brewfile's dependencies are satisfied" do
expect { brew "bundle", "check" } HOMEBREW_REPOSITORY.cd do
.to output("The Brewfile's dependencies are satisfied.\n").to_stdout system "git", "init"
.and not_to_output.to_stderr system "git", "commit", "--allow-empty", "-m", "This is a test commit"
.and be_a_success end
end
mktmpdir do |path|
FileUtils.touch "#{path}/Brewfile"
path.cd do
expect { brew "bundle", "check" }
.to output("The Brewfile's dependencies are satisfied.\n").to_stdout
.and not_to_output.to_stderr
.and be_a_success
end end
end end
end end

View File

@ -1,9 +1,13 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.describe "brew services", :integration_test, :needs_network do require "cmd/shared_examples/args_parse"
it "allows controlling services" do
setup_remote_tap "homebrew/services"
RSpec.describe "Homebrew::Cmd::Services", :integration_test, :needs_network do
before { setup_remote_tap "homebrew/services" }
it_behaves_like "parseable arguments", command_name: "services"
it "allows controlling services" do
expect { brew "services", "list" } expect { brew "services", "list" }
.to not_to_output.to_stderr .to not_to_output.to_stderr
.and not_to_output.to_stdout .and not_to_output.to_stdout

View File

@ -1,22 +1,20 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples "parseable arguments" do |argv: nil| RSpec.shared_examples "parseable arguments" do |command_name: nil|
subject(:method_name) { "#{command_name.tr("-", "_")}_args" } let(:command) do |example|
example.metadata.dig(:example_group, :parent_example_group, :description)
let(:command_name) do |example|
example.metadata[:example_group][:parent_example_group][:description].delete_prefix("brew ")
end end
it "can parse arguments" do it "can parse arguments" do
if described_class if described_class
argv ||= described_class.parser.instance_variable_get(:@min_named_args)&.times&.map { "argument" } klass = described_class
argv ||= []
cmd = described_class.new(argv)
expect(cmd.args).to be_a Homebrew::CLI::Args
else else
require "dev-cmd/#{command_name}" unless require? "cmd/#{command_name}" # for tests of remote taps, we need to load the command class
parser = Homebrew.public_send(method_name) require(Commands.external_ruby_v2_cmd_path(command_name))
expect(parser).to respond_to(:parse) klass = Object.const_get(command)
end end
argv = klass.parser.instance_variable_get(:@min_named_args)&.times&.map { "argument" } || []
cmd = klass.new(argv)
expect(cmd.args).to be_a Homebrew::CLI::Args
end end
end end

View File

@ -4,7 +4,7 @@ require "cmd/shared_examples/args_parse"
require "dev-cmd/prof" require "dev-cmd/prof"
RSpec.describe Homebrew::DevCmd::Prof do RSpec.describe Homebrew::DevCmd::Prof do
it_behaves_like "parseable arguments", argv: ["--", "help"] it_behaves_like "parseable arguments"
describe "integration tests", :integration_test, :needs_network do describe "integration tests", :integration_test, :needs_network do
after do after do