diff options
author | Eddie Lebow <elebow@users.noreply.github.com> | 2017-07-12 05:43:47 -0400 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2017-07-12 10:43:47 +0100 |
commit | bc32e24203159945dcf3906a5e08261ccb06e065 (patch) | |
tree | ef1ddaefe8aee1a7ca37c156a11c447753dee17f /test | |
parent | 400580e4e8fc330166658c689d1abf05db38ab3b (diff) | |
download | ale-bc32e24203159945dcf3906a5e08261ccb06e065.zip |
Add rails_best_practices handler (resolves #655) (#751)
* Move FindRailsRoot() to more general location
* Add rails_best_practices handler (resolves #655)
* Update documentation for rails_best_practices
Also add brakeman to *ale* documentation.
* rails_best_practices: allow overriding the executable
* rails_best_practices: format help correctly
* rails_best_practices: capture tool output on Windows
Diffstat (limited to 'test')
-rw-r--r-- | test/command_callback/test_rails_best_practices_command_callback.vader | 42 | ||||
-rw-r--r-- | test/handler/test_rails_best_practices_handler.vader | 50 |
2 files changed, 92 insertions, 0 deletions
diff --git a/test/command_callback/test_rails_best_practices_command_callback.vader b/test/command_callback/test_rails_best_practices_command_callback.vader new file mode 100644 index 00000000..09436be0 --- /dev/null +++ b/test/command_callback/test_rails_best_practices_command_callback.vader @@ -0,0 +1,42 @@ +Before: + Save g:ale_ruby_rails_best_practices_executable + + let g:ale_ruby_rails_best_practices_executable = 'rails_best_practices' + + runtime ale_linters/ruby/rails_best_practices.vim + call ale#test#SetDirectory('/testplugin/test/command_callback') + call ale#test#SetFilename('../ruby_fixtures/valid_rails_app/db/test.rb') + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(Executable should default to rails_best_practices): + AssertEqual + \ '''rails_best_practices'' --silent -f json --output-file /dev/stdout ' + \ . ale#Escape(simplify(g:dir . '/../ruby_fixtures/valid_rails_app')), + \ ale_linters#ruby#rails_best_practices#GetCommand(bufnr('')) + +Execute(Should be able to set a custom executable): + let g:ale_ruby_rails_best_practices_executable = 'bin/rails_best_practices' + + AssertEqual + \ '''bin/rails_best_practices'' --silent -f json --output-file /dev/stdout ' + \ . ale#Escape(simplify(g:dir . '/../ruby_fixtures/valid_rails_app')), + \ ale_linters#ruby#rails_best_practices#GetCommand(bufnr('')) + +Execute(Setting bundle appends 'exec rails_best_practices'): + let g:ale_ruby_rails_best_practices_executable = 'path to/bundle' + + AssertEqual + \ '''path to/bundle'' exec rails_best_practices --silent -f json --output-file /dev/stdout ' + \ . ale#Escape(simplify(g:dir . '/../ruby_fixtures/valid_rails_app')), + \ ale_linters#ruby#rails_best_practices#GetCommand(bufnr('')) + +Execute(Command callback should be empty when not in a valid Rails app): + call ale#test#SetFilename('../ruby_fixtures/not_a_rails_app/test.rb') + + AssertEqual + \ '', + \ ale_linters#ruby#rails_best_practices#GetCommand(bufnr('')) diff --git a/test/handler/test_rails_best_practices_handler.vader b/test/handler/test_rails_best_practices_handler.vader new file mode 100644 index 00000000..037d2527 --- /dev/null +++ b/test/handler/test_rails_best_practices_handler.vader @@ -0,0 +1,50 @@ +Before: + " Switch to the test rails directory. + let b:path = getcwd() + silent! cd /testplugin/test/handler + cd ../ruby_fixtures/valid_rails_app/app/models + + runtime ale_linters/ruby/rails_best_practices.vim + +After: + " Switch back to whatever directory it was that we started on. + silent! 'cd ' . fnameescape(b:path) + unlet! b:path + + call ale#linter#Reset() + +Execute(The rails_best_practices handler should parse JSON correctly): + silent file! thing.rb + + AssertEqual + \ [ + \ { + \ 'lnum': 5, + \ 'text': 'use local variable', + \ 'type': 'W', + \ }, + \ { + \ 'lnum': 10, + \ 'text': 'other advice', + \ 'type': 'W', + \ } + \ ], + \ ale_linters#ruby#rails_best_practices#Handle(bufnr(''), [ + \ '[', + \ '{', + \ '"message": "use local variable",', + \ '"line_number": "5",', + \ '"filename": "/testplugin/test/ruby_fixtures/valid_rails_app/app/models/thing.rb"', + \ '},{', + \ '"message": "other advice",', + \ '"line_number": "10",', + \ '"filename": "/testplugin/test/ruby_fixtures/valid_rails_app/app/models/thing.rb"', + \ '}', + \ ']' + \ ]) + +Execute(The rails_best_practices handler should parse JSON correctly when there is no output from the tool): + AssertEqual + \ [], + \ ale_linters#ruby#rails_best_practices#Handle(347, [ + \ ]) |