Skip to content

Commit

Permalink
New gem template: prefer require_relative to require
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Nov 17, 2020
1 parent 1fa4ee3 commit 74ca9ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions bundler/lib/bundler/templates/newgem/lib/newgem.rb.tt
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require "<%= config[:namespaced_path] %>/version"
require_relative "<%=File.basename(config[:namespaced_path])%>/version"
<%- if config[:ext] -%>
require "<%= config[:namespaced_path] %>/<%= config[:underscored_name] %>"
require_relative "<%= File.basename(config[:namespaced_path]) %>/<%= config[:underscored_name] %>"
<%- end -%>

<%- config[:constant_array].each_with_index do |c, i| -%>
Expand Down
6 changes: 5 additions & 1 deletion bundler/spec/commands/newgem_spec.rb
Expand Up @@ -424,7 +424,7 @@ def create_temporary_dir(dir)
it "requires the version file" do
bundle "gem #{gem_name}"

expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(%r{require "#{require_path}/version"})
expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(%r{require_relative "#{require_relative_path}/version"})
end

it "creates a base error class" do
Expand Down Expand Up @@ -911,6 +911,8 @@ def create_temporary_dir(dir)

let(:require_path) { "test_gem" }

let(:require_relative_path) { "test_gem" }

let(:flags) { nil }

it "does not nest constants" do
Expand Down Expand Up @@ -964,6 +966,8 @@ def create_temporary_dir(dir)

let(:require_path) { "test/gem" }

let(:require_relative_path) { "gem" }

it "nests constants so they work" do
bundle "gem #{gem_name}"
expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb").read).to match(/module Test\n module Gem/)
Expand Down

0 comments on commit 74ca9ae

Please sign in to comment.