Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New gem template: prefer require_relative to require #4066

Merged
merged 1 commit into from Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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