transpec 0.0.4 → 0.0.5

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.
@@ -65,16 +65,16 @@ module Transpec
65
65
  context "when it is `subject.#{method}(:method).and_return(value)` form" do
66
66
  let(:source) do
67
67
  <<-END
68
- it 'responds to #foo' do
69
- subject.#{method}(:foo).and_return(value)
68
+ it 'responds to #foo and returns 1' do
69
+ subject.#{method}(:foo).and_return(1)
70
70
  end
71
71
  END
72
72
  end
73
73
 
74
74
  let(:expected_source) do
75
75
  <<-END
76
- it 'responds to #foo' do
77
- allow(subject).to receive(:foo).and_return(value)
76
+ it 'responds to #foo and returns 1' do
77
+ allow(subject).to receive(:foo).and_return(1)
78
78
  end
79
79
  END
80
80
  end
@@ -88,7 +88,7 @@ module Transpec
88
88
  context "when it is `subject.#{method}(:method).and_raise(RuntimeError)` form" do
89
89
  let(:source) do
90
90
  <<-END
91
- it 'responds to #foo' do
91
+ it 'responds to #foo and raises RuntimeError' do
92
92
  subject.#{method}(:foo).and_raise(RuntimeError)
93
93
  end
94
94
  END
@@ -96,7 +96,7 @@ module Transpec
96
96
 
97
97
  let(:expected_source) do
98
98
  <<-END
99
- it 'responds to #foo' do
99
+ it 'responds to #foo and raises RuntimeError' do
100
100
  allow(subject).to receive(:foo).and_raise(RuntimeError)
101
101
  end
102
102
  END
@@ -108,15 +108,15 @@ module Transpec
108
108
  end
109
109
  end
110
110
 
111
- context "when it's statement continues over multi lines" do
111
+ context 'when the statement continues over multi lines' do
112
112
  let(:source) do
113
113
  <<-END
114
- it 'responds to #foo' do
114
+ it 'responds to #foo and returns 1' do
115
115
  subject.#{method}(
116
- :baz
116
+ :foo
117
117
  ).
118
118
  and_return(
119
- 3
119
+ 1
120
120
  )
121
121
  end
122
122
  END
@@ -124,12 +124,12 @@ module Transpec
124
124
 
125
125
  let(:expected_source) do
126
126
  <<-END
127
- it 'responds to #foo' do
127
+ it 'responds to #foo and returns 1' do
128
128
  allow(subject).to receive(
129
- :baz
129
+ :foo
130
130
  ).
131
131
  and_return(
132
- 3
132
+ 1
133
133
  )
134
134
  end
135
135
  END
@@ -190,7 +190,7 @@ module Transpec
190
190
  context "when it is `subject.#{method}(:a_method => a_value, b_method => b_value)` form" do
191
191
  let(:source) do
192
192
  <<-END
193
- it 'responds to #foo and returns 1' do
193
+ it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
194
194
  subject.#{method}(:foo => 1, :bar => 2)
195
195
  end
196
196
  END
@@ -198,7 +198,7 @@ module Transpec
198
198
 
199
199
  let(:expected_source) do
200
200
  <<-END
201
- it 'responds to #foo and returns 1' do
201
+ it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
202
202
  allow(subject).to receive(:foo).and_return(1)
203
203
  allow(subject).to receive(:bar).and_return(2)
204
204
  end
@@ -211,10 +211,10 @@ module Transpec
211
211
  rewritten_source.should == expected_source
212
212
  end
213
213
 
214
- context "when it's statement continues over multi lines" do
214
+ context 'when the statement continues over multi lines' do
215
215
  let(:source) do
216
216
  <<-END
217
- it 'responds to #foo' do
217
+ it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
218
218
  subject
219
219
  .#{method}(
220
220
  :foo => 1,
@@ -226,7 +226,7 @@ module Transpec
226
226
 
227
227
  let(:expected_source) do
228
228
  <<-END
229
- it 'responds to #foo' do
229
+ it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
230
230
  allow(subject)
231
231
  .to receive(:foo).and_return(1)
232
232
  allow(subject)
@@ -382,6 +382,86 @@ module Transpec
382
382
  end
383
383
  end
384
384
  end
