forked from coala/coala-bears
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 coala#1548
- Loading branch information
1 parent
012b7d1
commit d35b120
Showing
6 changed files
with
112 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ class RuboCopBear: | |
""" | ||
|
||
LANGUAGES = {'Ruby'} | ||
REQUIREMENTS = {GemRequirement('rubocop', '0.47.1'), | ||
REQUIREMENTS = {GemRequirement('rubocop', '0.49.1'), | ||
PipRequirement('pyyaml', '3.12')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
|
@@ -36,7 +36,7 @@ class RuboCopBear: | |
def create_arguments(filename, file, config_file, rubocop_config: str=''): | ||
# Need both stdin and filename. Explained in this comment: | ||
# https://github.com/bbatsov/rubocop/pull/2146#issuecomment-131403694 | ||
args = (filename, '--stdin', '--format=json') | ||
args = ('--stdin', filename, '--format=json') | ||
if rubocop_config: | ||
args += ('--config', rubocop_config) | ||
else: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,111 @@ | ||
import os | ||
from queue import Queue | ||
|
||
from coalib.results.Result import Result | ||
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY | ||
from coalib.settings.Section import Section | ||
from coalib.testing.BearTestHelper import generate_skip_decorator | ||
from coalib.testing.LocalBearTestHelper import LocalBearTestHelper | ||
|
||
from bears.ruby.RuboCopBear import RuboCopBear | ||
from coalib.testing.LocalBearTestHelper import verify_local_bear | ||
|
||
good_file = """def good_name | ||
test if something | ||
end | ||
""" | ||
|
||
bad_file = """def badName | ||
test if something | ||
end | ||
""" | ||
def get_testfile_path(name): | ||
return os.path.join(os.path.dirname(__file__), | ||
'test_files', | ||
name) | ||
|
||
|
||
def load_testfile(name): | ||
with open(get_testfile_path(name)) as f: | ||
return f.readlines() | ||
|
||
|
||
@generate_skip_decorator(RuboCopBear) | ||
class RuboCopBearTest(LocalBearTestHelper): | ||
|
||
RuboCopBearTest = verify_local_bear(RuboCopBear, | ||
invalid_files=(bad_file,), | ||
valid_files=(good_file,)) | ||
def setUp(self): | ||
self.uut = RuboCopBear(Section('name'), Queue()) | ||
|
||
# Testing Config | ||
rubocop_config = os.path.join(os.path.dirname(__file__), | ||
'test_files', | ||
'rubocop_config.yaml') | ||
def test_good_file(self): | ||
filename = 'good_file.rb' | ||
file_contents = load_testfile(filename) | ||
self.check_results( | ||
self.uut, | ||
file_contents, | ||
[], | ||
filename=get_testfile_path(filename)) | ||
|
||
def test_bad_file(self): | ||
filename = 'bad_file.rb' | ||
file_contents = load_testfile(filename) | ||
self.check_results( | ||
self.uut, | ||
file_contents, | ||
[Result.from_values('RuboCopBear (Style/MethodName)', | ||
message='Use snake_case for method names.', | ||
file=get_testfile_path(filename), | ||
line=1, | ||
column=5, | ||
end_line=1, | ||
end_column=12, | ||
severity=RESULT_SEVERITY.INFO)], | ||
filename=get_testfile_path(filename)) | ||
|
||
|
||
# bad file becomes good and vice-versa | ||
RuboCopBearConfigFileTest = verify_local_bear( | ||
RuboCopBear, | ||
valid_files=(bad_file,), | ||
invalid_files=(good_file,), | ||
settings={'rubocop_config': rubocop_config}) | ||
|
||
# Testing settings | ||
another_good_file = """ | ||
def goodindent | ||
# 1 space indent | ||
end | ||
""" | ||
|
||
another_bad_file = """ | ||
def badindent | ||
# 2 spaces indent | ||
end | ||
""" | ||
|
||
RuboCopBearSettingsTest = verify_local_bear( | ||
RuboCopBear, | ||
valid_files=(another_good_file,), | ||
invalid_files=(another_bad_file,), | ||
settings={'indent_size': 1}) | ||
|
||
RuboCopBearSettingsTest = verify_local_bear( | ||
RuboCopBear, | ||
valid_files=(bad_file,), | ||
invalid_files=(good_file,), | ||
settings={'method_name_case': 'camel'}) | ||
def test_bad_config_file(self): | ||
filename = 'good_file.rb' | ||
file_contents = load_testfile(filename) | ||
self.check_results( | ||
self.uut, | ||
file_contents, | ||
[Result.from_values('RuboCopBear (Style/MethodName)', | ||
message='Use camelCase for method names.', | ||
file=get_testfile_path(filename), | ||
line=1, | ||
column=5, | ||
end_line=1, | ||
end_column=14, | ||
severity=RESULT_SEVERITY.INFO)], | ||
filename=get_testfile_path(filename), | ||
settings={'rubocop_config': get_testfile_path( | ||
'rubocop_config.yaml')}) | ||
|
||
def test_good_config_file(self): | ||
filename = 'bad_file.rb' | ||
file_contents = load_testfile(filename) | ||
self.check_results( | ||
self.uut, | ||
file_contents, | ||
[], | ||
filename=get_testfile_path(filename), | ||
settings={'rubocop_config': get_testfile_path( | ||
'rubocop_config.yaml')}) | ||
|
||
def test_bad_indent_size(self): | ||
filename = 'indent_file.rb' | ||
file_contents = load_testfile(filename) | ||
self.check_results( | ||
self.uut, | ||
file_contents, | ||
[Result.from_values('RuboCopBear (Layout/CommentIndentation)', | ||
message='Incorrect indentation detected ' | ||
'(column 2 instead of 1).', | ||
file=get_testfile_path(filename), | ||
line=2, | ||
column=3, | ||
end_line=2, | ||
end_column=20, | ||
severity=RESULT_SEVERITY.INFO)], | ||
filename=get_testfile_path(filename), | ||
settings={'indent_size': 1}) | ||
|
||
def test_good_indent_size(self): | ||
filename = 'indent_file.rb' | ||
file_contents = load_testfile(filename) | ||
self.check_results( | ||
self.uut, | ||
file_contents, | ||
[], | ||
filename=get_testfile_path(filename)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def badName | ||
test if something | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def good_name | ||
test if something | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def badindent | ||
# 2 spaces indent | ||
end |