Skip to content

Commit d35b120

Browse files
committed
RuboCopBear: Fix CI breakage for version > 0.47.1
rubocop/rubocop#4226 indicates that `--stdin` takes filename as an argument which was incorporated. A part of the fixing was to improve the tests that involved the bear to be run on files with the `.rb`(ruby) extension because initially the bear was run on the generated temporary files that was the cause of error. Fixes #1548
1 parent 012b7d1 commit d35b120

File tree

6 files changed

+112
-49
lines changed

6 files changed

+112
-49
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ruby '2.2.2'
44
gem "csvlint"
55
gem "puppet-lint", "2.1.1"
66
gem "reek"
7-
gem "rubocop", "0.47.1"
7+
gem "rubocop", "0.49.1"
88
gem "scss_lint", require: false
99
gem "sqlint"
1010
gem "travis", "1.8.8"

bears/ruby/RuboCopBear.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class RuboCopBear:
1919
"""
2020

2121
LANGUAGES = {'Ruby'}
22-
REQUIREMENTS = {GemRequirement('rubocop', '0.47.1'),
22+
REQUIREMENTS = {GemRequirement('rubocop', '0.49.1'),
2323
PipRequirement('pyyaml', '3.12')}
2424
AUTHORS = {'The coala developers'}
2525
AUTHORS_EMAILS = {'coala-devel@googlegroups.com'}
@@ -36,7 +36,7 @@ class RuboCopBear:
3636
def create_arguments(filename, file, config_file, rubocop_config: str=''):
3737
# Need both stdin and filename. Explained in this comment:
3838
# https://github.com/bbatsov/rubocop/pull/2146#issuecomment-131403694
39-
args = (filename, '--stdin', '--format=json')
39+
args = ('--stdin', filename, '--format=json')
4040
if rubocop_config:
4141
args += ('--config', rubocop_config)
4242
else:

tests/ruby/RuboCopBearTest.py

+100-46
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,111 @@
11
import os
2+
from queue import Queue
3+
4+
from coalib.results.Result import Result
5+
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
6+
from coalib.settings.Section import Section
7+
from coalib.testing.BearTestHelper import generate_skip_decorator
8+
from coalib.testing.LocalBearTestHelper import LocalBearTestHelper
29

310
from bears.ruby.RuboCopBear import RuboCopBear
4-
from coalib.testing.LocalBearTestHelper import verify_local_bear
511

6-
good_file = """def good_name
7-
test if something
8-
end
9-
"""
1012

11-
bad_file = """def badName
12-
test if something
13-
end
14-
"""
13+
def get_testfile_path(name):
14+
return os.path.join(os.path.dirname(__file__),
15+
'test_files',
16+
name)
17+
18+
19+
def load_testfile(name):
20+
with open(get_testfile_path(name)) as f:
21+
return f.readlines()
22+
1523

24+
@generate_skip_decorator(RuboCopBear)
25+
class RuboCopBearTest(LocalBearTestHelper):
1626

17-
RuboCopBearTest = verify_local_bear(RuboCopBear,
18-
invalid_files=(bad_file,),
19-
valid_files=(good_file,))
27+
def setUp(self):
28+
self.uut = RuboCopBear(Section('name'), Queue())
2029

21-
# Testing Config
22-
rubocop_config = os.path.join(os.path.dirname(__file__),
23-
'test_files',
24-
'rubocop_config.yaml')
30+
def test_good_file(self):
31+
filename = 'good_file.rb'
32+
file_contents = load_testfile(filename)
33+
self.check_results(
34+
self.uut,
35+
file_contents,
36+
[],
37+
filename=get_testfile_path(filename))
38+
39+
def test_bad_file(self):
40+
filename = 'bad_file.rb'
41+
file_contents = load_testfile(filename)
42+
self.check_results(
43+
self.uut,
44+
file_contents,
45+
[Result.from_values('RuboCopBear (Style/MethodName)',
46+
message='Use snake_case for method names.',
47+
file=get_testfile_path(filename),
48+
line=1,
49+
column=5,
50+
end_line=1,
51+
end_column=12,
52+
severity=RESULT_SEVERITY.INFO)],
53+
filename=get_testfile_path(filename))
2554

2655

2756
# bad file becomes good and vice-versa
28-
RuboCopBearConfigFileTest = verify_local_bear(
29-
RuboCopBear,
30-
valid_files=(bad_file,),
31-
invalid_files=(good_file,),
32-
settings={'rubocop_config': rubocop_config})
33-
34-
# Testing settings
35-
another_good_file = """
36-
def goodindent
37-
# 1 space indent
38-
end
39-
"""
40-
41-
another_bad_file = """
42-
def badindent
43-
# 2 spaces indent
44-
end
45-
"""
46-
47-
RuboCopBearSettingsTest = verify_local_bear(
48-
RuboCopBear,
49-
valid_files=(another_good_file,),
50-
invalid_files=(another_bad_file,),
51-
settings={'indent_size': 1})
52-
53-
RuboCopBearSettingsTest = verify_local_bear(
54-
RuboCopBear,
55-
valid_files=(bad_file,),
56-
invalid_files=(good_file,),
57-
settings={'method_name_case': 'camel'})
57+
def test_bad_config_file(self):
58+
filename = 'good_file.rb'
59+
file_contents = load_testfile(filename)
60+
self.check_results(
61+
self.uut,
62+
file_contents,
63+
[Result.from_values('RuboCopBear (Style/MethodName)',
64+
message='Use camelCase for method names.',
65+
file=get_testfile_path(filename),
66+
line=1,
67+
column=5,
68+
end_line=1,
69+
end_column=14,
70+
severity=RESULT_SEVERITY.INFO)],
71+
filename=get_testfile_path(filename),
72+
settings={'rubocop_config': get_testfile_path(
73+
'rubocop_config.yaml')})
74+
75+
def test_good_config_file(self):
76+
filename = 'bad_file.rb'
77+
file_contents = load_testfile(filename)
78+
self.check_results(
79+
self.uut,
80+
file_contents,
81+
[],
82+
filename=get_testfile_path(filename),
83+
settings={'rubocop_config': get_testfile_path(
84+
'rubocop_config.yaml')})
85+
86+
def test_bad_indent_size(self):
87+
filename = 'indent_file.rb'
88+
file_contents = load_testfile(filename)
89+
self.check_results(
90+
self.uut,
91+
file_contents,
92+
[Result.from_values('RuboCopBear (Layout/CommentIndentation)',
93+
message='Incorrect indentation detected '
94+
'(column 2 instead of 1).',
95+
file=get_testfile_path(filename),
96+
line=2,
97+
column=3,
98+
end_line=2,
99+
end_column=20,
100+
severity=RESULT_SEVERITY.INFO)],
101+
filename=get_testfile_path(filename),
102+
settings={'indent_size': 1})
103+
104+
def test_good_indent_size(self):
105+
filename = 'indent_file.rb'
106+
file_contents = load_testfile(filename)
107+
self.check_results(
108+
self.uut,
109+
file_contents,
110+
[],
111+
filename=get_testfile_path(filename))

tests/ruby/test_files/bad_file.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def badName
2+
test if something
3+
end

tests/ruby/test_files/good_file.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def good_name
2+
test if something
3+
end

tests/ruby/test_files/indent_file.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def badindent
2+
# 2 spaces indent
3+
end

0 commit comments

Comments
 (0)