]> git.immae.eu Git - github/fretlink/pronto-hlint.git/blob - spec/pronto/eslint_spec.rb
add class variables to prepare setting external config
[github/fretlink/pronto-hlint.git] / spec / pronto / eslint_spec.rb
1 require 'spec_helper'
2
3 module Pronto
4 describe ESLintNpm do
5 let(:eslint) { ESLintNpm.new(patches) }
6
7 describe '#run' do
8 subject(:run) { eslint.run }
9
10 context 'patches are nil' do
11 let(:patches) { nil }
12
13 it 'returns an empty array' do
14 expect(run).to eql([])
15 end
16 end
17
18 context 'no patches' do
19 let(:patches) { [] }
20
21 it 'returns an empty array' do
22 expect(run).to eql([])
23 end
24 end
25
26 context 'patches with a one and a four warnings' do
27 include_context 'test repo'
28
29 let(:patches) { repo.diff('master') }
30
31 it 'returns correct number of errors' do
32 expect(run.count).to eql(5)
33 end
34
35 it 'has correct first message' do
36 expect(run.first.msg).to eql("'foo' is not defined.")
37 end
38 end
39
40 context 'repo with ignored and not ignored file, each with three warnings' do
41 include_context 'eslintignore repo'
42
43 let(:patches) { repo.diff('master') }
44
45 it 'returns correct number of errors' do
46 expect(run.count).to eql(3)
47 end
48
49 it 'has correct first message' do
50 expect(run.first.msg).to eql("'HelloWorld' is defined but never used.")
51 end
52 end
53 end
54
55 describe '.files_to_lint' do
56 subject(:files_to_lint) { ESLintNpm.files_to_lint }
57
58 it 'matches .js by default' do
59 expect(files_to_lint).to match('my_js.js')
60 end
61
62 it 'matches .es6 by default' do
63 expect(files_to_lint).to match('my_js.es6')
64 end
65 end
66
67 describe '.eslint_executable' do
68 subject(:eslint_executable) { ESLintNpm.eslint_executable }
69
70 it 'is `eslint` by default' do
71 expect(eslint_executable).to eql('eslint')
72 end
73 end
74 end
75 end