@@ -47,26 +47,38 @@ def apply
47
47
described_class . run ( config , arguments )
48
48
end
49
49
50
- let ( :arguments ) { instance_double ( Array ) }
51
- let ( :env ) { instance_double ( Mutant ::Env ) }
52
- let ( :report_success ) { true }
50
+ let ( :arguments ) { instance_double ( Array ) }
51
+ let ( :env ) { instance_double ( Mutant ::Env ) }
52
+ let ( :report_success ) { true }
53
+ let ( :cli_result ) { Mutant ::Either ::Right . new ( config ) }
53
54
54
55
let ( :report ) do
55
56
instance_double ( Mutant ::Result ::Env , success? : report_success )
56
57
end
57
58
58
59
before do
59
- allow ( Mutant ::CLI ) . to receive_messages ( call : config )
60
+ allow ( Mutant ::CLI ) . to receive_messages ( apply : cli_result )
60
61
allow ( Mutant ::Env ::Bootstrap ) . to receive_messages ( call : env )
61
62
allow ( Mutant ::Runner ) . to receive_messages ( call : report )
62
63
end
63
64
64
65
it 'performs calls in expected sequence' do
65
66
apply
66
67
67
- expect ( Mutant ::CLI ) . to have_received ( :call ) . with ( config , arguments ) . ordered
68
- expect ( Mutant ::Env ::Bootstrap ) . to have_received ( :call ) . with ( config ) . ordered
69
- expect ( Mutant ::Runner ) . to have_received ( :call ) . with ( env ) . ordered
68
+ expect ( Mutant ::CLI )
69
+ . to have_received ( :apply )
70
+ . with ( config , arguments )
71
+ . ordered
72
+
73
+ expect ( Mutant ::Env ::Bootstrap )
74
+ . to have_received ( :call )
75
+ . with ( config )
76
+ . ordered
77
+
78
+ expect ( Mutant ::Runner )
79
+ . to have_received ( :call )
80
+ . with ( env )
81
+ . ordered
70
82
end
71
83
72
84
context 'when report signals success' do
@@ -85,30 +97,27 @@ def apply
85
97
end
86
98
end
87
99
88
- context 'when execution raises an Mutant::CLI::Error' do
89
- let ( :exception ) { Mutant ::CLI ::Error . new ( 'test-error' ) }
90
- let ( :expected_message ) { 'test-error' }
91
- let ( :report_success ) { false }
92
- let ( :target_stream ) { stderr }
100
+ context 'when parts of the chain fail' do
101
+ let ( :cli_result ) { Mutant ::Either ::Left . new ( expected_message ) }
102
+ let ( :expected_message ) { 'cli-error' }
103
+ let ( :target_stream ) { stderr }
93
104
94
- before do
95
- allow ( report ) . to receive ( :success? ) . and_raise ( exception )
96
- end
105
+ include_examples 'prints expected message'
97
106
98
- it 'exits with failure' do
107
+ it 'exits failure' do
99
108
expect ( apply ) . to be ( false )
100
109
end
101
-
102
- include_examples 'prints expected message'
103
110
end
104
111
end
105
112
106
- describe '.new' do
113
+ describe '.apply' do
114
+ def apply
115
+ described_class . apply ( config , arguments )
116
+ end
117
+
107
118
shared_examples 'invalid arguments' do
108
- it 'raises error' do
109
- expect do
110
- apply
111
- end . to raise_error ( Mutant ::CLI ::Error , expected_message )
119
+ it 'returns left error' do
120
+ expect ( apply ) . to eql ( Mutant ::Either ::Left . new ( expected_message ) )
112
121
end
113
122
end
114
123
@@ -127,12 +136,8 @@ def apply
127
136
end
128
137
129
138
shared_examples_for 'cli parser' do
130
- it { expect ( apply . config . integration ) . to eql ( expected_integration ) }
131
- it { expect ( apply . config . matcher ) . to eql ( expected_matcher_config ) }
132
- end
133
-
134
- def apply
135
- described_class . new ( config , arguments )
139
+ it { expect ( apply . from_right . integration ) . to eql ( expected_integration ) }
140
+ it { expect ( apply . from_right . matcher ) . to eql ( expected_matcher_config ) }
136
141
end
137
142
138
143
before do
@@ -192,7 +197,7 @@ def apply
192
197
include_examples 'no explicit exit'
193
198
194
199
it 'configures includes' do
195
- expect ( apply . config . includes ) . to eql ( %w[ foo ] )
200
+ expect ( apply . from_right . includes ) . to eql ( %w[ foo ] )
196
201
end
197
202
end
198
203
@@ -222,15 +227,18 @@ def apply
222
227
context 'when integration does NOT exist' do
223
228
let ( :options ) { %w[ --use other ] }
224
229
230
+ let ( :expected_message ) do
231
+ 'invalid argument: ' \
232
+ '--use Could not load integration "other" ' \
233
+ '(you may want to try installing the gem mutant-other)'
234
+ end
235
+
225
236
before do
226
237
allow ( Mutant ::Integration ) . to receive ( :setup ) . and_raise ( LoadError )
227
238
end
228
239
229
- it 'raises error' do
230
- expect { apply } . to raise_error (
231
- Mutant ::CLI ::Error ,
232
- 'Could not load integration "other" (you may want to try installing the gem mutant-other)'
233
- )
240
+ it 'returns error' do
241
+ expect ( apply ) . to eql ( Mutant ::Either ::Left . new ( expected_message ) )
234
242
end
235
243
end
236
244
end
@@ -251,7 +259,7 @@ def apply
251
259
include_examples 'no explicit exit'
252
260
253
261
it 'configures expected coverage' do
254
- expect ( apply . config . jobs ) . to eql ( 0 )
262
+ expect ( apply . from_right . jobs ) . to eql ( 0 )
255
263
end
256
264
end
257
265
@@ -262,7 +270,7 @@ def apply
262
270
include_examples 'no explicit exit'
263
271
264
272
it 'configures requires' do
265
- expect ( apply . config . requires ) . to eql ( %w[ foo bar ] )
273
+ expect ( apply . from_right . requires ) . to eql ( %w[ foo bar ] )
266
274
end
267
275
end
268
276
@@ -305,7 +313,7 @@ def apply
305
313
include_examples 'no explicit exit'
306
314
307
315
it 'sets the fail fast option' do
308
- expect ( apply . config . fail_fast ) . to be ( true )
316
+ expect ( apply . from_right . fail_fast ) . to be ( true )
309
317
end
310
318
end
311
319
@@ -316,7 +324,7 @@ def apply
316
324
include_examples 'no explicit exit'
317
325
318
326
it 'sets the zombie option' do
319
- expect ( apply . config . zombie ) . to be ( true )
327
+ expect ( apply . from_right . zombie ) . to be ( true )
320
328
end
321
329
end
322
330
end
0 commit comments