aboutsummaryrefslogtreecommitdiffhomepage
path: root/spec/pronto
diff options
context:
space:
mode:
Diffstat (limited to 'spec/pronto')
-rw-r--r--spec/pronto/eslint_spec.rb163
-rw-r--r--spec/pronto/hlint_spec.rb138
2 files changed, 138 insertions, 163 deletions
diff --git a/spec/pronto/eslint_spec.rb b/spec/pronto/eslint_spec.rb
deleted file mode 100644
index 0924f30..0000000
--- a/spec/pronto/eslint_spec.rb
+++ /dev/null
@@ -1,163 +0,0 @@
1# frozen_string_literal: true
2
3require 'spec_helper'
4
5module Pronto
6 describe ESLintNpm do
7 let(:eslint) { ESLintNpm.new(patches) }
8 let(:patches) { [] }
9
10 describe '#run' do
11 subject(:run) { eslint.run }
12
13 context 'patches are nil' do
14 let(:patches) { nil }
15
16 it 'returns an empty array' do
17 expect(run).to eql([])
18 end
19 end
20
21 context 'no patches' do
22 let(:patches) { [] }
23
24 it 'returns an empty array' do
25 expect(run).to eql([])
26 end
27 end
28
29 context 'patches with a one and a four warnings' do
30 include_context 'test repo'
31
32 let(:patches) { repo.diff('master') }
33
34 it 'returns correct number of errors' do
35 expect(run.count).to eql(5)
36 end
37
38 it 'has correct first message' do
39 expect(run.first.msg).to eql("'foo' is not defined.")
40 end
41
42 context(
43 'with files to lint config that never matches',
44 config: { 'files_to_lint' => 'will never match' }
45 ) do
46 it 'returns zero errors' do
47 expect(run.count).to eql(0)
48 end
49 end
50
51 context(
52 'with files to lint config that matches only .js',
53 config: { 'files_to_lint' => '\.js$' }
54 ) do
55 it 'returns correct amount of errors' do
56 expect(run.count).to eql(2)
57 end
58 end
59
60 context(
61 'with cmd_line_opts to include .html',
62 config: { 'cmd_line_opts' => '--ext .html' }
63 ) do
64 it 'returns correct number of errors' do
65 expect(run.count).to eql 5
66 end
67 end
68
69 context(
70 'with different eslint executable',
71 config: { 'eslint_executable' => './custom_eslint.sh' }
72 ) do
73 it 'calls the custom eslint eslint_executable' do
74 expect { run }.to raise_error(JSON::ParserError, /custom eslint called/)
75 end
76 end
77 end
78
79 context 'repo with ignored and not ignored file, each with three warnings' do
80 include_context 'eslintignore repo'
81
82 let(:patches) { repo.diff('master') }
83
84 it 'returns correct number of errors' do
85 expect(run.count).to eql(3)
86 end
87
88 it 'has correct first message' do
89 expect(run.first.msg).to eql("'HelloWorld' is defined but never used.")
90 end
91 end
92 end
93
94 describe '#files_to_lint' do
95 subject(:files_to_lint) { eslint.files_to_lint }
96
97 it 'matches .js by default' do
98 expect(files_to_lint).to match('my_js.js')
99 end
100
101 it 'matches .es6 by default' do
102 expect(files_to_lint).to match('my_js.es6')
103 end
104 end
105
106 describe '#eslint_executable' do
107 subject(:eslint_executable) { eslint.eslint_executable }
108
109 it 'is `eslint` by default' do
110 expect(eslint_executable).to eql('eslint')
111 end
112
113 context(
114 'with different eslint executable config',
115 config: { 'eslint_executable' => 'custom_eslint' }
116 ) do
117 it 'is correct' do
118 eslint.read_config
119 expect(eslint_executable).to eql('custom_eslint')
120 end
121 end
122 end
123
124 describe '#eslint_command_line' do
125 subject(:eslint_command_line) { eslint.send(:eslint_command_line, path) }
126 let(:path) { '/some/path.rb' }
127
128 it 'adds json output flag' do
129 expect(eslint_command_line).to include('-f json')
130 end
131
132 it 'adds path' do
133 expect(eslint_command_line).to include(path)
134 end
135
136 it 'starts with eslint executable' do
137 expect(eslint_command_line).to start_with(eslint.eslint_executable)
138 end
139
140 context 'with path that should be escaped' do
141 let(:path) { '/must be/$escaped' }
142
143 it 'escapes the path correctly' do
144 expect(eslint_command_line).to include('/must\\ be/\\$escaped')
145 end
146
147 it 'does not include unescaped path' do
148 expect(eslint_command_line).not_to include(path)
149 end
150 end
151
152 context(
153 'with some command line options',
154 config: { 'cmd_line_opts' => '--my command --line opts' }
155 ) do
156 it 'includes the custom command line options' do
157 eslint.read_config
158 expect(eslint_command_line).to include('--my command --line opts')
159 end
160 end
161 end
162 end
163end
diff --git a/spec/pronto/hlint_spec.rb b/spec/pronto/hlint_spec.rb
new file mode 100644
index 0000000..fdabab5
--- /dev/null
+++ b/spec/pronto/hlint_spec.rb
@@ -0,0 +1,138 @@
1# frozen_string_literal: true
2
3require 'spec_helper'
4
5module Pronto
6 module Hlint
7 describe Runner do
8 let(:hlint) { Hlint::Runner.new(patches) }
9 let(:patches) { [] }
10
11 describe '#run' do
12 subject(:run) { hlint.run }
13
14 context 'patches are nil' do
15 let(:patches) { nil }
16
17 it 'returns an empty array' do
18 expect(run).to eql([])
19 end
20 end
21
22 context 'no patches' do
23 let(:patches) { [] }
24
25 it 'returns an empty array' do
26 expect(run).to eql([])
27 end
28 end
29
30 context 'patches with a one and a four warnings' do
31 include_context 'test repo'
32
33 let(:patches) { repo.diff('master') }
34
35 it 'returns correct number of errors' do
36 expect(run.count).to eql(3)
37 end
38
39 it 'has correct first message' do
40 expect(run.first.msg).to match("Unused LANGUAGE pragma")
41 end
42
43 context(
44 'with files to lint config that never matches',
45 config: { 'files_to_lint' => 'will never match' }
46 ) do
47 it 'returns zero errors' do
48 expect(run.count).to eql(0)
49 end
50 end
51
52 context(
53 'with files to lint config that matches only .lhs',
54 config: { 'files_to_lint' => '\.lhs$' }
55 ) do
56 it 'returns correct amount of errors' do
57 expect(run.count).to eql(0)
58 end
59 end
60
61 context(
62 'with different hlint executable',
63 config: { 'hlint_executable' => './custom_hlint.sh' }
64 ) do
65 it 'calls the custom hlint hlint_executable' do
66 expect { run }.to raise_error(JSON::ParserError, /hlint called!/)
67 end
68 end
69 end
70 end
71
72 describe '#files_to_lint' do
73 subject(:files_to_lint) { hlint.files_to_lint }
74
75 it 'matches .he by default' do
76 expect(files_to_lint).to match('Types.hs')
77 end
78 end
79
80 describe '#hlint_executable' do
81 subject(:hlint_executable) { hlint.hlint_executable }
82
83 it 'is `hlint` by default' do
84 expect(hlint_executable).to eql('hlint')
85 end
86
87 context(
88 'with different hlint executable config',
89 config: { 'hlint_executable' => 'custom_hlint' }
90 ) do
91 it 'is correct' do
92 hlint.read_config
93 expect(hlint_executable).to eql('custom_hlint')
94 end
95 end
96 end
97
98 describe '#hlint_command_line' do
99 subject(:hlint_command_line) { hlint.send(:hlint_command_line, path) }
100 let(:path) { '/some/path.rb' }
101
102 it 'adds json output flag' do
103 expect(hlint_command_line).to include('--json')
104 end
105
106 it 'adds path' do
107 expect(hlint_command_line).to include(path)
108 end
109
110 it 'starts with hlint executable' do
111 expect(hlint_command_line).to start_with(hlint.hlint_executable)
112 end
113
114 context 'with path that should be escaped' do
115 let(:path) { '/must be/$escaped' }
116
117 it 'escapes the path correctly' do
118 expect(hlint_command_line).to include('/must\\ be/\\$escaped')
119 end
120
121 it 'does not include unescaped path' do
122 expect(hlint_command_line).not_to include(path)
123 end
124 end
125
126 context(
127 'with some command line options',
128 config: { 'cmd_line_opts' => '--my command --line opts' }
129 ) do
130 it 'includes the custom command line options' do
131 hlint.read_config
132 expect(hlint_command_line).to include('--my command --line opts')
133 end
134 end
135 end
136 end
137 end
138end