385
+
386
+ describe '#any_number_of_times?' do
387
+ subject { method_stub_object.any_number_of_times? }
388
+
389
+ context 'when it is `subject.stub(:method).any_number_of_times` form' do
390
+ let(:source) do
391
+ <<-END
392
+ it 'responds to #foo' do
393
+ subject.stub(:foo).any_number_of_times
394
+ end
395
+ END
396
+ end
397
+
398
+ it { should be_true }
399
+ end
400
+
401
+ context 'when it is `subject.stub(:method).with(arg).any_number_of_times` form' do
402
+ let(:source) do
403
+ <<-END
404
+ it 'responds to #foo with 1' do
405
+ subject.stub(:foo).with(1).any_number_of_times
406
+ end
407
+ END
408
+ end
409
+
410
+ it { should be_true }
411
+ end
412
+
413
+ context 'when it is `subject.stub(:method)` form' do
414
+ let(:source) do
415
+ <<-END
416
+ it 'responds to #foo' do
417
+ subject.stub(:foo)
418
+ end
419
+ END
420
+ end
421
+
422
+ it { should be_false }
423
+ end
424
+ end
425
+
426
+ describe '#remove_any_number_of_times!' do
427
+ context 'when it is `subject.stub(:method).any_number_of_times` form' do
428
+ let(:source) do
429
+ <<-END
430
+ it 'responds to #foo' do
431
+ subject.stub(:foo).any_number_of_times
432
+ end
433
+ END
434
+ end
435
+
436
+ let(:expected_source) do
437
+ <<-END
438
+ it 'responds to #foo' do
439
+ subject.stub(:foo)
440
+ end
441
+ END
442
+ end
443
+
444
+ it 'removes `.any_number_of_times`' do
445
+ method_stub_object.remove_any_number_of_times!
446
+ rewritten_source.should == expected_source
447
+ end
448
+ end
449
+
450
+ context 'when it is `subject.stub(:method)` form' do
451
+ let(:source) do
452
+ <<-END
453
+ it 'responds to #foo' do
454
+ subject.stub(:foo)
455
+ end
456
+ END
457
+ end
458
+
459
+ it 'does nothing' do
460
+ method_stub_object.remove_any_number_of_times!
461
+ rewritten_source.should == source
462
+ end
463
+ end
464
+ end
385
465
  end
386
466
  end
387
467
  end
@@ -113,7 +113,7 @@ module Transpec
113
113
  # arg == 1
114
114
  # }
115
115
  #
116
- context 'when it is `subject.should_receive(:method).with do..end` form' do
116
+ context 'when it is `subject.should_receive(:method).with do .. end` form' do
117
117
  let(:source) do
118
118
  <<-END
119
119
  it 'receives #foo with 1' do
@@ -143,11 +143,11 @@ module Transpec
143
143
  end
144
144
 
145
145
  # If #with take normal arguments, the block won't be used as an argument matcher.
146
- context 'when it is `subject.should_receive(:method).with(:arg) do..end` form' do
146
+ context 'when it is `subject.should_receive(:method).with(arg) do .. end` form' do
147
147
  let(:source) do
148
148
  <<-END
149
149
  it 'receives #foo with 1' do
150
- subject.should_receive(:foo).with(:bar) do |arg|
150
+ subject.should_receive(:foo).with(1) do |arg|
151
151
  do_some_substitute_implementation
152
152
  end
153
153
  subject.foo(1)
@@ -158,7 +158,7 @@ module Transpec
158
158
  let(:expected_source) do
159
159
  <<-END
160
160
  it 'receives #foo with 1' do
161
- expect(subject).to receive(:foo).with(:bar) do |arg|
161
+ expect(subject).to receive(:foo).with(1) do |arg|
162
162
  do_some_substitute_implementation
163
163
  end
164
164
  subject.foo(1)
@@ -166,7 +166,7 @@ module Transpec
166
166
  END
167
167
  end
168
168
 
169
- it 'converts into `expect(subject).to receive(:method) { .. }` form' do
169
+ it 'converts into `expect(subject).to receive(:method).with(arg) do .. end` form' do
170
170
  should_receive_object.expectize!
171
171
  rewritten_source.should == expected_source
172
172
  end
@@ -200,7 +200,7 @@ module Transpec
200
200
  # arg == 1
201
201
  # }.once
202
202
  #
203
- context 'when it is `subject.should_receive(:method) do..end.once` form' do
203
+ context 'when it is `subject.should_receive(:method) do .. end.once` form' do
204
204
  let(:source) do
205
205
  <<-END
206
206
  it 'receives #foo with 1' do
@@ -230,7 +230,7 @@ module Transpec
230
230
  end
231
231
 
232
232
  # This case, do..end block works without problem.
233
- context 'when it is `subject.should_receive(:method) do..end` form' do
233
+ context 'when it is `subject.should_receive(:method) do .. end` form' do
234
234
  let(:source) do
235
235
  <<-END
236
236
  it 'receives #foo with 1' do
@@ -253,7 +253,7 @@ module Transpec
253
253
  END
