X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=spec%2Fpronto%2Feslint_spec.rb;h=b0b9c22d11bb5fc7788949b2fc4447b36c71730b;hb=e66c2f5c9b209f5e519655cb64ed563e999742e0;hp=27f57d170983c7561e68918d2a21f36b9cba7f36;hpb=295096252547f3abb76788fbadf0ce059e74f2cc;p=github%2Ffretlink%2Fpronto-hlint.git diff --git a/spec/pronto/eslint_spec.rb b/spec/pronto/eslint_spec.rb index 27f57d1..b0b9c22 100644 --- a/spec/pronto/eslint_spec.rb +++ b/spec/pronto/eslint_spec.rb @@ -1,20 +1,27 @@ require 'spec_helper' module Pronto - describe ESLint do - let(:eslint) { ESLint.new(patches) } + describe ESLintNpm do + let(:eslint) { ESLintNpm.new(patches) } + let(:patches) { [] } describe '#run' do - subject { eslint.run } + subject(:run) { eslint.run } context 'patches are nil' do let(:patches) { nil } - it { should == [] } + + it 'returns an empty array' do + expect(run).to eql([]) + end end context 'no patches' do let(:patches) { [] } - it { should == [] } + + it 'returns an empty array' do + expect(run).to eql([]) + end end context 'patches with a one and a four warnings' do @@ -22,8 +29,40 @@ module Pronto let(:patches) { repo.diff('master') } - its(:count) { should == 5 } - its(:'first.msg') { should == "'foo' is not defined." } + it 'returns correct number of errors' do + expect(run.count).to eql(5) + end + + it 'has correct first message' do + expect(run.first.msg).to eql("'foo' is not defined.") + end + + context( + 'with files to lint config that never matches', + config: { 'files_to_lint' => 'will never match' } + ) do + it 'returns zero errors' do + expect(run.count).to eql(0) + end + end + + context( + 'with files to lint config that matches only .js', + config: { 'files_to_lint' => '\.js$' } + ) do + it 'returns correct amount of errors' do + expect(run.count).to eql(2) + end + end + + context( + 'with different eslint executable', + config: { 'eslint_executable' => './custom_eslint.sh' } + ) do + it 'calls the custom eslint eslint_executable' do + expect { run }.to raise_error(JSON::ParserError, /custom eslint called/) + end + end end context 'repo with ignored and not ignored file, each with three warnings' do @@ -31,8 +70,33 @@ module Pronto let(:patches) { repo.diff('master') } - its(:count) { should == 3 } - its(:'first.msg') { should == "'HelloWorld' is defined but never used" } + it 'returns correct number of errors' do + expect(run.count).to eql(3) + end + + it 'has correct first message' do + expect(run.first.msg).to eql("'HelloWorld' is defined but never used.") + end + end + end + + describe '#files_to_lint' do + subject(:files_to_lint) { eslint.files_to_lint } + + it 'matches .js by default' do + expect(files_to_lint).to match('my_js.js') + end + + it 'matches .es6 by default' do + expect(files_to_lint).to match('my_js.es6') + end + end + + describe '#eslint_executable' do + subject(:eslint_executable) { eslint.eslint_executable } + + it 'is `eslint` by default' do + expect(eslint_executable).to eql('eslint') end end end