diff --git a/toys/lib/toys/templates/gem_build.rb b/toys/lib/toys/templates/gem_build.rb index c20c8eb5..509267b0 100644 --- a/toys/lib/toys/templates/gem_build.rb +++ b/toys/lib/toys/templates/gem_build.rb @@ -186,13 +186,16 @@ def name # def gem_name(context_dir = nil) return @gem_name if @gem_name - glob = "*.gemspec" - glob = ::File.join(context_dir, glob) if context_dir - candidates = ::Dir.glob(glob) + candidates = + if context_dir + Compat.glob_in_dir("*.gemspec", context_dir) + else + ::Dir.glob("*.gemspec") + end if candidates.empty? raise ToolDefinitionError, "Could not find a gemspec" end - candidates.first.sub(/\.gemspec$/, "") + ::File.basename(candidates.first, ".gemspec") end ## diff --git a/toys/test/test_gem_build.rb b/toys/test/test_gem_build.rb index 819b09d8..340606ae 100644 --- a/toys/test/test_gem_build.rb +++ b/toys/test/test_gem_build.rb @@ -27,6 +27,14 @@ assert_equal("toys", template.gem_name) end + it "handles the gem_name field with a context dir" do + assert_equal("toys", template.gem_name(toys_dir)) + template.gem_name = "toys-core" + assert_equal("toys-core", template.gem_name(toys_dir)) + template.gem_name = nil + assert_equal("toys", template.gem_name(toys_dir)) + end + it "handles the output field" do assert_nil(template.output) template.output = "/path/to/somewhere"