From e49d898340fd06633e479131874440286cbdf040 Mon Sep 17 00:00:00 2001 From: Takuto Komazaki <1654804+komazarari@users.noreply.github.com> Date: Sat, 4 Sep 2021 15:02:44 +0900 Subject: [PATCH 1/3] Add more specs --- lib/capistrano/locally.rb | 27 +++++++++------------------ spec/capistrano/locally_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lib/capistrano/locally.rb b/lib/capistrano/locally.rb index 17d93e0..8ae0c4e 100644 --- a/lib/capistrano/locally.rb +++ b/lib/capistrano/locally.rb @@ -36,7 +36,9 @@ def on(hosts, options={}, &block) end def with_unbundled_env? - fetch_setting_related_bundler_with_unbundled_env + [deprecated_with_unbundled_env?, fetch(:run_locally_with_unbundled_env, true)].find do |val| + !val.nil? + end end private @@ -45,24 +47,13 @@ def dry_run? fetch(:sshkit_backend) == SSHKit::Backend::Printer end - def fetch_setting_related_bundler_with_unbundled_env - value = fetch(:run_locally_with_unbundled_env) - value = fetch_run_locally_with_clean_env if value.nil? - value = true if value.nil? - - value - end - - def fetch_run_locally_with_clean_env - value = fetch(:run_locally_with_clean_env) - - unless value.nil? - $stderr.puts(<<-MESSAGE) -[Deprecation Notice] `set :run_locally_with_clean_env` has been deprecated in favor of `set :run_locally_with_unbundled_env`. -MESSAGE + def deprecated_with_unbundled_env? + fetch(:run_locally_with_clean_env).tap do |val| + $stderr.puts(<<~MESSAGE) unless val.nil? + [Deprecation Notice] `set :run_locally_with_clean_env` has been deprecated \ + in favor of `set :run_locally_with_unbundled_env`. + MESSAGE end - - value end end end diff --git a/spec/capistrano/locally_spec.rb b/spec/capistrano/locally_spec.rb index 0de4612..d2668f9 100644 --- a/spec/capistrano/locally_spec.rb +++ b/spec/capistrano/locally_spec.rb @@ -47,6 +47,29 @@ class DummyDSL expect(dsl.with_unbundled_env?).to be_truthy end end + + context 'with the :run_locally_with_unbundled_env is set to true' do + it 'returns truthy' do + dsl.set(:run_locally_with_unbundled_env, true) + expect(dsl.with_unbundled_env?).to be_truthy + dsl.set(:run_locally_with_unbundled_env, nil) + end + end + context 'with the old key :run_locally_with_clean_env is set to true' do + around do |example| + dsl.set(:run_locally_with_clean_env, true) + example.run + dsl.set(:run_locally_with_clean_env, nil) + end + it 'returns truthy' do + expect(dsl.with_unbundled_env?).to be_truthy + end + it 'shows a Deprecation message' do + expect { dsl.with_unbundled_env? }.to output(/\[Deprecation Notice\]/).to_stderr + end + end + + context 'with the :run_locally_with_unbundled_env is set to false' do it 'returns falsy' do dsl.set(:run_locally_with_unbundled_env, false) From 7850243da5deed6ca0dc8fbada4a8062187dce6b Mon Sep 17 00:00:00 2001 From: Takuto Komazaki <1654804+komazarari@users.noreply.github.com> Date: Sat, 4 Sep 2021 15:17:21 +0900 Subject: [PATCH 2/3] Compatibility with bundler<2 --- lib/capistrano/locally.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/capistrano/locally.rb b/lib/capistrano/locally.rb index 8ae0c4e..86b7f22 100644 --- a/lib/capistrano/locally.rb +++ b/lib/capistrano/locally.rb @@ -24,7 +24,11 @@ def on(hosts, options={}, &block) end if (defined? Bundler) && with_unbundled_env? - Bundler.with_unbundled_env do + if Bundler.respond_to?(:with_unbundled_env) + Bundler.method(:with_unbundled_env) + else + Bundler.method(:with_clean_env) + end.call do klass.new(localhost, &block).run end else From 515adfb2bb2a419ec3c00cade3e0298c155cd165 Mon Sep 17 00:00:00 2001 From: Takuto Komazaki <1654804+komazarari@users.noreply.github.com> Date: Sat, 4 Sep 2021 15:18:55 +0900 Subject: [PATCH 3/3] ver up --- lib/capistrano/locally/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capistrano/locally/version.rb b/lib/capistrano/locally/version.rb index be5da4f..8f42369 100644 --- a/lib/capistrano/locally/version.rb +++ b/lib/capistrano/locally/version.rb @@ -1,5 +1,5 @@ module Capistrano module Locally - VERSION = "0.2.7" + VERSION = "0.3.0" end end