Skip to content

Commit

Permalink
(puppetlabs#773) Respect --verbose in interactive pdk test unit
Browse files Browse the repository at this point in the history
`pdk test unit` will now use the `progress` formatter (dots) and `pdk
test unit --verbose` will now use the `documentation` formatter.

Fixes puppetlabs#773
  • Loading branch information
rodjek authored and logicminds committed Nov 30, 2020
1 parent 4b08f1b commit 59002f3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 0 additions & 2 deletions lib/pdk/cli/test/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ module PDK::CLI
end
end
else
PDK.logger.info _('--verbose has no effect when not used with --list') if opts[:verbose]

report = PDK::Report.new
report_formats = if opts[:format]
opts[:interactive] = false
Expand Down
9 changes: 6 additions & 3 deletions lib/pdk/tests/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def self.interactive_rake(task, environment)

command = PDK::CLI::Exec::InteractiveCommand.new(*cmd_with_args(task)).tap do |c|
c.context = :module
c.environment = environment.reject do |key, _|
key == 'CI_SPEC_OPTIONS'
end
c.environment = environment
end

command.execute!
Expand Down Expand Up @@ -97,6 +95,11 @@ def self.invoke(report, options = {})
spinner_msg = options[:parallel] ? _('Running unit tests in parallel.') : _('Running unit tests.')

if options[:interactive]
environment['CI_SPEC_OPTIONS'] = if options[:verbose]
'--format documentation'
else
'--format progress'
end
result = interactive_rake(cmd(tests, options), environment)
return result[:exit_code]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/test_unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

describe command('pdk test unit') do
its(:exit_status) { is_expected.not_to eq(0) }
its(:stdout) { is_expected.to match(%r{failed.*expected: true.*got: false}im) }
its(:stdout) { is_expected.to match(%r{expected: true.*got: false}im) }
its(:stdout) { is_expected.to match(%r{1 examples?.*1 failures?}im) }
end
end
Expand Down
23 changes: 21 additions & 2 deletions spec/unit/pdk/test/unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,17 @@

context 'when running interactively' do
subject(:exit_code) do
described_class.invoke(report, interactive: true)
described_class.invoke(report, options)
end

before(:each) do
allow(PDK::CLI::Exec::InteractiveCommand).to receive(:new)
.and_return(command)
allow(command).to receive(:execute!).and_return(exit_code: 0)
end

let(:options) { { interactive: true } }

let(:command) do
instance_double(
PDK::CLI::Exec::InteractiveCommand,
Expand All @@ -309,9 +312,25 @@
end

it 'runs the rake task interactively' do
expect(command).to receive(:execute!).and_return(exit_code: 0)
expect(exit_code).to eq(0)
end

context 'when --verbose is not passed' do
it 'uses the progress formatter' do
expect(command).to receive(:environment=).with(include('CI_SPEC_OPTIONS' => '--format progress'))

exit_code
end
end

context 'when --verbose is passed' do
let(:options) { super().merge(verbose: true) }

it 'uses the documentation formatter' do
expect(command).to receive(:environment=).with(include('CI_SPEC_OPTIONS' => '--format documentation'))
exit_code
end
end
end

context 'in parallel without examples' do
Expand Down

0 comments on commit 59002f3

Please sign in to comment.