From 00fd58eaa69015092ee272c4cb5aa92a5e7ee45c Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Thu, 5 Apr 2018 19:58:03 +0900 Subject: [PATCH] Use `__dir__` instead of `__FILE__` in newgem.gemspec template ### What was the end-user problem that led to this PR? Since Ruby 2.0 we've had `__dir__` as well as `__FILE__`. The initial gem codes written with `bundle gem` using Ruby 2.0 or higher is an old description using `__FILE__`. ### What was your diagnosis of the problem? Ruby 1.9 is EOL, so I think that there is not much Gem to start developed using it. ### What is your fix for the problem, implemented in this PR? This PR uses `__dir__` when starting Gem development (i.e. `bundle gem`) using Ruby 2.0 or higher version. --- lib/bundler/templates/newgem/newgem.gemspec.tt | 4 +++- lib/bundler/templates/newgem/test/test_helper.rb.tt | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/bundler/templates/newgem/newgem.gemspec.tt b/lib/bundler/templates/newgem/newgem.gemspec.tt index 991d645cc63..116bb5fa626 100644 --- a/lib/bundler/templates/newgem/newgem.gemspec.tt +++ b/lib/bundler/templates/newgem/newgem.gemspec.tt @@ -1,8 +1,10 @@ <%- if RUBY_VERSION < "2.0.0" -%> # coding: utf-8 -<%- end -%> lib = File.expand_path("../lib", __FILE__) +<%- else -%> +lib = File.expand_path("lib", __dir__) +<%- end -%> $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "<%= config[:namespaced_path] %>/version" diff --git a/lib/bundler/templates/newgem/test/test_helper.rb.tt b/lib/bundler/templates/newgem/test/test_helper.rb.tt index 725e3e46473..335c4704ec8 100644 --- a/lib/bundler/templates/newgem/test/test_helper.rb.tt +++ b/lib/bundler/templates/newgem/test/test_helper.rb.tt @@ -1,4 +1,8 @@ +<%- if RUBY_VERSION < "2.0.0" -%> $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) +<%- else -%> +$LOAD_PATH.unshift File.expand_path("../lib", __dir__) +<%- end -%> require "<%= config[:namespaced_path] %>" require "minitest/autorun"