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 specs tor unbundled_env #18

Merged
merged 1 commit 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
10 changes: 7 additions & 3 deletions lib/capistrano/locally.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def on(hosts, options={}, &block)
SSHKit::Backend::Local
end

if (defined? Bundler) && fetch_setting_related_bundler_with_unbundled_env
if (defined? Bundler) && with_unbundled_env?
Bundler.with_unbundled_env do
klass.new(localhost, &block).run
end
Expand All @@ -35,6 +35,10 @@ def on(hosts, options={}, &block)
original_on(remotehosts, options, &block)
end

def with_unbundled_env?
fetch_setting_related_bundler_with_unbundled_env
end

private

def dry_run?
Expand All @@ -43,8 +47,8 @@ def dry_run?

def fetch_setting_related_bundler_with_unbundled_env
value = fetch(:run_locally_with_unbundled_env)
value = fetch_run_locally_with_clean_env if use.nil?
value = true if use.nil?
value = fetch_run_locally_with_clean_env if value.nil?
value = true if value.nil?

value
end
Expand Down
30 changes: 29 additions & 1 deletion spec/capistrano/locally_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,40 @@ class DummyDSL
expect(override.parameters).to eq original.parameters
end

context '#on' do
describe '#on' do
let(:opts) { {} }
let(:block) { proc { true } }
it 'calls the original "#on" with arguments excluding "localhost" server' do
allow(dsl).to receive(:original_on).with(locally_servers, opts, &block)
dsl.on(servers, opts, &block)
end
end

describe '#with_unbundled_env?' do
context 'with default configuration' do
it 'returns truthy' do
expect(dsl.with_unbundled_env?).to be_truthy
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)
expect(dsl.with_unbundled_env?).to be_falsy
dsl.set(:run_locally_with_unbundled_env, nil)
end
end
context 'with the old key :run_locally_with_clean_env is set to false' do
around do |example|
dsl.set(:run_locally_with_clean_env, false)
example.run
dsl.set(:run_locally_with_clean_env, nil)
end
it 'returns falsy' do
expect(dsl.with_unbundled_env?).to be_falsy
end
it 'shows a Deprecation message' do
expect { dsl.with_unbundled_env? }.to output(/\[Deprecation Notice\]/).to_stderr
end
end
end
end