-
Notifications
You must be signed in to change notification settings - Fork 204
/
rubocop_test.rb
75 lines (60 loc) 路 2.23 KB
/
rubocop_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require "test_helper"
require "standard/runners/rubocop"
require "fixture/runner/bad_cop"
class Standard::Runners::RubocopTest < UnitTest
DEFAULT_OPTIONS = {
formatters: [["quiet", nil]]
}.freeze
def setup
super
@subject = Standard::Runners::Rubocop.new
end
def test_empty_output_on_quiet_success
fake_out, fake_err = do_with_fake_io {
@subject.call(create_config)
}
assert_equal "", fake_out.string
assert_equal "", fake_err.string
end
def test_error_output_on_cop_error
RuboCop::Cop::Standard::BadCop.send(:define_method, :on_send) { |_| raise "hell" }
fake_out, fake_err = do_with_fake_io {
@subject.call(create_config(
only: ["Standard/BadCop"]
))
}
assert_equal "", fake_out.string
assert_match(/An error occurred while Standard\/BadCop cop was inspecting/, fake_err.string)
RuboCop::Cop::Standard::BadCop.send(:define_method, :on_send) { |_| }
end
def test_print_corrected_output_on_stdin
fake_out, fake_err = do_with_fake_io {
@subject.call(create_config(
auto_correct: true,
safe_auto_correct: true,
stdin: "def Foo;'hi'end\n"
))
}
expected_out = <<-OUT.gsub(/^ {6}/, "")
== test/fixture/runner/agreeable.rb ==
C: 1: 1: Style/FrozenStringLiteralComment: Missing frozen string literal comment.
C: 1: 1: [Corrected] Style/SingleLineMethods: Avoid single-line method definitions.
C: 1: 5: Naming/MethodName: Use snake_case for method names.
C: 1: 8: [Corrected] Layout/SpaceAfterSemicolon: Space missing after semicolon.
C: 1: 8: [Corrected] Style/Semicolon: Do not use semicolons to terminate expressions.
C: 1: 9: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
1 file inspected, 6 offenses detected, 4 offenses corrected, 1 more offense can be corrected with `rubocop -A`
====================
def Foo
'hi'
end
OUT
assert_equal expected_out, fake_out.string
assert_equal "", fake_err.string
end
private
def create_config(options = {}, path = "test/fixture/runner/agreeable.rb")
Standard::Config.new(nil, [path], DEFAULT_OPTIONS.merge(options),
RuboCop::ConfigStore.new)
end
end