This repository has been archived on 2024-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
ale/test/fixers/test_rubocop_fixer_callback.vader
Horacio Sanson 8e6c7bff9a
Fix 1695 - Change rubocop fixer to use stdin (#3230)
* Fix 1695 - Change rubocop fixer to use stdin
* Update test_rubocop_fixer_callback.vader

Co-authored-by: Horacio Sanson <horacio@allm.inc>
Co-authored-by: w0rp <w0rp@users.noreply.github.com>
2020-08-13 11:25:07 +01:00

110 lines
3.5 KiB
Text

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('ruby_paths/dummy.rb')
AssertEqual
\ {
\ 'process_with': 'ale#fixers#rubocop#PostProcess',
\ 'command': ale#Escape(g:ale_ruby_rubocop_executable)
\ . ' --auto-correct --force-exclusion --stdin '
\ . ale#Escape(expand('#' . bufnr('') . ':p')),
\ },
\ ale#fixers#rubocop#Fix(bufnr(''))
Execute(The rubocop callback should include configuration files):
call ale#test#SetFilename('ruby_paths/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 . '/ruby_paths/with_config/.rubocop.yml'))
\ . ' --auto-correct --force-exclusion --stdin '
\ . ale#Escape(expand('#' . bufnr('') . ':p')),
\ },
\ 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('ruby_paths/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 . '/ruby_paths/with_config/.rubocop.yml'))
\ . ' --except Lint/Debugger'
\ . ' --auto-correct --force-exclusion --stdin '
\ . ale#Escape(expand('#' . bufnr('') . ':p')),
\ },
\ 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('ruby_paths/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 . '/ruby_paths/with_config/.rubocop.yml'))
\ . ' --auto-correct-all --force-exclusion --stdin '
\ . ale#Escape(expand('#' . bufnr('') . ':p')),
\ },
\ 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'']',
\ ])