-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
require "abstract_command" | ||
|
||
RSpec.describe Homebrew::AbstractCommand do | ||
describe "subclasses" do | ||
before do | ||
cat = Class.new(described_class) do | ||
cmd_args do | ||
switch "--foo" | ||
flag "--bar=" | ||
end | ||
def run; end | ||
end | ||
stub_const("Cat", cat) | ||
end | ||
|
||
describe "parsing args" do | ||
it "parses valid args" do | ||
expect { Cat.new(["--foo"]).run }.not_to raise_error | ||
end | ||
|
||
it "allows access to args" do | ||
expect(Cat.new(["--bar", "baz"]).args[:bar]).to eq("baz") | ||
end | ||
|
||
it "raises on invalid args" do | ||
expect { Cat.new(["--bat"]) }.to raise_error(OptionParser::InvalidOption) | ||
end | ||
end | ||
|
||
describe "command names" do | ||
it "has a default command name" do | ||
expect(Cat.command_name).to eq("cat") | ||
end | ||
|
||
it "can lookup command" do | ||
expect(described_class.command("cat")).to be(Cat) | ||
end | ||
|
||
describe "when command name is overridden" do | ||
before do | ||
tac = Class.new(described_class) do | ||
def self.command_name = "t-a-c" | ||
def run; end | ||
end | ||
stub_const("Tac", tac) | ||
end | ||
|
||
it "can be looked up by command name" do | ||
expect(described_class.command("t-a-c")).to be(Tac) | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# typed: strict | ||
|
||
class Cat < Homebrew::AbstractCommand; end | ||
class Tac < Homebrew::AbstractCommand; end |