Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17007 from Homebrew/remote-tap-tests
Clean up args_parse tests
- Loading branch information
Showing
4 changed files
with
36 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_examples "parseable arguments" do |argv: nil| | ||
subject(:method_name) { "#{command_name.tr("-", "_")}_args" } | ||
|
||
let(:command_name) do |example| | ||
example.metadata[:example_group][:parent_example_group][:description].delete_prefix("brew ") | ||
RSpec.shared_examples "parseable arguments" do |command_name: nil| | ||
let(:command) do |example| | ||
example.metadata.dig(:example_group, :parent_example_group, :description) | ||
end | ||
|
||
it "can parse arguments" do | ||
if described_class | ||
argv ||= described_class.parser.instance_variable_get(:@min_named_args)&.times&.map { "argument" } | ||
argv ||= [] | ||
cmd = described_class.new(argv) | ||
expect(cmd.args).to be_a Homebrew::CLI::Args | ||
klass = described_class | ||
else | ||
require "dev-cmd/#{command_name}" unless require? "cmd/#{command_name}" | ||
parser = Homebrew.public_send(method_name) | ||
expect(parser).to respond_to(:parse) | ||
# for tests of remote taps, we need to load the command class | ||
require(Commands.external_ruby_v2_cmd_path(command_name)) | ||
klass = Object.const_get(command) | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters