Skip to content

Commit

Permalink
(PDK-654) Allow rubocop to determine its own targets by default
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjek committed Nov 14, 2018
1 parent 905ac33 commit 0eca126
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
2 changes: 2 additions & 0 deletions lib/pdk/validate/ruby/rubocop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
module PDK
module Validate
class Rubocop < BaseValidator
ALLOW_EMPTY_TARGETS = true

def self.name
'rubocop'
end
Expand Down
15 changes: 7 additions & 8 deletions spec/acceptance/validate_ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
end

context 'when validating specific directories' do
another_violation_rb = File.join('lib', 'puppet', 'another_violation.rb')
another_violation_rb = File.join('spec', 'fixtures', 'test', 'another_violation.rb')

before(:all) do
FileUtils.mkdir_p(File.dirname(another_violation_rb))
Expand All @@ -43,7 +43,7 @@
end
end

describe command('pdk validate ruby lib') do
describe command('pdk validate ruby spec/fixtures') do
its(:exit_status) { is_expected.not_to eq(0) }
its(:stdout) { is_expected.to match(%r{#{Regexp.escape(another_violation_rb)}}) }
its(:stdout) { is_expected.not_to match(%r{#{Regexp.escape(spec_violation_rb)}}) }
Expand All @@ -58,8 +58,8 @@

its(:stdout) do
is_expected.to have_junit_testsuite('rubocop').with_attributes(
'failures' => a_value > 1,
'tests' => a_value >= 3,
'failures' => a_value >= 1,
'tests' => a_value >= 2,
)
end

Expand All @@ -71,10 +71,9 @@
end

its(:stdout) do
is_expected.to have_junit_testcase.in_testsuite('rubocop').with_attributes(
'classname' => a_string_matching(%r{UselessAssignment}),
'name' => a_string_starting_with(File.join('spec', 'violation.rb')),
).that_failed
is_expected.not_to have_junit_testcase.in_testsuite('rubocop').with_attributes(
'name' => a_string_starting_with(File.join('spec', 'fixtures')),
)
end
end
end
Expand Down
9 changes: 1 addition & 8 deletions spec/unit/pdk/validate/rubocop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,8 @@
context 'when given no targets' do
let(:targets) { [] }

let(:files) { [File.join('spec', 'spec_helper.rb')] }
let(:globbed_files) { files.map { |file| File.join(module_root, file) } }

before(:each) do
allow(Dir).to receive(:glob).with(glob_pattern).and_return(globbed_files)
end

it 'returns the module root' do
expect(target_files.first).to eq(files)
expect(target_files.first).to be_empty
end
end

Expand Down

0 comments on commit 0eca126

Please sign in to comment.