vcr 2.0.0.beta2 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +0 -2
  3. data/CHANGELOG.md +22 -1
  4. data/CONTRIBUTING.md +46 -0
  5. data/Gemfile +1 -9
  6. data/README.md +8 -2
  7. data/Rakefile +12 -1
  8. data/cucumber.yml +8 -9
  9. data/features/.nav +10 -4
  10. data/features/cassettes/format.feature +1 -1
  11. data/features/cassettes/no_cassette.feature +8 -11
  12. data/features/configuration/allow_http_connections_when_no_cassette.feature +4 -4
  13. data/features/configuration/filter_sensitive_data.feature +3 -0
  14. data/features/configuration/hook_into.feature +4 -8
  15. data/features/configuration/ignore_request.feature +191 -0
  16. data/features/getting_started.md +38 -21
  17. data/features/hooks/after_http_request.feature +44 -0
  18. data/features/hooks/around_http_request.feature +56 -0
  19. data/features/hooks/before_http_request.feature +44 -0
  20. data/features/hooks/before_playback.feature +181 -0
  21. data/features/hooks/before_record.feature +172 -0
  22. data/features/middleware/faraday.feature +7 -3
  23. data/features/record_modes/none.feature +2 -1
  24. data/features/record_modes/once.feature +2 -1
  25. data/features/request_matching/body.feature +2 -2
  26. data/features/request_matching/custom_matcher.feature +2 -2
  27. data/features/request_matching/headers.feature +2 -2
  28. data/features/request_matching/host.feature +2 -2
  29. data/features/request_matching/identical_request_sequence.feature +2 -2
  30. data/features/request_matching/method.feature +2 -2
  31. data/features/request_matching/path.feature +2 -2
  32. data/features/request_matching/playback_repeats.feature +2 -1
  33. data/features/request_matching/uri.feature +2 -2
  34. data/features/support/env.rb +21 -12
  35. data/features/test_frameworks/cucumber.feature +9 -4
  36. data/features/test_frameworks/{rspec.feature → rspec_macro.feature} +7 -7
  37. data/features/test_frameworks/rspec_metadata.feature +90 -0
  38. data/lib/vcr.rb +1 -1
  39. data/lib/vcr/cassette.rb +3 -3
  40. data/lib/vcr/cassette/http_interaction_list.rb +13 -9
  41. data/lib/vcr/cassette/migrator.rb +1 -1
  42. data/lib/vcr/configuration.rb +37 -0
  43. data/lib/vcr/errors.rb +172 -6
  44. data/lib/vcr/library_hooks.rb +4 -6
  45. data/lib/vcr/library_hooks/excon.rb +23 -11
  46. data/lib/vcr/library_hooks/fakeweb.rb +85 -24
  47. data/lib/vcr/library_hooks/faraday.rb +30 -2
  48. data/lib/vcr/library_hooks/typhoeus.rb +25 -3
  49. data/lib/vcr/library_hooks/webmock.rb +25 -36
  50. data/lib/vcr/middleware/faraday.rb +23 -5
  51. data/lib/vcr/request_handler.rb +12 -1
  52. data/lib/vcr/request_ignorer.rb +12 -1
  53. data/lib/vcr/request_matcher_registry.rb +1 -9
  54. data/lib/vcr/structs.rb +32 -2
  55. data/lib/vcr/test_frameworks/rspec.rb +28 -0
  56. data/lib/vcr/util/hooks.rb +12 -4
  57. data/lib/vcr/util/version_checker.rb +2 -0
  58. data/lib/vcr/version.rb +1 -1
  59. data/spec/fixtures/cassette_spec/example.yml +1 -1
  60. data/spec/fixtures/{fake_example.com_responses.yml → fake_example_responses.yml} +0 -0
  61. data/spec/monkey_patches.rb +1 -1
  62. data/spec/spec_helper.rb +3 -1
  63. data/spec/support/http_library_adapters.rb +4 -3
  64. data/spec/support/shared_example_groups/hook_into_http_library.rb +194 -12
  65. data/spec/support/shared_example_groups/request_hooks.rb +58 -0
  66. data/spec/support/shared_example_groups/version_checking.rb +5 -0
  67. data/spec/support/sinatra_app.rb +17 -9
  68. data/spec/support/vcr_stub_helpers.rb +17 -0
  69. data/spec/vcr/cassette/http_interaction_list_spec.rb +28 -29
  70. data/spec/vcr/cassette/migrator_spec.rb +6 -7
  71. data/spec/vcr/cassette_spec.rb +5 -5
  72. data/spec/vcr/configuration_spec.rb +51 -32
  73. data/spec/vcr/deprecations_spec.rb +0 -8
  74. data/spec/vcr/errors_spec.rb +129 -0
  75. data/spec/vcr/library_hooks/excon_spec.rb +21 -4
  76. data/spec/vcr/library_hooks/fakeweb_spec.rb +71 -3
  77. data/spec/vcr/library_hooks/faraday_spec.rb +45 -0
  78. data/spec/vcr/library_hooks/typhoeus_spec.rb +31 -1
  79. data/spec/vcr/library_hooks/webmock_spec.rb +26 -3
  80. data/spec/vcr/middleware/faraday_spec.rb +84 -1
  81. data/spec/vcr/request_ignorer_spec.rb +16 -0
  82. data/spec/vcr/request_matcher_registry_spec.rb +0 -26
  83. data/spec/vcr/structs_spec.rb +61 -1
  84. data/spec/vcr/test_frameworks/rspec_spec.rb +32 -0
  85. data/spec/vcr/util/hooks_spec.rb +73 -63
  86. data/spec/vcr_spec.rb +2 -2
  87. data/vcr.gemspec +5 -5
  88. metadata +51 -31
  89. data/features/configuration/hooks.feature +0 -270
  90. data/features/configuration/ignore_hosts.feature +0 -61
  91. data/features/configuration/ignore_localhost.feature +0 -97
