mirror of
https://github.com/Homebrew/brew.git
synced 2026-08-12 22:29:27 +04:00
- Tests reached into private APIs with `send` and poked internal state via `instance_variable_get`/`instance_variable_set`, hiding which interfaces specs really exercise and letting visibility rot. - Make every statically-poked method public and call it directly, keeping `public_send` only for dynamically-named public methods. - Read and write state through public `attr_*` accessors instead of instance variable reflection. - Add `Homebrew/NoSendInTests` and `Homebrew/NoInstanceVariableAccessInTests` cops scoped to `Library/Homebrew/test` so neither pattern creeps back in. - Keep rare justified disables, e.g. `Module#remove_const` is private core Ruby and raw memoisation state has no accessor.
25 lines
816 B
Ruby
25 lines
816 B
Ruby
# typed: false
|
|
# frozen_string_literal: true
|
|
|
|
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
|
|
klass = described_class
|
|
else
|
|
# for tests of remote taps, we need to load the command class
|
|
require(Commands.external_ruby_v2_cmd_path(command_name))
|
|
# The command class name is only known at runtime.
|
|
# rubocop:disable Sorbet/ConstantsFromStrings
|
|
klass = Object.const_get(command)
|
|
# rubocop:enable Sorbet/ConstantsFromStrings
|
|
end
|
|
argv = klass.parser.min_named_args&.times&.map { "argument" } || []
|
|
cmd = klass.new(argv)
|
|
expect(cmd.args).to be_a Homebrew::CLI::Args
|
|
end
|
|
end
|