254
254
  end
255
255
 
256
- it 'converts into `expect(subject).to receive(:method) do..end` form' do
256
+ it 'converts into `expect(subject).to receive(:method) do .. end` form' do
257
257
  should_receive_object.expectize!
258
258
  rewritten_source.should == expected_source
259
259
  end
@@ -282,6 +282,126 @@ module Transpec
282
282
  end
283
283
  end
284
284
  end
285
+
286
+ describe '#any_number_of_times?' do
287
+ subject { should_receive_object.any_number_of_times? }
288
+
289
+ context 'when it is `subject.should_receive(:method).any_number_of_times` form' do
290
+ let(:source) do
291
+ <<-END
292
+ it 'responds to #foo' do
293
+ subject.should_receive(:foo).any_number_of_times
294
+ end
295
+ END
296
+ end
297
+
298
+ it { should be_true }
299
+ end
300
+
301
+ context 'when it is `subject.should_receive(:method).with(arg).any_number_of_times` form' do
302
+ let(:source) do
303
+ <<-END
304
+ it 'responds to #foo with 1' do
305
+ subject.should_receive(:foo).with(1).any_number_of_times
306
+ end
307
+ END
308
+ end
309
+
310
+ it { should be_true }
311
+ end
312
+
313
+ context 'when it is `subject.should_receive(:method)` form' do
314
+ let(:source) do
315
+ <<-END
316
+ it 'receives to #foo' do
317
+ subject.should_receive(:foo)
318
+ end
319
+ END
320
+ end
321
+
322
+ it { should be_false }
323
+ end
324
+ end
325
+
326
+ describe '#allowize_any_number_of_times!' do
327
+ context 'when it is `subject.should_receive(:method).any_number_of_times` form' do
328
+ let(:source) do
329
+ <<-END
330
+ it 'responds to #foo' do
331
+ subject.should_receive(:foo).any_number_of_times
332
+ end
333
+ END
334
+ end
335
+
336
+ let(:expected_source) do
337
+ <<-END
338
+ it 'responds to #foo' do
339
+ allow(subject).to receive(:foo)
340
+ end
341
+ END
342
+ end
343
+
344
+ it 'converts into `allow(subject).to receive(:method)` form' do
345
+ should_receive_object.allowize_any_number_of_times!
346
+ rewritten_source.should == expected_source
347
+ end
348
+ end
349
+
350
+ context 'when it is `subject.should_receive(:method)` form' do
351
+ let(:source) do
352
+ <<-END
353
+ it 'receives to #foo' do
354
+ subject.should_receive(:foo)
355
+ end
356
+ END
357
+ end
358
+
359
+ it 'does nothing' do
360
+ should_receive_object.allowize_any_number_of_times!
361
+ rewritten_source.should == source
362
+ end
363
+ end
364
+ end
365
+
366
+ describe '#stubize_any_number_of_times!' do
367
+ context 'when it is `subject.should_receive(:method).any_number_of_times` form' do
368
+ let(:source) do
369
+ <<-END
370
+ it 'responds to #foo' do
371
+ subject.should_receive(:foo).any_number_of_times
372
+ end
373
+ END
374
+ end
375
+
376
+ let(:expected_source) do
377
+ <<-END
378
+ it 'responds to #foo' do
379
+ subject.stub(:foo)
380
+ end
381
+ END
382
+ end
383
+
384
+ it 'converts into `subject.stub(:method)` form' do
385
+ should_receive_object.stubize_any_number_of_times!
386
+ rewritten_source.should == expected_source
387
+ end
388
+ end
389
+
390
+ context 'when it is `subject.should_receive(:method)` form' do
391
+ let(:source) do
392
+ <<-END
393
+ it 'receives to #foo' do
394
+ subject.should_receive(:foo)
395
+ end
396
+ END
397
+ end
398
+
399
+ it 'does nothing' do
400
+ should_receive_object.stubize_any_number_of_times!
401
+ rewritten_source.should == source
402
+ end
403
+ end
404
+ end
285
405
  end
286
406
  end
287
407
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transpec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Nakayama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-30 00:00:00.000000000 Z
11
+ date: 2013-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -179,6 +179,7 @@ files:
179
179
  - lib/transpec/rewriter.rb
180
180
  - lib/transpec/syntax.rb
181
181
  - lib/transpec/syntax/any_instanceable.rb
182
+ - lib/transpec/syntax/any_number_of_timesable.rb
182
183
  - lib/transpec/syntax/be_close.rb
183
184
  - lib/transpec/syntax/double.rb
184
185
  - lib/transpec/syntax/expectizable.rb