data/spec/vcr_spec.rb CHANGED
@@ -94,7 +94,7 @@ describe VCR do
94
94
 
95
95
  it 'returns a null list when there is no current cassette' do
96
96
  VCR.current_cassette.should be_nil
97
- VCR.http_interactions.should be_a(VCR::Cassette::HTTPInteractionList::NullList)
97
+ VCR.http_interactions.should be(VCR::Cassette::HTTPInteractionList::NullList)
98
98
  end
99
99
  end
100
100
 
@@ -157,7 +157,7 @@ describe VCR do
157
157
  end
158
158
  end
159
159
 
160
- describe '.serializers' do
160
+ describe '.cassette_serializers' do
161
161
  it 'always returns the same memoized cassette serializers instance' do
162
162
  VCR.cassette_serializers.should be_a(VCR::Cassette::Serializers)
163
163
  VCR.cassette_serializers.should be(VCR.cassette_serializers)
data/vcr.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.version = VCR.version
16
16
  s.platform = Gem::Platform::RUBY
17
- s.required_ruby_version = '>= 1.8.6'
17
+ s.required_ruby_version = '>= 1.8.7'
18
18
  s.required_rubygems_version = '>= 1.3.5'
19
19
 
20
20
  {
@@ -24,16 +24,16 @@ Gem::Specification.new do |s|
24
24
  'cucumber' => '~> 1.0.3',
25
25
  'aruba' => '~> 0.4.6',
26
26
 
27
- 'rspec' => '~> 2.7',
27
+ 'rspec' => '~> 2.8.0.rc1',
28
28
  'shoulda' => '~> 2.9.2',
29
29
 
30
30
  'fakeweb' => '~> 1.3.0',
31
- 'webmock' => '~> 1.7.4',
31
+ 'webmock' => '~> 1.7.8',
32
32
  'addressable' => '~> 2.2.6',
33
33
 
34
34
  'faraday' => '~> 0.7.2',
35
35
  'httpclient' => '~> 2.1.5.2',
36
- 'excon' => '~> 0.6.5',
36
+ 'excon' => '~> 0.7.9',
37
37
 
38
38
  'timecop' => '~> 0.3.5',
39
39
  'rack' => '1.1.0',
@@ -48,7 +48,7 @@ Gem::Specification.new do |s|
48
48
  'patron' => '~> 0.4.15',
49
49
  'em-http-request' => '~> 0.3.0',
50
50
  'curb' => '0.7.15',
51
- 'typhoeus' => '~> 0.3.2'
51
+ 'typhoeus' => '~> 0.3.3'
52
52
  }.each do |lib, version|
