summaryrefslogtreecommitdiff
path: root/test/fixers/test_rubocop_fixer_callback.vader
blob: 2029df23792c27dc0873f68164f5ceeab4c489a6 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
Before:
  Save g:ale_ruby_rubocop_executable
  Save g:ale_ruby_rubocop_options

  " Use an invalid global executable, so we don't match it.
  let g:ale_ruby_rubocop_executable = 'xxxinvalid'
  let g:ale_ruby_rubocop_options = ''

  call ale#test#SetDirectory('/testplugin/test/fixers')
  silent cd ..
  silent cd command_callback
  let g:dir = getcwd()

After:
  Restore

  call ale#test#RestoreDirectory()

Execute(The rubocop callback should return the correct default values):
  call ale#test#SetFilename('../test-files/ruby/dummy.rb')

  AssertEqual
  \ {
  \   'process_with': 'ale#fixers#rubocop#PostProcess',
  \   'command': ale#Escape(g:ale_ruby_rubocop_executable)
  \     . ' --auto-correct --force-exclusion --stdin %s',
  \ },
  \ ale#fixers#rubocop#Fix(bufnr(''))

Execute(The rubocop callback should include configuration files):
  call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')

  AssertEqual
  \ {
  \   'process_with': 'ale#fixers#rubocop#PostProcess',
  \   'command': ale#Escape(g:ale_ruby_rubocop_executable)
  \     . ' --config ' . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/ruby/with_config/.rubocop.yml'))
  \     . ' --auto-correct --force-exclusion --stdin %s',
  \ },
  \ ale#fixers#rubocop#Fix(bufnr(''))

Execute(The rubocop callback should include custom rubocop options):
  let g:ale_ruby_rubocop_options = '--except Lint/Debugger'
  call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')

  AssertEqual
  \ {
  \   'process_with': 'ale#fixers#rubocop#PostProcess',
  \   'command': ale#Escape(g:ale_ruby_rubocop_executable)
  \     . ' --config ' . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/ruby/with_config/.rubocop.yml'))
  \     . ' --except Lint/Debugger'
  \     . ' --auto-correct --force-exclusion --stdin %s',
  \ },
  \ ale#fixers#rubocop#Fix(bufnr(''))

Execute(The rubocop callback should use auto-correct-all option when set):
  let g:ale_ruby_rubocop_auto_correct_all = 1
  call ale#test#SetFilename('../test-files/ruby/with_config/dummy.rb')

  AssertEqual
  \ {
  \   'process_with': 'ale#fixers#rubocop#PostProcess',
  \   'command': ale#Escape(g:ale_ruby_rubocop_executable)
  \     . ' --config ' . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/ruby/with_config/.rubocop.yml'))
  \     . ' --auto-correct-all --force-exclusion --stdin %s'
  \ },
  \ ale#fixers#rubocop#Fix(bufnr(''))

Execute(The rubocop post-processor should remove diagnostics content):
  AssertEqual
  \ [
  \   'class MyModel < ApplicationRecord',
  \   '  # rubocop:disable Rails/InverseOf',
  \   '  has_one :something',
  \   '  # rubocop:enable Rails/InverseOf',
  \   'end',
  \   '',
  \   'array = [1, 2, 3,',
  \   '         4, 5, 6]',
  \   'array = [''run'',',
  \   '         ''forrest'',',
  \   '         ''run'']',
  \ ],
  \ ale#fixers#rubocop#PostProcess(bufnr(''), [
  \   'Inspecting 1 file',
  \   'C',
  \   '',
  \   'Offenses:',
  \   'app/models/my_model.rb:8:3: C: [Corrected] Layout/ArrayAlignment: ',
  \   '4, 5, 6]',
  \   '^',
  \   '',
  \   '1 file inspected, 3 offenses detected, 3 offenses corrected',
  \   '====================',
  \   'class MyModel < ApplicationRecord',
  \   '  # rubocop:disable Rails/InverseOf',
  \   '  has_one :something',
  \   '  # rubocop:enable Rails/InverseOf',
  \   'end',
  \   '',
  \   'array = [1, 2, 3,',
  \   '         4, 5, 6]',
  \   'array = [''run'',',
  \   '         ''forrest'',',
  \   '         ''run'']',
  \ ])