transpec 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/lib/transpec/version.rb +1 -1
- data/transpec.gemspec +4 -3
- metadata +3 -97
- data/spec/.rubocop.yml +0 -23
- data/spec/integration/configuration_modification_spec.rb +0 -186
- data/spec/integration/conversion_spec.rb +0 -145
- data/spec/spec_helper.rb +0 -52
- data/spec/support/cache_helper.rb +0 -62
- data/spec/support/file_helper.rb +0 -25
- data/spec/support/shared_context.rb +0 -84
- data/spec/transpec/cli_spec.rb +0 -341
- data/spec/transpec/commit_message_spec.rb +0 -81
- data/spec/transpec/config_spec.rb +0 -99
- data/spec/transpec/converter_spec.rb +0 -1374
- data/spec/transpec/directory_cloner_spec.rb +0 -74
- data/spec/transpec/dynamic_analyzer/rewriter_spec.rb +0 -143
- data/spec/transpec/dynamic_analyzer_spec.rb +0 -329
- data/spec/transpec/git_spec.rb +0 -151
- data/spec/transpec/option_parser_spec.rb +0 -275
- data/spec/transpec/processed_source_spec.rb +0 -93
- data/spec/transpec/project_spec.rb +0 -194
- data/spec/transpec/record_spec.rb +0 -128
- data/spec/transpec/report_spec.rb +0 -126
- data/spec/transpec/rspec_version_spec.rb +0 -129
- data/spec/transpec/spec_file_finder_spec.rb +0 -118
- data/spec/transpec/spec_suite_spec.rb +0 -108
- data/spec/transpec/static_context_inspector_spec.rb +0 -713
- data/spec/transpec/syntax/allow_spec.rb +0 -122
- data/spec/transpec/syntax/be_boolean_spec.rb +0 -176
- data/spec/transpec/syntax/be_close_spec.rb +0 -51
- data/spec/transpec/syntax/current_example_spec.rb +0 -319
- data/spec/transpec/syntax/double_spec.rb +0 -175
- data/spec/transpec/syntax/example_group_spec.rb +0 -716
- data/spec/transpec/syntax/example_spec.rb +0 -301
- data/spec/transpec/syntax/expect_spec.rb +0 -313
- data/spec/transpec/syntax/have_spec.rb +0 -1276
- data/spec/transpec/syntax/hook_spec.rb +0 -215
- data/spec/transpec/syntax/its_spec.rb +0 -448
- data/spec/transpec/syntax/matcher_definition_spec.rb +0 -59
- data/spec/transpec/syntax/method_stub_spec.rb +0 -1301
- data/spec/transpec/syntax/oneliner_should_spec.rb +0 -628
- data/spec/transpec/syntax/operator_spec.rb +0 -871
- data/spec/transpec/syntax/pending_spec.rb +0 -415
- data/spec/transpec/syntax/raise_error_spec.rb +0 -354
- data/spec/transpec/syntax/receive_spec.rb +0 -499
- data/spec/transpec/syntax/rspec_configure_spec.rb +0 -870
- data/spec/transpec/syntax/should_receive_spec.rb +0 -1108
- data/spec/transpec/syntax/should_spec.rb +0 -497
- data/spec/transpec/util_spec.rb +0 -115
- data/spec/transpec_spec.rb +0 -22
@@ -1,870 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'transpec/syntax/rspec_configure'
|
5
|
-
require 'transpec/rspec_version'
|
6
|
-
|
7
|
-
module Transpec
|
8
|
-
class Syntax
|
9
|
-
describe RSpecConfigure do
|
10
|
-
include_context 'parsed objects'
|
11
|
-
include_context 'syntax object', RSpecConfigure, :rspec_configure
|
12
|
-
|
13
|
-
let(:record) { rspec_configure.report.records.first }
|
14
|
-
|
15
|
-
context 'when multiple configurations are added' do
|
16
|
-
before do
|
17
|
-
rspec_configure.stub(:rspec_rails?).and_return(true)
|
18
|
-
rspec_configure.expose_dsl_globally = true
|
19
|
-
rspec_configure.infer_spec_type_from_file_location!
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:source) do
|
23
|
-
<<-END
|
24
|
-
RSpec.configure do |config|
|
25
|
-
end
|
26
|
-
END
|
27
|
-
end
|
28
|
-
|
29
|
-
let(:expected_source) do
|
30
|
-
<<-END
|
31
|
-
RSpec.configure do |config|
|
32
|
-
# Setting this config option `false` removes rspec-core's monkey patching of the
|
33
|
-
# top level methods like `describe`, `shared_examples_for` and `shared_context`
|
34
|
-
# on `main` and `Module`. The methods are always available through the `RSpec`
|
35
|
-
# module like `RSpec.describe` regardless of this setting.
|
36
|
-
# For backwards compatibility this defaults to `true`.
|
37
|
-
#
|
38
|
-
# https://relishapp.com/rspec/rspec-core/v/3-0/docs/configuration/global-namespace-dsl
|
39
|
-
config.expose_dsl_globally = true
|
40
|
-
|
41
|
-
# rspec-rails 3 will no longer automatically infer an example group's spec type
|
42
|
-
# from the file location. You can explicitly opt-in to the feature using this
|
43
|
-
# config option.
|
44
|
-
# To explicitly tag specs without using automatic inference, set the `:type`
|
45
|
-
# metadata manually:
|
46
|
-
#
|
47
|
-
# describe ThingsController, :type => :controller do
|
48
|
-
# # Equivalent to being in spec/controllers
|
49
|
-
# end
|
50
|
-
config.infer_spec_type_from_file_location!
|
51
|
-
end
|
52
|
-
END
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'properly adds them' do
|
56
|
-
rewritten_source.should == expected_source
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '#convert_deprecated_options!' do
|
61
|
-
before do
|
62
|
-
rspec_configure.stub(:rspec_version).and_return(RSpecVersion.new('3.0.0'))
|
63
|
-
rspec_configure.convert_deprecated_options!
|
64
|
-
end
|
65
|
-
|
66
|
-
[
|
67
|
-
[:output, :output_stream],
|
68
|
-
[:out, :output_stream],
|
69
|
-
[:filename_pattern, :pattern],
|
70
|
-
[:backtrace_cleaner, :backtrace_formatter],
|
71
|
-
[:backtrace_clean_patterns, :backtrace_exclusion_patterns],
|
72
|
-
[:warnings, :warnings?]
|
73
|
-
].each do |old_config, new_config|
|
74
|
-
context "with `c.#{old_config}`" do
|
75
|
-
let(:source) do
|
76
|
-
<<-END
|
77
|
-
RSpec.configure do |config|
|
78
|
-
if config.#{old_config} == something
|
79
|
-
do_something
|
80
|
-
end
|
81
|
-
end
|
82
|
-
END
|
83
|
-
end
|
84
|
-
|
85
|
-
let(:expected_source) do
|
86
|
-
<<-END
|
87
|
-
RSpec.configure do |config|
|
88
|
-
if config.#{new_config} == something
|
89
|
-
do_something
|
90
|
-
end
|
91
|
-
end
|
92
|
-
END
|
93
|
-
end
|
94
|
-
|
95
|
-
it "converts to `c.#{new_config}`" do
|
96
|
-
rewritten_source.should == expected_source
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'adds record of conversion ' \
|
100
|
-
"`RSpec.configure { |c| c.#{old_config} }` -> " \
|
101
|
-
"`RSpec.configure { |c| c.#{new_config} }`" do
|
102
|
-
record.type.should == :conversion
|
103
|
-
record.old_syntax.should == "RSpec.configure { |c| c.#{old_config} }"
|
104
|
-
record.new_syntax.should == "RSpec.configure { |c| c.#{new_config} }"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
[
|
110
|
-
[:output, :output_stream],
|
111
|
-
[:out, :output_stream],
|
112
|
-
[:filename_pattern, :pattern],
|
113
|
-
[:backtrace_clean_patterns, :backtrace_exclusion_patterns],
|
114
|
-
[:color_enabled, :color]
|
115
|
-
].each do |old_config, new_config|
|
116
|
-
context "with `c.#{old_config} = something`" do
|
117
|
-
let(:source) do
|
118
|
-
<<-END
|
119
|
-
RSpec.configure do |config|
|
120
|
-
config.#{old_config} = something
|
121
|
-
end
|
122
|
-
END
|
123
|
-
end
|
124
|
-
|
125
|
-
let(:expected_source) do
|
126
|
-
<<-END
|
127
|
-
RSpec.configure do |config|
|
128
|
-
config.#{new_config} = something
|
129
|
-
end
|
130
|
-
END
|
131
|
-
end
|
132
|
-
|
133
|
-
it "converts to `c.#{new_config} = something`" do
|
134
|
-
rewritten_source.should == expected_source
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'adds record of conversion ' \
|
138
|
-
"`RSpec.configure { |c| c.#{old_config} = something }` -> " \
|
139
|
-
"`RSpec.configure { |c| c.#{new_config} = something }`" do
|
140
|
-
record.type.should == :conversion
|
141
|
-
record.old_syntax.should == "RSpec.configure { |c| c.#{old_config} = something }"
|
142
|
-
record.new_syntax.should == "RSpec.configure { |c| c.#{new_config} = something }"
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context 'with `c.color?(io)`' do
|
148
|
-
let(:source) do
|
149
|
-
<<-END
|
150
|
-
RSpec.configure do |config|
|
151
|
-
if config.color?($stdout)
|
152
|
-
do_something
|
153
|
-
end
|
154
|
-
end
|
155
|
-
END
|
156
|
-
end
|
157
|
-
|
158
|
-
let(:expected_source) do
|
159
|
-
<<-END
|
160
|
-
RSpec.configure do |config|
|
161
|
-
if config.color_enabled?($stdout)
|
162
|
-
do_something
|
163
|
-
end
|
164
|
-
end
|
165
|
-
END
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'convertes to `c.color_enabled?(io)`' do
|
169
|
-
rewritten_source.should == expected_source
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
describe '#expose_dsl_globally=' do
|
175
|
-
before do
|
176
|
-
rspec_configure.expose_dsl_globally = false
|
177
|
-
end
|
178
|
-
|
179
|
-
context 'when #expose_dsl_globally= already exists' do
|
180
|
-
context 'and the current value is same as the new value' do
|
181
|
-
let(:source) do
|
182
|
-
<<-END
|
183
|
-
RSpec.configure do |config|
|
184
|
-
config.expose_dsl_globally = false
|
185
|
-
end
|
186
|
-
END
|
187
|
-
end
|
188
|
-
|
189
|
-
it 'does nothing' do
|
190
|
-
rewritten_source.should == source
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'reports nothing' do
|
194
|
-
record.should be_nil
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
context 'and the current value is different from the new value' do
|
199
|
-
let(:source) do
|
200
|
-
<<-END
|
201
|
-
RSpec.configure do |config|
|
202
|
-
config.expose_dsl_globally = true
|
203
|
-
end
|
204
|
-
END
|
205
|
-
end
|
206
|
-
|
207
|
-
let(:expected_source) do
|
208
|
-
<<-END
|
209
|
-
RSpec.configure do |config|
|
210
|
-
config.expose_dsl_globally = false
|
211
|
-
end
|
212
|
-
END
|
213
|
-
end
|
214
|
-
|
215
|
-
it 'rewrites the value' do
|
216
|
-
rewritten_source.should == expected_source
|
217
|
-
end
|
218
|
-
|
219
|
-
it 'adds record of modification ' \
|
220
|
-
'`RSpec.configure { |c| c.expose_dsl_globally = true }` -> ' \
|
221
|
-
'`RSpec.configure { |c| c.expose_dsl_globally = false }`' do
|
222
|
-
record.type.should == :modification
|
223
|
-
record.old_syntax.should == 'RSpec.configure { |c| c.expose_dsl_globally = true }'
|
224
|
-
record.new_syntax.should == 'RSpec.configure { |c| c.expose_dsl_globally = false }'
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
context 'when #expose_dsl_globally= does not exist' do
|
230
|
-
let(:source) do
|
231
|
-
<<-END
|
232
|
-
RSpec.configure do |config|
|
233
|
-
end
|
234
|
-
END
|
235
|
-
end
|
236
|
-
|
237
|
-
let(:expected_source) do
|
238
|
-
<<-END
|
239
|
-
RSpec.configure do |config|
|
240
|
-
# Setting this config option `false` removes rspec-core's monkey patching of the
|
241
|
-
# top level methods like `describe`, `shared_examples_for` and `shared_context`
|
242
|
-
# on `main` and `Module`. The methods are always available through the `RSpec`
|
243
|
-
# module like `RSpec.describe` regardless of this setting.
|
244
|
-
# For backwards compatibility this defaults to `true`.
|
245
|
-
#
|
246
|
-
# https://relishapp.com/rspec/rspec-core/v/3-0/docs/configuration/global-namespace-dsl
|
247
|
-
config.expose_dsl_globally = false
|
248
|
-
end
|
249
|
-
END
|
250
|
-
end
|
251
|
-
|
252
|
-
it 'adds #expose_dsl_globally= statement along with comment' do
|
253
|
-
rewritten_source.should == expected_source
|
254
|
-
end
|
255
|
-
|
256
|
-
it 'adds record of addition `RSpec.configure { |c| c.expose_dsl_globally = value }`' do
|
257
|
-
record.type.should == :addition
|
258
|
-
record.new_syntax.should == 'RSpec.configure { |c| c.expose_dsl_globally = false }'
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
context 'when there are already some other configurations' do
|
263
|
-
let(:source) do
|
264
|
-
<<-END
|
265
|
-
RSpec.configure do |config|
|
266
|
-
config.foo = 1
|
267
|
-
end
|
268
|
-
END
|
269
|
-
end
|
270
|
-
|
271
|
-
let(:expected_source) do
|
272
|
-
<<-END
|
273
|
-
RSpec.configure do |config|
|
274
|
-
config.foo = 1
|
275
|
-
|
276
|
-
# Setting this config option `false` removes rspec-core's monkey patching of the
|
277
|
-
# top level methods like `describe`, `shared_examples_for` and `shared_context`
|
278
|
-
# on `main` and `Module`. The methods are always available through the `RSpec`
|
279
|
-
# module like `RSpec.describe` regardless of this setting.
|
280
|
-
# For backwards compatibility this defaults to `true`.
|
281
|
-
#
|
282
|
-
# https://relishapp.com/rspec/rspec-core/v/3-0/docs/configuration/global-namespace-dsl
|
283
|
-
config.expose_dsl_globally = false
|
284
|
-
end
|
285
|
-
END
|
286
|
-
end
|
287
|
-
|
288
|
-
it 'adds the block after a blank line' do
|
289
|
-
rewritten_source.should == expected_source
|
290
|
-
end
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
describe '#infer_spec_type_from_file_location!' do
|
295
|
-
context 'in rspec-rails project' do
|
296
|
-
before do
|
297
|
-
rspec_configure.stub(:rspec_rails?).and_return(true)
|
298
|
-
rspec_configure.infer_spec_type_from_file_location!
|
299
|
-
end
|
300
|
-
|
301
|
-
context 'when #infer_spec_type_from_file_location! does not exist' do
|
302
|
-
let(:source) do
|
303
|
-
<<-END
|
304
|
-
RSpec.configure do |config|
|
305
|
-
end
|
306
|
-
END
|
307
|
-
end
|
308
|
-
|
309
|
-
let(:expected_source) do
|
310
|
-
<<-END
|
311
|
-
RSpec.configure do |config|
|
312
|
-
# rspec-rails 3 will no longer automatically infer an example group's spec type
|
313
|
-
# from the file location. You can explicitly opt-in to the feature using this
|
314
|
-
# config option.
|
315
|
-
# To explicitly tag specs without using automatic inference, set the `:type`
|
316
|
-
# metadata manually:
|
317
|
-
#
|
318
|
-
# describe ThingsController, :type => :controller do
|
319
|
-
# # Equivalent to being in spec/controllers
|
320
|
-
# end
|
321
|
-
config.infer_spec_type_from_file_location!
|
322
|
-
end
|
323
|
-
END
|
324
|
-
end
|
325
|
-
|
326
|
-
it 'adds #infer_spec_type_from_file_location! statement along with comment' do
|
327
|
-
rewritten_source.should == expected_source
|
328
|
-
end
|
329
|
-
|
330
|
-
it 'adds record of addition `RSpec.configure { |c| c.expose_dsl_globally = value }`' do
|
331
|
-
record.type.should == :addition
|
332
|
-
record.new_syntax.should == 'RSpec.configure { |c| c.infer_spec_type_from_file_location! }'
|
333
|
-
end
|
334
|
-
end
|
335
|
-
|
336
|
-
context 'when #infer_spec_type_from_file_location! already exists' do
|
337
|
-
let(:source) do
|
338
|
-
<<-END
|
339
|
-
RSpec.configure do |config|
|
340
|
-
config.infer_spec_type_from_file_location!
|
341
|
-
end
|
342
|
-
END
|
343
|
-
end
|
344
|
-
|
345
|
-
it 'does nothing' do
|
346
|
-
rewritten_source.should == source
|
347
|
-
end
|
348
|
-
|
349
|
-
it 'reports nothing' do
|
350
|
-
record.should be_nil
|
351
|
-
end
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
context 'with runtime information' do
|
356
|
-
include_context 'dynamic analysis objects'
|
357
|
-
|
358
|
-
before do
|
359
|
-
rspec_configure.infer_spec_type_from_file_location!
|
360
|
-
end
|
361
|
-
|
362
|
-
context 'when rspec-rails is loaded in the spec' do
|
363
|
-
let(:source) do
|
364
|
-
<<-END
|
365
|
-
module RSpec
|
366
|
-
module Rails
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
RSpec.configure do |config|
|
371
|
-
end
|
372
|
-
END
|
373
|
-
end
|
374
|
-
|
375
|
-
let(:expected_source) do
|
376
|
-
<<-END
|
377
|
-
module RSpec
|
378
|
-
module Rails
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
RSpec.configure do |config|
|
383
|
-
# rspec-rails 3 will no longer automatically infer an example group's spec type
|
384
|
-
# from the file location. You can explicitly opt-in to the feature using this
|
385
|
-
# config option.
|
386
|
-
# To explicitly tag specs without using automatic inference, set the `:type`
|
387
|
-
# metadata manually:
|
388
|
-
#
|
389
|
-
# describe ThingsController, :type => :controller do
|
390
|
-
# # Equivalent to being in spec/controllers
|
391
|
-
# end
|
392
|
-
config.infer_spec_type_from_file_location!
|
393
|
-
end
|
394
|
-
END
|
395
|
-
end
|
396
|
-
|
397
|
-
it 'adds #infer_spec_type_from_file_location! statement' do
|
398
|
-
rewritten_source.should == expected_source
|
399
|
-
end
|
400
|
-
|
401
|
-
context 'when rspec-rails is not loaded in the spec' do
|
402
|
-
let(:source) do
|
403
|
-
<<-END
|
404
|
-
RSpec.configure do |config|
|
405
|
-
end
|
406
|
-
END
|
407
|
-
end
|
408
|
-
|
409
|
-
it 'does nothing' do
|
410
|
-
rewritten_source.should == source
|
411
|
-
end
|
412
|
-
end
|
413
|
-
end
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
shared_examples '#syntaxes' do |framework_block_method|
|
418
|
-
describe '#syntaxes' do
|
419
|
-
subject { super().syntaxes }
|
420
|
-
|
421
|
-
context 'when :should is enabled' do
|
422
|
-
let(:source) do
|
423
|
-
<<-END
|
424
|
-
RSpec.configure do |config|
|
425
|
-
config.#{framework_block_method} :rspec do |c|
|
426
|
-
c.syntax = :should
|
427
|
-
end
|
428
|
-
end
|
429
|
-
END
|
430
|
-
end
|
431
|
-
|
432
|
-
it 'returns [:should]' do
|
433
|
-
should == [:should]
|
434
|
-
end
|
435
|
-
end
|
436
|
-
|
437
|
-
context 'when :should and :expect are enabled' do
|
438
|
-
let(:source) do
|
439
|
-
<<-END
|
440
|
-
RSpec.configure do |config|
|
441
|
-
config.#{framework_block_method} :rspec do |c|
|
442
|
-
c.syntax = [:should, :expect]
|
443
|
-
end
|
444
|
-
end
|
445
|
-
END
|
446
|
-
end
|
447
|
-
|
448
|
-
it 'returns [:should, :expect]' do
|
449
|
-
should == [:should, :expect]
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
context 'when the syntax is specified indirectly with method or variable' do
|
454
|
-
let(:source) do
|
455
|
-
<<-END
|
456
|
-
RSpec.configure do |config|
|
457
|
-
config.#{framework_block_method} :rspec do |c|
|
458
|
-
c.syntax = some_syntax
|
459
|
-
end
|
460
|
-
end
|
461
|
-
END
|
462
|
-
end
|
463
|
-
|
464
|
-
it 'raises error' do
|
465
|
-
-> { subject }.should raise_error(RSpecConfigure::Framework::UnknownSyntaxError)
|
466
|
-
end
|
467
|
-
end
|
468
|
-
|
469
|
-
context "when ##{framework_block_method} block does not exist" do
|
470
|
-
let(:source) do
|
471
|
-
<<-END
|
472
|
-
RSpec.configure do |config|
|
473
|
-
end
|
474
|
-
END
|
475
|
-
end
|
476
|
-
|
477
|
-
it 'returns empty array' do
|
478
|
-
should == []
|
479
|
-
end
|
480
|
-
end
|
481
|
-
|
482
|
-
context "when ##{framework_block_method} { #syntax= } does not exist" do
|
483
|
-
let(:source) do
|
484
|
-
<<-END
|
485
|
-
RSpec.configure do |config|
|
486
|
-
config.#{framework_block_method} :rspec do |c|
|
487
|
-
end
|
488
|
-
end
|
489
|
-
END
|
490
|
-
end
|
491
|
-
|
492
|
-
it 'returns empty array' do
|
493
|
-
should == []
|
494
|
-
end
|
495
|
-
end
|
496
|
-
end
|
497
|
-
end
|
498
|
-
|
499
|
-
shared_examples '#syntaxes=' do |framework_block_method, block_arg_name|
|
500
|
-
describe '#syntaxes=' do
|
501
|
-
before do
|
502
|
-
subject.syntaxes = syntaxes
|
503
|
-
end
|
504
|
-
|
505
|
-
let(:source) do
|
506
|
-
<<-END
|
507
|
-
RSpec.configure do |config|
|
508
|
-
config.#{framework_block_method} :rspec do |c|
|
509
|
-
c.syntax = :should
|
510
|
-
end
|
511
|
-
end
|
512
|
-
END
|
513
|
-
end
|
514
|
-
|
515
|
-
context 'when :expect is passed' do
|
516
|
-
let(:syntaxes) { :expect }
|
517
|
-
|
518
|
-
let(:expected_source) do
|
519
|
-
<<-END
|
520
|
-
RSpec.configure do |config|
|
521
|
-
config.#{framework_block_method} :rspec do |c|
|
522
|
-
c.syntax = :expect
|
523
|
-
end
|
524
|
-
end
|
525
|
-
END
|
526
|
-
end
|
527
|
-
|
528
|
-
it 'rewrites syntax specification to `c.syntax = :expect`' do
|
529
|
-
rewritten_source.should == expected_source
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
|
-
context 'when [:should, :expect] is passed' do
|
534
|
-
let(:syntaxes) { [:should, :expect] }
|
535
|
-
|
536
|
-
let(:expected_source) do
|
537
|
-
<<-END
|
538
|
-
RSpec.configure do |config|
|
539
|
-
config.#{framework_block_method} :rspec do |c|
|
540
|
-
c.syntax = [:should, :expect]
|
541
|
-
end
|
542
|
-
end
|
543
|
-
END
|
544
|
-
end
|
545
|
-
|
546
|
-
it 'rewrites syntax specification to `c.syntax = [:should, :expect]`' do
|
547
|
-
rewritten_source.should == expected_source
|
548
|
-
end
|
549
|
-
end
|
550
|
-
|
551
|
-
context "when ##{framework_block_method} { #syntax= } does not exist" do
|
552
|
-
let(:source) do
|
553
|
-
<<-END
|
554
|
-
RSpec.configure do |config|
|
555
|
-
config.#{framework_block_method} :rspec do |c|
|
556
|
-
end
|
557
|
-
end
|
558
|
-
END
|
559
|
-
end
|
560
|
-
|
561
|
-
let(:syntaxes) { :expect }
|
562
|
-
|
563
|
-
let(:expected_source) do
|
564
|
-
<<-END
|
565
|
-
RSpec.configure do |config|
|
566
|
-
config.#{framework_block_method} :rspec do |c|
|
567
|
-
c.syntax = :expect
|
568
|
-
end
|
569
|
-
end
|
570
|
-
END
|
571
|
-
end
|
572
|
-
|
573
|
-
it 'adds #syntax= statement' do
|
574
|
-
rewritten_source.should == expected_source
|
575
|
-
end
|
576
|
-
end
|
577
|
-
|
578
|
-
context "when ##{framework_block_method} block does not exist" do
|
579
|
-
let(:source) do
|
580
|
-
<<-END
|
581
|
-
RSpec.configure do |config|
|
582
|
-
end
|
583
|
-
END
|
584
|
-
end
|
585
|
-
|
586
|
-
let(:syntaxes) { :expect }
|
587
|
-
|
588
|
-
let(:expected_source) do
|
589
|
-
<<-END
|
590
|
-
RSpec.configure do |config|
|
591
|
-
config.#{framework_block_method} :rspec do |#{block_arg_name}|
|
592
|
-
#{block_arg_name}.syntax = :expect
|
593
|
-
end
|
594
|
-
end
|
595
|
-
END
|
596
|
-
end
|
597
|
-
|
598
|
-
it "adds ##{framework_block_method} block " \
|
599
|
-
'and #syntax= statement' do
|
600
|
-
rewritten_source.should == expected_source
|
601
|
-
end
|
602
|
-
|
603
|
-
context 'when there are already some configurations' do
|
604
|
-
let(:source) do
|
605
|
-
<<-END
|
606
|
-
RSpec.configure do |config|
|
607
|
-
config.foo = 1
|
608
|
-
end
|
609
|
-
END
|
610
|
-
end
|
611
|
-
|
612
|
-
let(:syntaxes) { :expect }
|
613
|
-
|
614
|
-
let(:expected_source) do
|
615
|
-
<<-END
|
616
|
-
RSpec.configure do |config|
|
617
|
-
config.foo = 1
|
618
|
-
|
619
|
-
config.#{framework_block_method} :rspec do |#{block_arg_name}|
|
620
|
-
#{block_arg_name}.syntax = :expect
|
621
|
-
end
|
622
|
-
end
|
623
|
-
END
|
624
|
-
end
|
625
|
-
|
626
|
-
it 'adds the block after a blank line' do
|
627
|
-
rewritten_source.should == expected_source
|
628
|
-
end
|
629
|
-
end
|
630
|
-
end
|
631
|
-
end
|
632
|
-
end
|
633
|
-
|
634
|
-
describe '#expectations' do
|
635
|
-
subject { rspec_configure.expectations }
|
636
|
-
|
637
|
-
include_examples '#syntaxes', :expect_with
|
638
|
-
include_examples '#syntaxes=', :expect_with, :expectations
|
639
|
-
end
|
640
|
-
|
641
|
-
describe '#mocks' do
|
642
|
-
subject(:mocks) { rspec_configure.mocks }
|
643
|
-
|
644
|
-
include_examples '#syntaxes', :mock_with
|
645
|
-
include_examples '#syntaxes=', :mock_with, :mocks
|
646
|
-
|
647
|
-
describe '#yield_receiver_to_any_instance_implementation_blocks=' do
|
648
|
-
before do
|
649
|
-
mocks.yield_receiver_to_any_instance_implementation_blocks = value
|
650
|
-
end
|
651
|
-
|
652
|
-
context 'when #mock_with { #yield_receiver_to_any_instance_implementation_blocks= } exists' do
|
653
|
-
let(:source) do
|
654
|
-
<<-END
|
655
|
-
RSpec.configure do |config|
|
656
|
-
config.mock_with :rspec do |c|
|
657
|
-
c.yield_receiver_to_any_instance_implementation_blocks = foo
|
658
|
-
end
|
659
|
-
end
|
660
|
-
END
|
661
|
-
end
|
662
|
-
|
663
|
-
context 'when true is passed' do
|
664
|
-
let(:value) { true }
|
665
|
-
|
666
|
-
let(:expected_source) do
|
667
|
-
<<-END
|
668
|
-
RSpec.configure do |config|
|
669
|
-
config.mock_with :rspec do |c|
|
670
|
-
c.yield_receiver_to_any_instance_implementation_blocks = true
|
671
|
-
end
|
672
|
-
end
|
673
|
-
END
|
674
|
-
end
|
675
|
-
|
676
|
-
it 'rewrites the setter argument to `true`' do
|
677
|
-
rewritten_source.should == expected_source
|
678
|
-
end
|
679
|
-
|
680
|
-
# rubocop:disable LineLength
|
681
|
-
it 'adds record of modification ' \
|
682
|
-
'`RSpec.configure { |c| c.mock_with :rspec { |m| m.yield_receiver_to_any_instance_implementation_blocks = foo } }` ->' \
|
683
|
-
'`RSpec.configure { |c| c.mock_with :rspec { |m| m.yield_receiver_to_any_instance_implementation_blocks = true } }`' do
|
684
|
-
record.type.should == :modification
|
685
|
-
record.old_syntax.should == 'RSpec.configure { |c| c.mock_with :rspec { |m| m.yield_receiver_to_any_instance_implementation_blocks = foo } }'
|
686
|
-
record.new_syntax.should == 'RSpec.configure { |c| c.mock_with :rspec { |m| m.yield_receiver_to_any_instance_implementation_blocks = true } }'
|
687
|
-
end
|
688
|
-
# rubocop:enable LineLength
|
689
|
-
end
|
690
|
-
|
691
|
-
context 'when false is passed' do
|
692
|
-
let(:value) { false }
|
693
|
-
|
694
|
-
let(:expected_source) do
|
695
|
-
<<-END
|
696
|
-
RSpec.configure do |config|
|
697
|
-
config.mock_with :rspec do |c|
|
698
|
-
c.yield_receiver_to_any_instance_implementation_blocks = false
|
699
|
-
end
|
700
|
-
end
|
701
|
-
END
|
702
|
-
end
|
703
|
-
|
704
|
-
it 'rewrites the setter argument to `false`' do
|
705
|
-
rewritten_source.should == expected_source
|
706
|
-
end
|
707
|
-
end
|
708
|
-
end
|
709
|
-
|
710
|
-
context 'when #mock_with { #yield_receiver_to_any_instance_implementation_blocks= } does not exist' do
|
711
|
-
let(:source) do
|
712
|
-
<<-END
|
713
|
-
RSpec.configure do |config|
|
714
|
-
config.mock_with :rspec do |c|
|
715
|
-
end
|
716
|
-
end
|
717
|
-
END
|
718
|
-
end
|
719
|
-
|
720
|
-
let(:value) { true }
|
721
|
-
|
722
|
-
let(:expected_source) do
|
723
|
-
<<-END
|
724
|
-
RSpec.configure do |config|
|
725
|
-
config.mock_with :rspec do |c|
|
726
|
-
# In RSpec 3, `any_instance` implementation blocks will be yielded the receiving
|
727
|
-
# instance as the first block argument to allow the implementation block to use
|
728
|
-
# the state of the receiver.
|
729
|
-
# In RSpec 2.99, to maintain compatibility with RSpec 3 you need to either set
|
730
|
-
# this config option to `false` OR set this to `true` and update your
|
731
|
-
# `any_instance` implementation blocks to account for the first block argument
|
732
|
-
# being the receiving instance.
|
733
|
-
c.yield_receiver_to_any_instance_implementation_blocks = true
|
734
|
-
end
|
735
|
-
end
|
736
|
-
END
|
737
|
-
end
|
738
|
-
|
739
|
-
it 'adds #yield_receiver_to_any_instance_implementation_blocks= statement along with comment' do
|
740
|
-
rewritten_source.should == expected_source
|
741
|
-
end
|
742
|
-
|
743
|
-
# rubocop:disable LineLength
|
744
|
-
it 'adds record of addition ' \
|
745
|
-
'`RSpec.configure { |c| c.mock_with :rspec { |m| m.yield_receiver_to_any_instance_implementation_blocks = true } }`' do
|
746
|
-
record.type.should == :addition
|
747
|
-
record.new_syntax.should == 'RSpec.configure { |c| c.mock_with :rspec { |m| m.yield_receiver_to_any_instance_implementation_blocks = true } }'
|
748
|
-
end
|
749
|
-
# rubocop:enable LineLength
|
750
|
-
end
|
751
|
-
|
752
|
-
context 'when #mock_with block does not exist' do
|
753
|
-
let(:source) do
|
754
|
-
<<-END
|
755
|
-
RSpec.configure do |config|
|
756
|
-
end
|
757
|
-
END
|
758
|
-
end
|
759
|
-
|
760
|
-
let(:value) { true }
|
761
|
-
|
762
|
-
let(:expected_source) do
|
763
|
-
<<-END
|
764
|
-
RSpec.configure do |config|
|
765
|
-
config.mock_with :rspec do |mocks|
|
766
|
-
# In RSpec 3, `any_instance` implementation blocks will be yielded the receiving
|
767
|
-
# instance as the first block argument to allow the implementation block to use
|
768
|
-
# the state of the receiver.
|
769
|
-
# In RSpec 2.99, to maintain compatibility with RSpec 3 you need to either set
|
770
|
-
# this config option to `false` OR set this to `true` and update your
|
771
|
-
# `any_instance` implementation blocks to account for the first block argument
|
772
|
-
# being the receiving instance.
|
773
|
-
mocks.yield_receiver_to_any_instance_implementation_blocks = true
|
774
|
-
end
|
775
|
-
end
|
776
|
-
END
|
777
|
-
end
|
778
|
-
|
779
|
-
it 'adds #mock_with block ' \
|
780
|
-
'and #yield_receiver_to_any_instance_implementation_blocks= statement along with comment' do
|
781
|
-
rewritten_source.should == expected_source
|
782
|
-
end
|
783
|
-
|
784
|
-
# rubocop:disable LineLength
|
785
|
-
it 'adds record of addition ' \
|
786
|
-
'`RSpec.configure { |c| c.mock_with :rspec { |m| m.yield_receiver_to_any_instance_implementation_blocks = true } }`' do
|
787
|
-
record.type.should == :addition
|
788
|
-
record.new_syntax.should == 'RSpec.configure { |c| c.mock_with :rspec { |m| m.yield_receiver_to_any_instance_implementation_blocks = true } }'
|
789
|
-
end
|
790
|
-
# rubocop:enable LineLength
|
791
|
-
|
792
|
-
context "when RSpec.configure's block argument name is `mocks`" do
|
793
|
-
let(:source) do
|
794
|
-
<<-END
|
795
|
-
RSpec.configure do |mocks|
|
796
|
-
end
|
797
|
-
END
|
798
|
-
end
|
799
|
-
|
800
|
-
let(:expected_source) do
|
801
|
-
<<-END
|
802
|
-
RSpec.configure do |mocks|
|
803
|
-
mocks.mock_with :rspec do |config|
|
804
|
-
# In RSpec 3, `any_instance` implementation blocks will be yielded the receiving
|
805
|
-
# instance as the first block argument to allow the implementation block to use
|
806
|
-
# the state of the receiver.
|
807
|
-
# In RSpec 2.99, to maintain compatibility with RSpec 3 you need to either set
|
808
|
-
# this config option to `false` OR set this to `true` and update your
|
809
|
-
# `any_instance` implementation blocks to account for the first block argument
|
810
|
-
# being the receiving instance.
|
811
|
-
config.yield_receiver_to_any_instance_implementation_blocks = true
|
812
|
-
end
|
813
|
-
end
|
814
|
-
END
|
815
|
-
end
|
816
|
-
|
817
|
-
it 'defines #mock_with block argument name as `config`' do
|
818
|
-
rewritten_source.should == expected_source
|
819
|
-
end
|
820
|
-
end
|
821
|
-
end
|
822
|
-
end
|
823
|
-
end
|
824
|
-
|
825
|
-
context 'when multiple configurations are added' do
|
826
|
-
before do
|
827
|
-
rspec_configure.expose_dsl_globally = true
|
828
|
-
rspec_configure.mocks.yield_receiver_to_any_instance_implementation_blocks = false
|
829
|
-
end
|
830
|
-
|
831
|
-
let(:source) do
|
832
|
-
<<-END
|
833
|
-
RSpec.configure do |config|
|
834
|
-
end
|
835
|
-
END
|
836
|
-
end
|
837
|
-
|
838
|
-
let(:expected_source) do
|
839
|
-
<<-END
|
840
|
-
RSpec.configure do |config|
|
841
|
-
# Setting this config option `false` removes rspec-core's monkey patching of the
|
842
|
-
# top level methods like `describe`, `shared_examples_for` and `shared_context`
|
843
|
-
# on `main` and `Module`. The methods are always available through the `RSpec`
|
844
|
-
# module like `RSpec.describe` regardless of this setting.
|
845
|
-
# For backwards compatibility this defaults to `true`.
|
846
|
-
#
|
847
|
-
# https://relishapp.com/rspec/rspec-core/v/3-0/docs/configuration/global-namespace-dsl
|
848
|
-
config.expose_dsl_globally = true
|
849
|
-
|
850
|
-
config.mock_with :rspec do |mocks|
|
851
|
-
# In RSpec 3, `any_instance` implementation blocks will be yielded the receiving
|
852
|
-
# instance as the first block argument to allow the implementation block to use
|
853
|
-
# the state of the receiver.
|
854
|
-
# In RSpec 2.99, to maintain compatibility with RSpec 3 you need to either set
|
855
|
-
# this config option to `false` OR set this to `true` and update your
|
856
|
-
# `any_instance` implementation blocks to account for the first block argument
|
857
|
-
# being the receiving instance.
|
858
|
-
mocks.yield_receiver_to_any_instance_implementation_blocks = false
|
859
|
-
end
|
860
|
-
end
|
861
|
-
END
|
862
|
-
end
|
863
|
-
|
864
|
-
it 'adds them properly' do
|
865
|
-
rewritten_source.should == expected_source
|
866
|
-
end
|
867
|
-
end
|
868
|
-
end
|
869
|
-
end
|
870
|
-
end
|