53
53
  s.add_development_dependency lib, version
54
54
  end unless RUBY_PLATFORM == 'java'
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196455
4
+ hash: 15424087
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
9
  - 0
10
- - beta
11
- - 2
12
- version: 2.0.0.beta2
10
+ - rc
11
+ - 1
12
+ version: 2.0.0.rc1
13
13
  platform: ruby
14
14
  authors:
15
15
  - Myron Marston
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-11-07 00:00:00 Z
20
+ date: 2011-12-09 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -138,11 +138,14 @@ dependencies:
138
138
  requirements:
139
139
  - - ~>
140
140
  - !ruby/object:Gem::Version
141
- hash: 13
141
+ hash: 15424215
142
142
  segments:
143
143
  - 2
144
- - 7
145
- version: "2.7"
144
+ - 8
145
+ - 0
146
+ - rc
147
+ - 1
148
+ version: 2.8.0.rc1
146
149
  name: rspec
147
150
  type: :development
148
151
  prerelease: false
@@ -233,12 +236,12 @@ dependencies:
233
236
  requirements:
234
237
  - - ~>
235
238
  - !ruby/object:Gem::Version
236
- hash: 13
239
+ hash: 17
237
240
  segments:
238
241
  - 0
239
- - 6
240
- - 5
241
- version: 0.6.5
242
+ - 7
243
+ - 9
244
+ version: 0.7.9
242
245
  name: excon
243
246
  type: :development
244
247
  prerelease: false
@@ -265,12 +268,12 @@ dependencies:
265
268
  requirements:
266
269
  - - ~>
267
270
  - !ruby/object:Gem::Version
268
- hash: 3
271
+ hash: 27
269
272
  segments:
270
273
  - 1
271
274
  - 7
272
- - 4
273
- version: 1.7.4
275
+ - 8
276
+ version: 1.7.8
274
277
  name: webmock
275
278
  type: :development
276
279
  prerelease: false
@@ -329,12 +332,12 @@ dependencies:
329
332
  requirements:
330
333
  - - ~>
331
334
  - !ruby/object:Gem::Version
332
- hash: 23
335
+ hash: 21
333
336
  segments:
334
337
  - 0
335
338
  - 3
336
- - 2
337
- version: 0.3.2
339
+ - 3
340
+ version: 0.3.3
338
341
  name: typhoeus
339
342
  type: :development
340
343
  prerelease: false
@@ -355,6 +358,7 @@ files:
355
358
  - .rspec
356
359
  - .travis.yml
357
360
  - CHANGELOG.md
361
+ - CONTRIBUTING.md
358
362
  - Gemfile
359
363
  - Guardfile
360
364
  - LICENSE
@@ -377,10 +381,13 @@ files:
377
381
  - features/configuration/default_cassette_options.feature
378
382
  - features/configuration/filter_sensitive_data.feature
379
383
  - features/configuration/hook_into.feature
380
- - features/configuration/hooks.feature
381
- - features/configuration/ignore_hosts.feature
382
- - features/configuration/ignore_localhost.feature
384
+ - features/configuration/ignore_request.feature
383
385
  - features/getting_started.md
386
+ - features/hooks/after_http_request.feature
387
+ - features/hooks/around_http_request.feature
388
+ - features/hooks/before_http_request.feature
389
+ - features/hooks/before_playback.feature
390
+ - features/hooks/before_record.feature
384
391
  - features/http_libraries/em_http_request.feature
385
392
  - features/http_libraries/net_http.feature
