Skip to content

Commit

Permalink
Add tests for shared namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hmistry committed Jul 31, 2022
1 parent ef8c698 commit 1d34fa5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion spec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def hello
expect(Thor::Base.subclass_files[File.expand_path(thorfile)]).to eq([
MyScript, MyScript::AnotherScript, MyChildScript, Barn,
PackageNameScript, Scripts::MyScript, Scripts::MyDefaults,
Scripts::ChildDefault, Scripts::Arities
Scripts::ChildDefault, Scripts::Arities, Apple, Pear
])
end

Expand Down
9 changes: 9 additions & 0 deletions spec/fixtures/script.thor
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,12 @@ module Scripts
end
end

class Apple < Thor
namespace :fruits
desc 'apple', 'apple'; def apple; end
end

class Pear < Thor
namespace :fruits
desc 'pear', 'pear'; def pear; end
end
5 changes: 5 additions & 0 deletions spec/util_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ def self.clear_user_home!
it "falls back on the default namespace class if nothing else matches" do
expect(Thor::Util.find_class_and_command_by_namespace("test")).to eq([Scripts::MyDefaults, "test"])
end

it "returns correct Thor class and the command name when shared namespaces" do
expect(Thor::Util.find_class_and_command_by_namespace("fruits:apple")).to eq([Apple, "apple"])
expect(Thor::Util.find_class_and_command_by_namespace("fruits:pear")).to eq([Pear, "pear"])
end
end

describe "#thor_classes_in" do
Expand Down

0 comments on commit 1d34fa5

Please sign in to comment.