Skip to content

Commit efa40dc

Browse files
fixlrsds
authored andcommitted
Correctly fail hook when rubocop is not installed
When rubocop is not installed, or when the installed version does not match the version expected by Bundler, the 'pre_commit/rubo_cop' hook passes 100% of the time because 'result.stdout' is empty. This commit updates the hook to fail if anything is present in stderr after the hook runs.
1 parent ee28194 commit efa40dc

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/overcommit/hook/pre_commit/rubo_cop.rb

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class RuboCop < Base
1010
def run
1111
result = execute(command, args: applicable_files)
1212
return :pass if result.success?
13+
return [:fail, result.stderr] unless result.stderr.empty?
1314

1415
extract_messages(
1516
result.stdout.split("\n"),

spec/overcommit/hook/pre_commit/rubo_cop_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,16 @@
4848

4949
it { should fail_hook }
5050
end
51+
52+
context 'when there is an error running rubocop' do
53+
before do
54+
result.stub(:stdout).and_return('')
55+
result.stub(:stderr).and_return([
56+
'Could not find rubocop in any of the sources'
57+
].join("\n"))
58+
end
59+
60+
it { should fail_hook }
61+
end
5162
end
5263
end

0 commit comments

Comments
 (0)