386
393
  - features/middleware/faraday.feature
@@ -405,7 +412,8 @@ files:
405
412
  - features/support/http_lib_filters.rb
406
413
  - features/support/vcr_cucumber_helpers.rb
407
414
  - features/test_frameworks/cucumber.feature
408
- - features/test_frameworks/rspec.feature
415
+ - features/test_frameworks/rspec_macro.feature
416
+ - features/test_frameworks/rspec_metadata.feature
409
417
  - features/test_frameworks/shoulda.feature
410
418
  - features/test_frameworks/test_unit.feature
411
419
  - lib/vcr.rb
@@ -450,7 +458,7 @@ files:
450
458
  - spec/fixtures/cassette_spec/empty.yml
451
459
  - spec/fixtures/cassette_spec/example.yml
452
460
  - spec/fixtures/cassette_spec/with_localhost_requests.yml
453
- - spec/fixtures/fake_example.com_responses.yml
461
+ - spec/fixtures/fake_example_responses.yml
454
462
  - spec/fixtures/match_requests_on.yml
455
463
  - spec/monkey_patches.rb
456
464
  - spec/spec_helper.rb
@@ -458,9 +466,11 @@ files:
458
466
  - spec/support/http_library_adapters.rb
459
467
  - spec/support/ruby_interpreter.rb
460
468
  - spec/support/shared_example_groups/hook_into_http_library.rb
469
+ - spec/support/shared_example_groups/request_hooks.rb
461
470
  - spec/support/shared_example_groups/version_checking.rb
462
471
  - spec/support/sinatra_app.rb
463
472
  - spec/support/vcr_localhost_server.rb
473
+ - spec/support/vcr_stub_helpers.rb
464
474
  - spec/vcr/cassette/http_interaction_list_spec.rb
465
475
  - spec/vcr/cassette/migrator_spec.rb
466
476
  - spec/vcr/cassette/reader_spec.rb
@@ -468,9 +478,11 @@ files:
468
478
  - spec/vcr/cassette_spec.rb
469
479
  - spec/vcr/configuration_spec.rb
470
480
  - spec/vcr/deprecations_spec.rb
481
+ - spec/vcr/errors_spec.rb
471
482
  - spec/vcr/extensions/net_http_response_spec.rb
472
483
  - spec/vcr/library_hooks/excon_spec.rb
473
484
  - spec/vcr/library_hooks/fakeweb_spec.rb
485
+ - spec/vcr/library_hooks/faraday_spec.rb
474
486
  - spec/vcr/library_hooks/typhoeus_spec.rb
475
487
  - spec/vcr/library_hooks/webmock_spec.rb
476
488
  - spec/vcr/library_hooks_spec.rb
@@ -499,12 +511,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
499
511
  requirements:
500
512
  - - ">="
501
513
  - !ruby/object:Gem::Version
502
- hash: 59
514
+ hash: 57
503
515
  segments:
504
516
  - 1
505
517
  - 8
506
- - 6
507
- version: 1.8.6
518
+ - 7
519
+ version: 1.8.7
508
520
  required_rubygems_version: !ruby/object:Gem::Requirement
509
521
  none: false
510
522
  requirements:
@@ -537,10 +549,13 @@ test_files:
537
549
  - features/configuration/default_cassette_options.feature
538
550
  - features/configuration/filter_sensitive_data.feature
539
551
  - features/configuration/hook_into.feature
540
- - features/configuration/hooks.feature
541
- - features/configuration/ignore_hosts.feature
542
- - features/configuration/ignore_localhost.feature
552
+ - features/configuration/ignore_request.feature
543
553
  - features/getting_started.md
554
+ - features/hooks/after_http_request.feature
555
+ - features/hooks/around_http_request.feature
556
+ - features/hooks/before_http_request.feature
557
+ - features/hooks/before_playback.feature
558
+ - features/hooks/before_record.feature
544
559
  - features/http_libraries/em_http_request.feature
545
560
  - features/http_libraries/net_http.feature
