Skip to content

Commit

Permalink
(maint) Update PDK::Test::Unit.parallel_with_no_tests? for PSH #216 c…
Browse files Browse the repository at this point in the history
…hanges
  • Loading branch information
rodjek committed Nov 22, 2017
1 parent 232862b commit 2d8be3f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/pdk/tests/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def self.rake(task, spinner_text, environment = {})

def self.parallel_with_no_tests?(ran_in_parallel, json_result, result)
ran_in_parallel && json_result.empty? &&
!result[:exit_code].zero? &&
result[:stderr].strip =~ %r{Pass files or folders to run$}
((!result[:exit_code].zero? && result[:stderr].strip =~ %r{Pass files or folders to run$}) ||
result[:stderr].strip =~ %r{No files for parallel_spec to run against$})
end

def self.print_failure(result, exception)
Expand Down
40 changes: 33 additions & 7 deletions spec/unit/pdk/test/unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,40 @@
end

describe '.parallel_with_no_tests?' do
context 'when not parallel' do
it 'is false' do
result = {
stderr: 'Pass files or folders to run',
exit_code: 1,
}
subject { described_class.parallel_with_no_tests?(ran_in_parallel, json_result, cmd_result) }

let(:json_result) { [] }
let(:cmd_result) { { stderr: '', stdout: '', exit_code: 1 } }

context 'when not run in parallel' do
let(:ran_in_parallel) { false }

it { is_expected.to be_falsey }
end

context 'when run in parallel' do
let(:ran_in_parallel) { true }

context 'and no tests (puppetlabs_spec_helper <= 2.5.0)' do
let(:cmd_result) do
{ stderr: 'Pass files or folders to run', stdout: '', exit_code: 1}
end

it { is_expected.to be_truthy }
end

context 'and no tests (puppetlabs_spec_helper >= 2.5.1' do
let(:cmd_result) do
{ stderr: 'No files for parallel_spec to run against', stdout: '', exit_code: 0 }
end

it { is_expected.to be_truthy }
end

context 'and there are tests' do
let(:json_result) { ['something'] }

expect(described_class.parallel_with_no_tests?(false, ['json_result'], result)).to be(false)
it { is_expected.to be_falsey }
end
end
end
Expand Down

0 comments on commit 2d8be3f

Please sign in to comment.