transpec 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -7
- data/CHANGELOG.md +4 -0
- data/README.md +58 -12
- data/README.md.erb +58 -12
- data/lib/transpec/cli.rb +10 -12
- data/lib/transpec/context.rb +98 -49
- data/lib/transpec/syntax/method_stub.rb +1 -1
- data/lib/transpec/syntax/rspec_configure.rb +21 -20
- data/lib/transpec/syntax/should.rb +1 -1
- data/lib/transpec/syntax/should_receive.rb +1 -1
- data/lib/transpec/version.rb +1 -1
- data/spec/.rubocop.yml +4 -0
- data/spec/support/shared_context.rb +1 -1
- data/spec/transpec/context_spec.rb +497 -109
- data/spec/transpec/syntax/method_stub_spec.rb +2 -3
- data/spec/transpec/syntax/should_receive_spec.rb +2 -2
- data/spec/transpec/syntax/should_spec.rb +1 -1
- data/tasks/demo.rake +23 -0
- data/tasks/lib/transpec_demo.rb +51 -0
- data/tasks/lib/transpec_test.rb +148 -0
- data/tasks/test.rake +3 -151
- data/transpec.gemspec +1 -1
- metadata +7 -4
@@ -22,7 +22,7 @@ module Transpec
|
|
22
22
|
|
23
23
|
fail 'Already replaced deprecated method, cannot allowize.' if @replaced_deprecated_method
|
24
24
|
|
25
|
-
unless context.
|
25
|
+
unless context.allow_to_receive_available?
|
26
26
|
fail InvalidContextError.new(selector_range, "##{method_name}", '#allow')
|
27
27
|
end
|
28
28
|
|
@@ -44,30 +44,31 @@ module Transpec
|
|
44
44
|
def syntaxes_node
|
45
45
|
return nil unless framework_block_node
|
46
46
|
|
47
|
-
@syntaxes_node
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
47
|
+
return @syntaxes_node if instance_variable_defined?(:@syntaxes_node)
|
48
|
+
|
49
|
+
framework_config_variable_name = first_block_arg_name(framework_block_node)
|
50
|
+
|
51
|
+
framework_block_node.each_descendent_node do |node|
|
52
|
+
next unless node.type == :send
|
53
|
+
receiver_node, method_name, arg_node, *_ = *node
|
54
|
+
next unless receiver_node == s(:lvar, framework_config_variable_name)
|
55
|
+
next unless method_name == :syntax=
|
56
|
+
return @syntaxes_node = arg_node
|
57
57
|
end
|
58
|
+
|
59
|
+
@syntaxes_node = nil
|
58
60
|
end
|
59
61
|
|
60
62
|
def framework_block_node
|
61
|
-
@framework_block_node
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
63
|
+
return @framework_block_node if instance_variable_defined?(:@framework_block_node)
|
64
|
+
|
65
|
+
@framework_block_node = @rspec_configure_node.each_descendent_node.find do |node|
|
66
|
+
next unless node.type == :block
|
67
|
+
send_node = node.children.first
|
68
|
+
receiver_node, method_name, *_ = *send_node
|
69
|
+
next unless receiver_node == s(:lvar, rspec_configure_block_arg_name)
|
70
|
+
method_name == @framework_config_method_name
|
71
|
+
# TODO: Check expectation framework.
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
@@ -15,7 +15,7 @@ module Transpec
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def expectize!(negative_form = 'not_to', parenthesize_matcher_arg = true)
|
18
|
-
unless context.
|
18
|
+
unless context.expect_to_matcher_available?
|
19
19
|
fail InvalidContextError.new(selector_range, "##{method_name}", '#expect')
|
20
20
|
end
|
21
21
|
|
data/lib/transpec/version.rb
CHANGED
data/spec/.rubocop.yml
CHANGED
@@ -28,7 +28,7 @@ end
|
|
28
28
|
|
29
29
|
shared_context 'should object' do
|
30
30
|
let(:should_object) do
|
31
|
-
Transpec::AST::Scanner.scan(ast) do |node, ancestor_nodes
|
31
|
+
Transpec::AST::Scanner.scan(ast) do |node, ancestor_nodes|
|
32
32
|
next unless Transpec::Syntax::Should.target_node?(node)
|
33
33
|
return Transpec::Syntax::Should.new(
|
34
34
|
node,
|
@@ -5,30 +5,32 @@ require 'transpec/context'
|
|
5
5
|
|
6
6
|
module Transpec
|
7
7
|
describe Context do
|
8
|
+
include ::AST::Sexp
|
8
9
|
include_context 'parsed objects'
|
10
|
+
include_context 'isolated environment'
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
describe '#scopes' do
|
13
|
+
def node_id(node)
|
14
|
+
id = node.type.to_s
|
15
|
+
node.children.each do |child|
|
16
|
+
break if child.is_a?(Parser::AST::Node)
|
17
|
+
id << " #{child.inspect}"
|
18
|
+
end
|
19
|
+
id
|
15
20
|
end
|
16
|
-
id
|
17
|
-
end
|
18
21
|
|
19
|
-
describe '#scopes' do
|
20
22
|
let(:source) do
|
21
23
|
<<-END
|
22
|
-
|
24
|
+
top_level
|
23
25
|
|
24
26
|
RSpec.configure do |config|
|
25
27
|
config.before do
|
26
|
-
|
28
|
+
in_before
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
32
|
module SomeModule
|
31
|
-
|
33
|
+
in_module
|
32
34
|
|
33
35
|
describe 'something' do
|
34
36
|
def some_method(some_arg)
|
@@ -36,9 +38,13 @@ module Transpec
|
|
36
38
|
end
|
37
39
|
|
38
40
|
it 'is 1' do
|
39
|
-
|
41
|
+
in_example
|
40
42
|
end
|
41
43
|
end
|
44
|
+
|
45
|
+
1.times do
|
46
|
+
in_normal_block
|
47
|
+
end
|
42
48
|
end
|
43
49
|
END
|
44
50
|
end
|
@@ -47,15 +53,15 @@ module Transpec
|
|
47
53
|
AST::Scanner.scan(ast) do |node, ancestor_nodes|
|
48
54
|
expected_scopes = begin
|
49
55
|
case node_id(node)
|
50
|
-
when '
|
56
|
+
when 'send nil :top_level'
|
51
57
|
[]
|
52
|
-
when 'send nil :
|
53
|
-
[:rspec_configure, :
|
58
|
+
when 'send nil :in_before'
|
59
|
+
[:rspec_configure, :each_before_after]
|
54
60
|
when 'module'
|
55
61
|
[]
|
56
62
|
when 'const nil :SomeModule'
|
57
63
|
# [:module] # TODO
|
58
|
-
when '
|
64
|
+
when 'send nil :in_module'
|
59
65
|
[:module]
|
60
66
|
when 'send nil :describe'
|
61
67
|
# [:module] # TODO
|
@@ -69,8 +75,10 @@ module Transpec
|
|
69
75
|
# [:module, :example_group] # TODO
|
70
76
|
when 'str "is 1"'
|
71
77
|
# [:module, :example_group] # TODO
|
72
|
-
when 'send nil :
|
73
|
-
[:module, :example_group, :
|
78
|
+
when 'send nil :in_example'
|
79
|
+
[:module, :example_group, :example]
|
80
|
+
when 'send nil :in_normal_block'
|
81
|
+
[:module]
|
74
82
|
end
|
75
83
|
end
|
76
84
|
|
@@ -87,170 +95,550 @@ module Transpec
|
|
87
95
|
end
|
88
96
|
end
|
89
97
|
|
90
|
-
|
98
|
+
shared_examples 'context inspection methods' do
|
99
|
+
let(:context_object) do
|
100
|
+
AST::Scanner.scan(ast) do |node, ancestor_nodes|
|
101
|
+
next unless node == s(:send, nil, :target)
|
102
|
+
return Context.new(ancestor_nodes)
|
103
|
+
end
|
104
|
+
|
105
|
+
fail 'Target node not found!'
|
106
|
+
end
|
107
|
+
|
108
|
+
def eval_with_rspec_in_context(eval_source)
|
109
|
+
result_path = 'result'
|
110
|
+
|
111
|
+
helper_source = <<-END
|
112
|
+
def target
|
113
|
+
File.open(#{result_path.inspect}, 'w') do |file|
|
114
|
+
Marshal.dump(#{eval_source}, file)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
END
|
118
|
+
|
119
|
+
source_path = 'spec.rb'
|
120
|
+
File.write(source_path, helper_source + source)
|
121
|
+
|
122
|
+
`rspec #{source_path}`
|
123
|
+
|
124
|
+
Marshal.load(File.read(result_path))
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#non_monkey_patch_expectation_available?' do
|
128
|
+
subject { context_object.non_monkey_patch_expectation_available? }
|
129
|
+
|
130
|
+
let(:expected) do
|
131
|
+
eval_with_rspec_in_context('respond_to?(:expect)')
|
132
|
+
end
|
133
|
+
|
134
|
+
it { should == expected }
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#non_monkey_patch_mock_available?' do
|
138
|
+
subject { context_object.non_monkey_patch_mock_available? }
|
139
|
+
|
140
|
+
let(:expected) do
|
141
|
+
eval_with_rspec_in_context('respond_to?(:allow) && respond_to?(:receive)')
|
142
|
+
end
|
143
|
+
|
144
|
+
it { should == expected }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'when in top level' do
|
91
149
|
let(:source) do
|
92
|
-
|
93
|
-
|
150
|
+
'target'
|
151
|
+
end
|
152
|
+
|
153
|
+
include_examples 'context inspection methods'
|
154
|
+
end
|
94
155
|
|
156
|
+
context 'when in an instance method in top level' do
|
157
|
+
let(:source) do
|
158
|
+
<<-END
|
95
159
|
def some_method
|
96
|
-
|
160
|
+
target
|
161
|
+
end
|
162
|
+
|
163
|
+
describe('test') { example { target } }
|
164
|
+
END
|
165
|
+
end
|
166
|
+
|
167
|
+
include_examples 'context inspection methods'
|
168
|
+
end
|
97
169
|
|
170
|
+
context 'when in a block in an instance method in top level' do
|
171
|
+
let(:source) do
|
172
|
+
<<-END
|
173
|
+
def some_method
|
98
174
|
1.times do
|
99
|
-
|
175
|
+
target
|
100
176
|
end
|
101
177
|
end
|
102
178
|
|
179
|
+
describe('test') { example { target } }
|
180
|
+
END
|
181
|
+
end
|
182
|
+
|
183
|
+
include_examples 'context inspection methods'
|
184
|
+
end
|
185
|
+
|
186
|
+
context 'when in #describe block in top level' do
|
187
|
+
let(:source) do
|
188
|
+
<<-END
|
103
189
|
describe 'foo' do
|
104
|
-
|
190
|
+
target
|
191
|
+
end
|
192
|
+
END
|
193
|
+
end
|
194
|
+
|
195
|
+
include_examples 'context inspection methods'
|
196
|
+
end
|
105
197
|
|
198
|
+
context 'when in an instance method in #describe block in top level' do
|
199
|
+
let(:source) do
|
200
|
+
<<-END
|
201
|
+
describe 'foo' do
|
106
202
|
def some_method
|
107
|
-
|
203
|
+
target
|
108
204
|
end
|
109
205
|
|
206
|
+
example { some_method }
|
207
|
+
end
|
208
|
+
END
|
209
|
+
end
|
210
|
+
|
211
|
+
include_examples 'context inspection methods'
|
212
|
+
end
|
213
|
+
|
214
|
+
context 'when in #it block in #describe block in top level' do
|
215
|
+
let(:source) do
|
216
|
+
<<-END
|
217
|
+
describe 'foo' do
|
110
218
|
it 'is an example' do
|
111
|
-
|
219
|
+
target
|
220
|
+
end
|
221
|
+
end
|
222
|
+
END
|
223
|
+
end
|
112
224
|
|
113
|
-
|
114
|
-
|
225
|
+
include_examples 'context inspection methods'
|
226
|
+
end
|
115
227
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
228
|
+
context 'when in #before block in #describe block in top level' do
|
229
|
+
let(:source) do
|
230
|
+
<<-END
|
231
|
+
describe 'foo' do
|
232
|
+
before do
|
233
|
+
target
|
120
234
|
end
|
235
|
+
|
236
|
+
example { }
|
121
237
|
end
|
238
|
+
END
|
239
|
+
end
|
122
240
|
|
123
|
-
|
124
|
-
|
125
|
-
describe_module
|
241
|
+
include_examples 'context inspection methods'
|
242
|
+
end
|
126
243
|
|
127
|
-
|
128
|
-
|
129
|
-
|
244
|
+
context 'when in #before(:each) block in #describe block in top level' do
|
245
|
+
let(:source) do
|
246
|
+
<<-END
|
247
|
+
describe 'foo' do
|
248
|
+
before(:each) do
|
249
|
+
target
|
250
|
+
end
|
130
251
|
|
131
|
-
|
132
|
-
|
133
|
-
|
252
|
+
example { }
|
253
|
+
end
|
254
|
+
END
|
255
|
+
end
|
256
|
+
|
257
|
+
include_examples 'context inspection methods'
|
258
|
+
end
|
259
|
+
|
260
|
+
context 'when in #before(:all) block in #describe block in top level' do
|
261
|
+
let(:source) do
|
262
|
+
<<-END
|
263
|
+
describe 'foo' do
|
264
|
+
before(:all) do
|
265
|
+
target
|
134
266
|
end
|
267
|
+
|
268
|
+
example { }
|
135
269
|
end
|
270
|
+
END
|
271
|
+
end
|
136
272
|
|
137
|
-
|
138
|
-
|
139
|
-
|
273
|
+
include_examples 'context inspection methods'
|
274
|
+
end
|
275
|
+
|
276
|
+
context 'when in #after block in #describe block in top level' do
|
277
|
+
let(:source) do
|
278
|
+
<<-END
|
279
|
+
describe 'foo' do
|
280
|
+
after do
|
281
|
+
target
|
140
282
|
end
|
283
|
+
|
284
|
+
example { }
|
141
285
|
end
|
286
|
+
END
|
287
|
+
end
|
142
288
|
|
143
|
-
|
144
|
-
|
145
|
-
|
289
|
+
include_examples 'context inspection methods'
|
290
|
+
end
|
291
|
+
|
292
|
+
context 'when in #after(:each) block in #describe block in top level' do
|
293
|
+
let(:source) do
|
294
|
+
<<-END
|
295
|
+
describe 'foo' do
|
296
|
+
after(:each) do
|
297
|
+
target
|
146
298
|
end
|
299
|
+
|
300
|
+
example { }
|
147
301
|
end
|
302
|
+
END
|
303
|
+
end
|
148
304
|
|
149
|
-
|
150
|
-
|
305
|
+
include_examples 'context inspection methods'
|
306
|
+
end
|
151
307
|
|
152
|
-
|
153
|
-
|
308
|
+
context 'when in #after(:all) block in #describe block in top level' do
|
309
|
+
let(:source) do
|
310
|
+
<<-END
|
311
|
+
describe 'foo' do
|
312
|
+
after(:all) do
|
313
|
+
target
|
154
314
|
end
|
155
315
|
|
156
|
-
|
157
|
-
|
316
|
+
example { }
|
317
|
+
end
|
318
|
+
END
|
319
|
+
end
|
320
|
+
|
321
|
+
include_examples 'context inspection methods'
|
322
|
+
end
|
323
|
+
|
324
|
+
context 'when in #around block in #describe block in top level' do
|
325
|
+
let(:source) do
|
326
|
+
<<-END
|
327
|
+
describe 'foo' do
|
328
|
+
around do
|
329
|
+
target
|
158
330
|
end
|
331
|
+
|
332
|
+
example { }
|
159
333
|
end
|
160
334
|
END
|
161
335
|
end
|
162
336
|
|
163
|
-
|
164
|
-
|
165
|
-
next unless node_id(node) == target_node_id
|
166
|
-
return Context.new(ancestor_nodes)
|
167
|
-
end
|
337
|
+
include_examples 'context inspection methods'
|
338
|
+
end
|
168
339
|
|
169
|
-
|
340
|
+
context 'when in #subject block in #describe block in top level' do
|
341
|
+
let(:source) do
|
342
|
+
<<-END
|
343
|
+
describe 'foo' do
|
344
|
+
subject do
|
345
|
+
target
|
346
|
+
end
|
347
|
+
|
348
|
+
example { subject }
|
349
|
+
end
|
350
|
+
END
|
351
|
+
end
|
352
|
+
|
353
|
+
include_examples 'context inspection methods'
|
354
|
+
end
|
355
|
+
|
356
|
+
context 'when in #subject! block in #describe block in top level' do
|
357
|
+
let(:source) do
|
358
|
+
<<-END
|
359
|
+
describe 'foo' do
|
360
|
+
subject! do
|
361
|
+
target
|
362
|
+
end
|
363
|
+
|
364
|
+
example { subject }
|
365
|
+
end
|
366
|
+
END
|
170
367
|
end
|
171
368
|
|
172
|
-
|
369
|
+
include_examples 'context inspection methods'
|
370
|
+
end
|
371
|
+
|
372
|
+
context 'when in #let block in #describe block in top level' do
|
373
|
+
let(:source) do
|
374
|
+
<<-END
|
375
|
+
describe 'foo' do
|
376
|
+
let(:something) do
|
377
|
+
target
|
378
|
+
end
|
173
379
|
|
174
|
-
|
175
|
-
|
176
|
-
|
380
|
+
example { something }
|
381
|
+
end
|
382
|
+
END
|
177
383
|
end
|
178
384
|
|
179
|
-
|
180
|
-
|
181
|
-
|
385
|
+
include_examples 'context inspection methods'
|
386
|
+
end
|
387
|
+
|
388
|
+
context 'when in #let! block in #describe block in top level' do
|
389
|
+
let(:source) do
|
390
|
+
<<-END
|
391
|
+
describe 'foo' do
|
392
|
+
let!(:something) do
|
393
|
+
target
|
394
|
+
end
|
395
|
+
|
396
|
+
example { something }
|
397
|
+
end
|
398
|
+
END
|
182
399
|
end
|
183
400
|
|
184
|
-
|
185
|
-
|
186
|
-
|
401
|
+
include_examples 'context inspection methods'
|
402
|
+
end
|
403
|
+
|
404
|
+
context 'when in any other block in #describe block in top level' do
|
405
|
+
let(:source) do
|
406
|
+
<<-END
|
407
|
+
describe 'foo' do
|
408
|
+
1.times do
|
409
|
+
target
|
410
|
+
end
|
411
|
+
|
412
|
+
example { }
|
413
|
+
end
|
414
|
+
END
|
187
415
|
end
|
188
416
|
|
189
|
-
|
190
|
-
|
191
|
-
|
417
|
+
include_examples 'context inspection methods'
|
418
|
+
end
|
419
|
+
|
420
|
+
context 'when in #before block in singleton method with self in #describe block in top level' do
|
421
|
+
let(:source) do
|
422
|
+
<<-END
|
423
|
+
describe 'foo' do
|
424
|
+
def self.some_method
|
425
|
+
before do
|
426
|
+
target
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
some_method
|
431
|
+
|
432
|
+
example { something }
|
433
|
+
end
|
434
|
+
END
|
192
435
|
end
|
193
436
|
|
194
|
-
|
195
|
-
|
196
|
-
|
437
|
+
include_examples 'context inspection methods'
|
438
|
+
end
|
439
|
+
|
440
|
+
context 'when in #before block in singleton method with other object in #describe block in top level' do
|
441
|
+
let(:source) do
|
442
|
+
<<-END
|
443
|
+
describe 'foo' do
|
444
|
+
some_object = 'some object'
|
445
|
+
|
446
|
+
def some_object.before
|
447
|
+
yield
|
448
|
+
end
|
449
|
+
|
450
|
+
def some_object.some_method
|
451
|
+
before do
|
452
|
+
target
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
some_object.some_method
|
457
|
+
end
|
458
|
+
END
|
197
459
|
end
|
198
460
|
|
199
|
-
|
200
|
-
|
201
|
-
|
461
|
+
include_examples 'context inspection methods'
|
462
|
+
end
|
463
|
+
|
464
|
+
context 'when in a class in a block in #describe block' do
|
465
|
+
let(:source) do
|
466
|
+
<<-END
|
467
|
+
describe 'foo' do
|
468
|
+
it 'is an example' do
|
469
|
+
class SomeClass
|
470
|
+
target
|
471
|
+
end
|
472
|
+
end
|
473
|
+
end
|
474
|
+
END
|
202
475
|
end
|
203
476
|
|
204
|
-
|
205
|
-
|
206
|
-
|
477
|
+
include_examples 'context inspection methods'
|
478
|
+
end
|
479
|
+
|
480
|
+
context 'when in an instance method in a class in a block in #describe block' do
|
481
|
+
let(:source) do
|
482
|
+
<<-END
|
483
|
+
describe 'foo' do
|
484
|
+
it 'is an example' do
|
485
|
+
class SomeClass
|
486
|
+
def some_method
|
487
|
+
target
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
SomeClass.new.some_method
|
492
|
+
end
|
493
|
+
end
|
494
|
+
END
|
207
495
|
end
|
208
496
|
|
209
|
-
|
210
|
-
|
211
|
-
|
497
|
+
include_examples 'context inspection methods'
|
498
|
+
end
|
499
|
+
|
500
|
+
context 'when in #describe block in a module' do
|
501
|
+
let(:source) do
|
502
|
+
<<-END
|
503
|
+
module SomeModule
|
504
|
+
describe 'foo' do
|
505
|
+
target
|
506
|
+
end
|
507
|
+
end
|
508
|
+
END
|
212
509
|
end
|
213
510
|
|
214
|
-
|
215
|
-
|
216
|
-
|
511
|
+
include_examples 'context inspection methods'
|
512
|
+
end
|
513
|
+
|
514
|
+
context 'when in an instance method in #describe block in a module' do
|
515
|
+
let(:source) do
|
516
|
+
<<-END
|
517
|
+
module SomeModule
|
518
|
+
describe 'foo' do
|
519
|
+
def some_method
|
520
|
+
target
|
521
|
+
end
|
522
|
+
|
523
|
+
example { some_method }
|
524
|
+
end
|
525
|
+
end
|
526
|
+
END
|
217
527
|
end
|
218
528
|
|
219
|
-
|
220
|
-
|
221
|
-
|
529
|
+
include_examples 'context inspection methods'
|
530
|
+
end
|
531
|
+
|
532
|
+
context 'when in a block in #describe block in a module' do
|
533
|
+
let(:source) do
|
534
|
+
<<-END
|
535
|
+
module SomeModule
|
536
|
+
describe 'foo' do
|
537
|
+
it 'is an example' do
|
538
|
+
target
|
539
|
+
end
|
540
|
+
end
|
541
|
+
end
|
542
|
+
END
|
222
543
|
end
|
223
544
|
|
224
|
-
|
225
|
-
|
226
|
-
|
545
|
+
include_examples 'context inspection methods'
|
546
|
+
end
|
547
|
+
|
548
|
+
context 'when in an instance method in a module' do
|
549
|
+
let(:source) do
|
550
|
+
<<-END
|
551
|
+
module SomeModule
|
552
|
+
def some_method
|
553
|
+
target
|
554
|
+
end
|
555
|
+
end
|
556
|
+
|
557
|
+
describe 'test' do
|
558
|
+
include SomeModule
|
559
|
+
example { some_method }
|
560
|
+
end
|
561
|
+
END
|
227
562
|
end
|
228
563
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
564
|
+
# Instance methods of module can be used by `include SomeModule` in #describe block.
|
565
|
+
include_examples 'context inspection methods'
|
566
|
+
end
|
567
|
+
|
568
|
+
context 'when in an instance method in a class' do
|
569
|
+
let(:source) do
|
570
|
+
<<-END
|
571
|
+
class SomeClass
|
572
|
+
def some_method
|
573
|
+
target
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|
577
|
+
describe 'test' do
|
578
|
+
example { SomeClass.new.some_method }
|
579
|
+
end
|
580
|
+
END
|
233
581
|
end
|
234
582
|
|
235
|
-
|
236
|
-
|
237
|
-
|
583
|
+
include_examples 'context inspection methods'
|
584
|
+
end
|
585
|
+
|
586
|
+
context 'when in RSpec.configure' do
|
587
|
+
let(:source) do
|
588
|
+
<<-END
|
589
|
+
RSpec.configure do |config|
|
590
|
+
target
|
591
|
+
end
|
592
|
+
END
|
238
593
|
end
|
239
594
|
|
240
|
-
|
241
|
-
|
242
|
-
|
595
|
+
include_examples 'context inspection methods'
|
596
|
+
end
|
597
|
+
|
598
|
+
context 'when in #before block in RSpec.configure' do
|
599
|
+
let(:source) do
|
600
|
+
<<-END
|
601
|
+
RSpec.configure do |config|
|
602
|
+
config.before do
|
603
|
+
target
|
604
|
+
end
|
605
|
+
end
|
606
|
+
|
607
|
+
describe('test') { example { } }
|
608
|
+
END
|
243
609
|
end
|
244
610
|
|
245
|
-
|
246
|
-
|
247
|
-
|
611
|
+
include_examples 'context inspection methods'
|
612
|
+
end
|
613
|
+
|
614
|
+
context 'when in a normal block in RSpec.configure' do
|
615
|
+
let(:source) do
|
616
|
+
<<-END
|
617
|
+
RSpec.configure do |config|
|
618
|
+
1.times do
|
619
|
+
target
|
620
|
+
end
|
621
|
+
end
|
622
|
+
END
|
248
623
|
end
|
249
624
|
|
250
|
-
|
251
|
-
|
252
|
-
|
625
|
+
include_examples 'context inspection methods'
|
626
|
+
end
|
627
|
+
|
628
|
+
context 'when in an instance method in RSpec.configure' do
|
629
|
+
let(:source) do
|
630
|
+
<<-END
|
631
|
+
RSpec.configure do |config|
|
632
|
+
def some_method
|
633
|
+
target
|
634
|
+
end
|
635
|
+
end
|
636
|
+
|
637
|
+
describe('test') { example { some_method } }
|
638
|
+
END
|
253
639
|
end
|
640
|
+
|
641
|
+
include_examples 'context inspection methods'
|
254
642
|
end
|
255
643
|
end
|
256
644
|
end
|