546
561
  - features/middleware/faraday.feature
@@ -565,7 +580,8 @@ test_files:
565
580
  - features/support/http_lib_filters.rb
566
581
  - features/support/vcr_cucumber_helpers.rb
567
582
  - features/test_frameworks/cucumber.feature
568
- - features/test_frameworks/rspec.feature
583
+ - features/test_frameworks/rspec_macro.feature
584
+ - features/test_frameworks/rspec_metadata.feature
569
585
  - features/test_frameworks/shoulda.feature
570
586
  - features/test_frameworks/test_unit.feature
571
587
  - spec/capture_warnings.rb
@@ -573,7 +589,7 @@ test_files:
573
589
  - spec/fixtures/cassette_spec/empty.yml
574
590
  - spec/fixtures/cassette_spec/example.yml
575
591
  - spec/fixtures/cassette_spec/with_localhost_requests.yml
576
- - spec/fixtures/fake_example.com_responses.yml
592
+ - spec/fixtures/fake_example_responses.yml
577
593
  - spec/fixtures/match_requests_on.yml
578
594
  - spec/monkey_patches.rb
579
595
  - spec/spec_helper.rb
@@ -581,9 +597,11 @@ test_files:
581
597
  - spec/support/http_library_adapters.rb
582
598
  - spec/support/ruby_interpreter.rb
583
599
  - spec/support/shared_example_groups/hook_into_http_library.rb
600
+ - spec/support/shared_example_groups/request_hooks.rb
584
601
  - spec/support/shared_example_groups/version_checking.rb
585
602
  - spec/support/sinatra_app.rb
586
603
  - spec/support/vcr_localhost_server.rb
604
+ - spec/support/vcr_stub_helpers.rb
587
605
  - spec/vcr/cassette/http_interaction_list_spec.rb
588
606
  - spec/vcr/cassette/migrator_spec.rb
589
607
  - spec/vcr/cassette/reader_spec.rb
@@ -591,9 +609,11 @@ test_files:
591
609
  - spec/vcr/cassette_spec.rb
592
610
  - spec/vcr/configuration_spec.rb
593
611
  - spec/vcr/deprecations_spec.rb
612
+ - spec/vcr/errors_spec.rb
594
613
  - spec/vcr/extensions/net_http_response_spec.rb
595
614
  - spec/vcr/library_hooks/excon_spec.rb
596
615
  - spec/vcr/library_hooks/fakeweb_spec.rb
616
+ - spec/vcr/library_hooks/faraday_spec.rb
597
617
  - spec/vcr/library_hooks/typhoeus_spec.rb
598
618
  - spec/vcr/library_hooks/webmock_spec.rb
599
619
  - spec/vcr/library_hooks_spec.rb
