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

Add more specs / previous version compatibility #19

Merged
merged 3 commits into from
Sep 4, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions lib/capistrano/locally.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,7 +40,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
Expand All @@ -45,24 +51,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
2 changes: 1 addition & 1 deletion lib/capistrano/locally/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Capistrano
module Locally
VERSION = "0.2.7"
VERSION = "0.3.0"
end
end
23 changes: 23 additions & 0 deletions spec/capistrano/locally_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down