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

(#902) Check for github_changelog_generator in proper bundler context #907

Merged
merged 1 commit into from
Aug 22, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/pdk/util/changelog_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ module ChangelogGenerator

# Raises if the github_changelog_generator is not available
def self.github_changelog_generator_available!
require 'bundler'
return if ::Bundler.rubygems.find_name(GEM).any?
check_command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, 'show', 'github_changelog_generator')
check_command.context = :module

result = check_command.execute!

return if result[:exit_code].zero?

raise PDK::CLI::ExitWithError, _(
'Unable to generate the changelog as the %{gem} gem is not installed',
'Unable to generate the changelog as the %{gem} gem is not included in this module\'s Gemfile',
) % { gem: GEM }
end

Expand Down
22 changes: 15 additions & 7 deletions spec/unit/pdk/util/changelog_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,27 +199,35 @@
describe '.github_changelog_generator_available!' do
subject(:method) { described_class.github_changelog_generator_available! }

let(:dummy_spec) { gem_present ? [Gem::Specification.new] : [] }
let(:command) { double(PDK::CLI::Exec::InteractiveCommand, :context= => nil) } # rubocop:disable RSpec/VerifiedDoubles

before(:each) do
allow(::Bundler.rubygems).to receive(:find_name).and_call_original
allow(::Bundler.rubygems).to receive(:find_name)
.with('github_changelog_generator').and_return(dummy_spec)
expect(PDK::CLI::Exec::InteractiveCommand).to receive(:new).and_return(command)
end

context 'when the gem is available to Bundler' do
let(:gem_present) { true }
let(:command_stdout) { '/path/to/gems/github_changelog_generator-1.15.2' }
let(:command_exit_code) { 0 }

before(:each) do
expect(command).to receive(:execute!).and_return(stdout: command_stdout, exit_code: command_exit_code)
end

it 'does not raise an error' do
expect { method }.not_to raise_error
end
end

context 'when the gem is not available to Bundler' do
let(:gem_present) { false }
let(:command_stderr) { 'Could not find gem \'github_changelog_generator\'.' }
let(:command_exit_code) { 7 }

before(:each) do
expect(command).to receive(:execute!).and_return(stderr: command_stderr, exit_code: command_exit_code)
end

it 'raises an error' do
expect { method }.to raise_error(PDK::CLI::ExitWithError, %r{not installed})
expect { method }.to raise_error(PDK::CLI::ExitWithError, %r{not included})
end
end
end
Expand Down