@@ -1,270 +0,0 @@
1
- Feature: Hooks
2
-
3
- VCR provides two global hooks that you can use to customize recording and
4
- playback:
5
-
6
- - `before_record`: Called before a cassette is written to disk.
7
- - `before_playback`: Called before a cassette sets up its stubs for playback.
8
-
9
- To use these, call `config.before_record` or `config.before_playback` in
10
- your `VCR.configure` block. Provide a block that accepts 0, 1 or 2 arguments.
11
-
12
- The first argument, if the block accepts it, will be an HTTP interaction.
13
- Changes you make to the interaction will be reflected in the recording or
14
- playback. You can also call `#ignore!` on the interaction to cause VCR to
15
- ignore it. It will not be recorded or played back (depending on which
16
- kind of hook you use).
17
-
18
- The second argument, if the block accepts it, will be the
19
- `VCR::Cassette` instance. This may be useful for hooks that you want to
20
- behave differently for different cassettes.
21
-
22
- You can also use tagging to apply hooks to particular cassettes. Consider
23
- this code:
24
-
25
- VCR.configure do |c|
26
- c.before_record(:twitter) { ... } # modify the interactions somehow
27
- end
28
-
29
- VCR.use_cassette('cassette_1', :tag => :twitter) { ... }
30
- VCR.use_cassette('cassette_2') { ... }
31
-
32
- In this example, the hook would apply to the first cassette but not the
33
- second cassette.
34
-
35
- You can setup as many hooks as you like; each will be invoked at the
36
- appropriate time.
37
-
38
- Background:
39
- Given a previously recorded cassette file "cassettes/example.yml" with:
40
- """
41
- ---
42
- http_interactions:
43
- - request:
44
- method: get
45
- uri: http://example.com/foo
46
- body: ''
47
- headers: {}
48
- response:
49
- status:
50
- code: 200
51
- message: OK
52
- headers:
53
- Content-Type:
54
- - text/html;charset=utf-8
55
- Content-Length:
56
- - '20'
57
- body: example.com response
58
- http_version: '1.1'
59
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
60
- recorded_with: VCR 2.0.0
61
- """
62
-
63
- Scenario: Replace sensitive data with before_record hook
64
- Given a file named "before_record_example.rb" with:
65
- """ruby
66
- start_sinatra_app(:port => 7777) do
67
- get('/') { "Hello <secret>" }
68
- end
69
-
70
- require 'vcr'
71
-
72
- VCR.configure do |c|
73
- c.hook_into :fakeweb
74
- c.cassette_library_dir = 'cassettes'
75
-
76
- c.before_record do |i|
77
- i.response.body.sub!(/^Hello .*$/, 'Hello World')
78
- end
79
-
80
- end
81
-
82
- VCR.use_cassette('recording_example') do
83
- Net::HTTP.get_response('localhost', '/', 7777)
84
- end
85
- """
86
- When I run `ruby before_record_example.rb`
87
- Then the file "cassettes/recording_example.yml" should contain "body: Hello World"
88
- And the file "cassettes/recording_example.yml" should not contain "secret"
89
-
90
- Scenario: Prevent recording by ignoring interaction in before_record hook
91
- Given a file named "before_record_ignore.rb" with:
92
- """ruby
93
- start_sinatra_app(:port => 7777) do
94
- get('/') { "Hello World" }
95
- end
96
-
97
- require 'vcr'
98
-
99
- VCR.configure do |c|
100
- c.hook_into :fakeweb
101
- c.cassette_library_dir = 'cassettes'
102
- c.before_record { |i| i.ignore! }
103
- end
104
-
105
- VCR.use_cassette('recording_example') do
106
- response = Net::HTTP.get_response('localhost', '/', 7777)
107
- puts "Response: #{response.body}"
108
- end
109
- """
110
- When I run `ruby before_record_ignore.rb`
111
- Then it should pass with "Response: Hello World"
112
- And the file "cassettes/recording_example.yml" should not exist
113
-
114
- Scenario: Change playback with before_playback hook
115
- Given a file named "before_playback_example.rb" with:
116
- """ruby
117
- require 'vcr'
118
-
119
- VCR.configure do |c|
120
- c.hook_into :fakeweb
121
- c.cassette_library_dir = 'cassettes'
122
-
123
- c.before_playback do |i|
124
- i.response.body = 'response from before_playback'
125
- end
126
- end
127
-
128
- VCR.use_cassette('example') do
129
- response = Net::HTTP.get_response('example.com', '/foo')
130
- puts "Response: #{response.body}"
131
- end
132
- """
133
- When I run `ruby before_playback_example.rb`
134
- Then it should pass with "Response: response from before_playback"
135
-
136
- Scenario: Prevent playback by ignoring interaction in before_playback hook
137
- Given a previously recorded cassette file "cassettes/localhost.yml" with:
138
- """
139
- ---
140
- http_interactions:
141
- - request:
142
- method: get
143
- uri: http://localhost:7777/
144
- body: ''
145
- headers: {}
146
- response:
147
- status:
148
- code: 200
149
- message: OK
150
- headers:
151
- Content-Type:
152
- - text/html;charset=utf-8
153
- Content-Length:
154
- - '20'
155
- body: recorded response
156
- http_version: '1.1'
157
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
158
- recorded_with: VCR 2.0.0
159
- """
160
- And a file named "before_playback_ignore.rb" with:
161
- """ruby
162
- start_sinatra_app(:port => 7777) do
163
- get('/') { "sinatra response" }
164
- end
165
-
166
- require 'vcr'
167
-
168
- VCR.configure do |c|
169
- c.hook_into :fakeweb
170
- c.cassette_library_dir = 'cassettes'
171
- c.before_playback { |i| i.ignore! }
172
- end
173
-
174
- VCR.use_cassette('localhost', :record => :new_episodes) do
175
- response = Net::HTTP.get_response('localhost', '/', 7777)
176
- puts "Response: #{response.body}"
177
- end
178
- """
179
- When I run `ruby before_playback_ignore.rb`
180
- Then it should pass with "Response: sinatra response"
181
-
182
- Scenario: Multiple hooks are run in order
183
- Given a file named "multiple_hooks.rb" with:
184
- """ruby
185
- start_sinatra_app(:port => 7777) do
186
- get('/') { "Hello World" }
187
- end
188
-
189
- require 'vcr'
190
-
191
- VCR.configure do |c|
192
- c.hook_into :fakeweb
193
- c.cassette_library_dir = 'cassettes'
194
-
195
- c.before_record { puts "In before_record hook 1" }
196
- c.before_record { puts "In before_record hook 2" }
197
-
198
- c.before_playback { puts "In before_playback hook 1" }
199
- c.before_playback { puts "In before_playback hook 2" }
200
- end
201
-
202
- VCR.use_cassette('example', :record => :new_episodes) do
203
- response = Net::HTTP.get_response('localhost', '/', 7777)
204
- puts "Response 1: #{response.body}"
205
-
206
- response = Net::HTTP.get_response('example.com', '/foo')
207
- puts "Response 2: #{response.body}"
208
- end
209
- """
210
- When I run `ruby multiple_hooks.rb`
211
- Then it should pass with:
212
- """
213
- In before_playback hook 1
214
- In before_playback hook 2
215
- Response 1: Hello World
216
- Response 2: example.com response
217
- In before_record hook 1
218
- In before_record hook 2
219
- """
220
-
221
- Scenario: Use tagging to apply hooks to only certain cassettes
222
- Given a file named "tagged_hooks.rb" with:
223
- """ruby
224
- start_sinatra_app(:port => 7777) do
225
- get('/') { "Hello World" }
226
- end
227
-
228
- require 'vcr'
229
-
230
- VCR.configure do |c|
231
- c.hook_into :fakeweb
232
- c.cassette_library_dir = 'cassettes'
233
-
234
- c.before_record(:tag_1) { |i| puts "In before_record hook for tag_1 (#{i.response.body})" }
235
- c.before_playback(:tag_2) { |i| puts "In before_playback hook for tag_2 (#{i.response.body})" }
236
- end
237
-
238
- [:tag_1, :tag_2, nil].each do |tag|
239
- puts
240
- puts "Using tag: #{tag.inspect}"
241
-
242
- VCR.use_cassette('example', :record => :new_episodes, :tag => tag) do
243
- response = Net::HTTP.get_response('localhost', '/', 7777)
244
- puts "Response 1: #{response.body}"
245
-
246
- response = Net::HTTP.get_response('example.com', '/foo')
247
- puts "Response 2: #{response.body}"
248
- end
249
- end
250
- """
251
- When I run `ruby tagged_hooks.rb`
252
- Then it should pass with:
253
- """
254
- Using tag: :tag_1
255
- Response 1: Hello World
256
- Response 2: example.com response
257
- In before_record hook for tag_1 (example.com response)
258
- In before_record hook for tag_1 (Hello World)
259
-
260
- Using tag: :tag_2
261
- In before_playback hook for tag_2 (example.com response)
262
- In before_playback hook for tag_2 (Hello World)
263
- Response 1: Hello World
264
- Response 2: example.com response
265
-
266
- Using tag: nil
267
- Response 1: Hello World
268
- Response 2: example.com response
269
- """
270
-