vcr 3.0.3 → 6.2.0

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.
Files changed (146) hide show
  1. checksums.yaml +5 -5
  2. data/lib/vcr/cassette/erb_renderer.rb +4 -2
  3. data/lib/vcr/cassette/http_interaction_list.rb +14 -9
  4. data/lib/vcr/cassette/migrator.rb +5 -6
  5. data/lib/vcr/cassette/persisters/file_system.rb +9 -1
  6. data/lib/vcr/cassette/serializers/compressed.rb +2 -2
  7. data/lib/vcr/cassette/serializers/json.rb +14 -8
  8. data/lib/vcr/cassette/serializers/psych.rb +10 -2
  9. data/lib/vcr/cassette/serializers/syck.rb +7 -1
  10. data/lib/vcr/cassette/serializers/yaml.rb +14 -2
  11. data/lib/vcr/cassette/serializers.rb +10 -0
  12. data/lib/vcr/cassette.rb +63 -16
  13. data/lib/vcr/configuration.rb +21 -8
  14. data/lib/vcr/deprecations.rb +0 -62
  15. data/lib/vcr/errors.rb +17 -12
  16. data/lib/vcr/library_hooks/excon.rb +8 -0
  17. data/lib/vcr/library_hooks/typhoeus.rb +91 -79
  18. data/lib/vcr/library_hooks/webmock.rb +2 -11
  19. data/lib/vcr/linked_cassette.rb +4 -4
  20. data/lib/vcr/middleware/excon.rb +1 -1
  21. data/lib/vcr/middleware/faraday.rb +29 -2
  22. data/lib/vcr/request_ignorer.rb +8 -1
  23. data/lib/vcr/request_matcher_registry.rb +3 -3
  24. data/lib/vcr/structs.rb +48 -32
  25. data/lib/vcr/test_frameworks/cucumber.rb +16 -5
  26. data/lib/vcr/test_frameworks/rspec.rb +34 -22
  27. data/lib/vcr/util/hooks.rb +1 -0
  28. data/lib/vcr/util/internet_connection.rb +15 -21
  29. data/lib/vcr/version.rb +2 -2
  30. data/lib/vcr.rb +52 -2
  31. metadata +45 -272
  32. data/features/CHANGELOG.md +0 -710
  33. data/features/CONTRIBUTING.md +0 -26
  34. data/features/LICENSE.md +0 -20
  35. data/features/README.md +0 -339
  36. data/features/Upgrade.md +0 -289
  37. data/features/about_these_examples.md +0 -18
  38. data/features/cassettes/allow_unused_http_interactions.feature +0 -100
  39. data/features/cassettes/automatic_re_recording.feature +0 -72
  40. data/features/cassettes/decompress.feature +0 -74
  41. data/features/cassettes/dynamic_erb.feature +0 -100
  42. data/features/cassettes/exclusive.feature +0 -126
  43. data/features/cassettes/format.feature +0 -411
  44. data/features/cassettes/freezing_time.feature +0 -68
  45. data/features/cassettes/naming.feature +0 -28
  46. data/features/cassettes/no_cassette.feature +0 -152
  47. data/features/cassettes/update_content_length_header.feature +0 -112
  48. data/features/configuration/allow_http_connections_when_no_cassette.feature +0 -55
  49. data/features/configuration/cassette_library_dir.feature +0 -31
  50. data/features/configuration/debug_logging.feature +0 -58
  51. data/features/configuration/default_cassette_options.feature +0 -100
  52. data/features/configuration/filter_sensitive_data.feature +0 -153
  53. data/features/configuration/hook_into.feature +0 -172
  54. data/features/configuration/ignore_request.feature +0 -192
  55. data/features/configuration/preserve_exact_body_bytes.feature +0 -108
  56. data/features/configuration/query_parser.feature +0 -84
  57. data/features/configuration/uri_parser.feature +0 -93
  58. data/features/getting_started.md +0 -82
  59. data/features/hooks/after_http_request.feature +0 -58
  60. data/features/hooks/around_http_request.feature +0 -57
  61. data/features/hooks/before_http_request.feature +0 -63
  62. data/features/hooks/before_playback.feature +0 -184
  63. data/features/hooks/before_record.feature +0 -172
  64. data/features/http_libraries/em_http_request.feature +0 -250
  65. data/features/http_libraries/net_http.feature +0 -179
  66. data/features/middleware/faraday.feature +0 -56
  67. data/features/middleware/rack.feature +0 -92
  68. data/features/record_modes/all.feature +0 -82
  69. data/features/record_modes/new_episodes.feature +0 -79
  70. data/features/record_modes/none.feature +0 -72
  71. data/features/record_modes/once.feature +0 -95
  72. data/features/request_matching/README.md +0 -30
  73. data/features/request_matching/body.feature +0 -91
  74. data/features/request_matching/body_as_json.feature +0 -90
  75. data/features/request_matching/custom_matcher.feature +0 -135
  76. data/features/request_matching/headers.feature +0 -85
  77. data/features/request_matching/host.feature +0 -95
  78. data/features/request_matching/identical_request_sequence.feature +0 -89
  79. data/features/request_matching/method.feature +0 -96
  80. data/features/request_matching/path.feature +0 -96
  81. data/features/request_matching/playback_repeats.feature +0 -98
  82. data/features/request_matching/query.feature +0 -97
  83. data/features/request_matching/uri.feature +0 -94
  84. data/features/request_matching/uri_without_param.feature +0 -101
  85. data/features/step_definitions/cli_steps.rb +0 -199
  86. data/features/support/env.rb +0 -46
  87. data/features/support/http_lib_filters.rb +0 -46
  88. data/features/test_frameworks/cucumber.feature +0 -211
  89. data/features/test_frameworks/rspec_macro.feature +0 -81
  90. data/features/test_frameworks/rspec_metadata.feature +0 -150
  91. data/features/test_frameworks/test_unit.feature +0 -49
  92. data/lib/vcr/extensions/net_http_response.rb +0 -36
  93. data/lib/vcr/library_hooks/fakeweb.rb +0 -197
  94. data/lib/vcr/library_hooks/typhoeus_0.4.rb +0 -103
  95. data/spec/acceptance/concurrency_spec.rb +0 -51
  96. data/spec/acceptance/threading_spec.rb +0 -34
  97. data/spec/fixtures/cassette_spec/1_x_cassette.yml +0 -110
  98. data/spec/fixtures/cassette_spec/empty.yml +0 -0
  99. data/spec/fixtures/cassette_spec/example.yml +0 -111
  100. data/spec/fixtures/cassette_spec/with_localhost_requests.yml +0 -111
  101. data/spec/fixtures/fake_example_responses.yml +0 -110
  102. data/spec/fixtures/match_requests_on.yml +0 -187
  103. data/spec/lib/vcr/cassette/erb_renderer_spec.rb +0 -53
  104. data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +0 -295
  105. data/spec/lib/vcr/cassette/migrator_spec.rb +0 -196
  106. data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +0 -75
  107. data/spec/lib/vcr/cassette/persisters_spec.rb +0 -39
  108. data/spec/lib/vcr/cassette/serializers_spec.rb +0 -182
  109. data/spec/lib/vcr/cassette_spec.rb +0 -618
  110. data/spec/lib/vcr/configuration_spec.rb +0 -326
  111. data/spec/lib/vcr/deprecations_spec.rb +0 -85
  112. data/spec/lib/vcr/errors_spec.rb +0 -178
  113. data/spec/lib/vcr/extensions/net_http_response_spec.rb +0 -86
  114. data/spec/lib/vcr/library_hooks/excon_spec.rb +0 -104
  115. data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +0 -169
  116. data/spec/lib/vcr/library_hooks/faraday_spec.rb +0 -68
  117. data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +0 -36
  118. data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +0 -162
  119. data/spec/lib/vcr/library_hooks/webmock_spec.rb +0 -117
  120. data/spec/lib/vcr/library_hooks_spec.rb +0 -51
  121. data/spec/lib/vcr/middleware/faraday_spec.rb +0 -181
  122. data/spec/lib/vcr/middleware/rack_spec.rb +0 -115
  123. data/spec/lib/vcr/request_ignorer_spec.rb +0 -70
  124. data/spec/lib/vcr/request_matcher_registry_spec.rb +0 -345
  125. data/spec/lib/vcr/structs_spec.rb +0 -732
  126. data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +0 -107
  127. data/spec/lib/vcr/test_frameworks/rspec_spec.rb +0 -94
  128. data/spec/lib/vcr/util/hooks_spec.rb +0 -158
  129. data/spec/lib/vcr/util/internet_connection_spec.rb +0 -37
  130. data/spec/lib/vcr/util/version_checker_spec.rb +0 -31
  131. data/spec/lib/vcr/version_spec.rb +0 -27
  132. data/spec/lib/vcr_spec.rb +0 -354
  133. data/spec/monkey_patches.rb +0 -186
  134. data/spec/spec_helper.rb +0 -63
  135. data/spec/support/configuration_stubbing.rb +0 -8
  136. data/spec/support/cucumber_helpers.rb +0 -39
  137. data/spec/support/fixnum_extension.rb +0 -10
  138. data/spec/support/http_library_adapters.rb +0 -289
  139. data/spec/support/limited_uri.rb +0 -21
  140. data/spec/support/ruby_interpreter.rb +0 -7
  141. data/spec/support/shared_example_groups/excon.rb +0 -63
  142. data/spec/support/shared_example_groups/hook_into_http_library.rb +0 -594
  143. data/spec/support/shared_example_groups/request_hooks.rb +0 -59
  144. data/spec/support/sinatra_app.rb +0 -86
  145. data/spec/support/vcr_localhost_server.rb +0 -76
  146. data/spec/support/vcr_stub_helpers.rb +0 -17
@@ -1,79 +0,0 @@
1
- Feature: :new_episodes
2
-
3
- The `:new_episodes` record mode will:
4
-
5
- - Record new interactions.
6
- - Replay previously recorded interactions.
7
-
8
- It is similar to the `:once` record mode, but will _always_ record new
9
- interactions, even if you have an existing recorded one that is similar
10
- (but not identical, based on the `:match_request_on` option).
11
-
12
- Background:
13
- Given a file named "setup.rb" with:
14
- """ruby
15
- $server = start_sinatra_app do
16
- get('/') { 'Hello' }
17
- end
18
-
19
- require 'vcr'
20
-
21
- VCR.configure do |c|
22
- c.hook_into :webmock
23
- c.cassette_library_dir = 'cassettes'
24
- end
25
- """
26
- And a previously recorded cassette file "cassettes/example.yml" with:
27
- """
28
- ---
29
- http_interactions:
30
- - request:
31
- method: get
32
- uri: http://example.com/foo
33
- body:
34
- encoding: UTF-8
35
- string: ""
36
- headers: {}
37
- response:
38
- status:
39
- code: 200
40
- message: OK
41
- headers:
42
- Content-Length:
43
- - "20"
44
- body:
45
- encoding: UTF-8
46
- string: example.com response
47
- http_version: "1.1"
48
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
49
- recorded_with: VCR 2.0.0
50
- """
51
-
52
- Scenario: Previously recorded responses are replayed
53
- Given a file named "replay_recorded_response.rb" with:
54
- """ruby
55
- require 'setup'
56
-
57
- VCR.use_cassette('example', :record => :new_episodes) do
58
- response = Net::HTTP.get_response('example.com', '/foo')
59
- puts "Response: #{response.body}"
60
- end
61
- """
62
- When I run `ruby replay_recorded_response.rb`
63
- Then it should pass with "Response: example.com response"
64
-
65
- Scenario: New requests get recorded
66
- Given a file named "record_new_requests.rb" with:
67
- """ruby
68
- require 'setup'
69
-
70
- VCR.use_cassette('example', :record => :new_episodes) do
71
- response = Net::HTTP.get_response('localhost', '/', $server.port)
72
- puts "Response: #{response.body}"
73
- end
74
- """
75
- When I run `ruby record_new_requests.rb`
76
- Then it should pass with "Response: Hello"
77
- And the file "cassettes/example.yml" should contain each of these:
78
- | example.com response |
79
- | Hello |
@@ -1,72 +0,0 @@
1
- Feature: :none
2
-
3
- The `:none` record mode will:
4
-
5
- - Replay previously recorded interactions.
6
- - Cause an error to be raised for any new requests.
7
-
8
- This is useful when your code makes potentially dangerous
9
- HTTP requests. The `:none` record mode guarantees that no
10
- new HTTP requests will be made.
11
-
12
- Background:
13
- Given a file named "vcr_config.rb" with:
14
- """ruby
15
- require 'vcr'
16
-
17
- VCR.configure do |c|
18
- c.hook_into :webmock
19
- c.cassette_library_dir = 'cassettes'
20
- end
21
- """
22
- And a previously recorded cassette file "cassettes/example.yml" with:
23
- """
24
- ---
25
- http_interactions:
26
- - request:
27
- method: get
28
- uri: http://example.com/foo
29
- body:
30
- encoding: UTF-8
31
- string: ""
32
- headers: {}
33
- response:
34
- status:
35
- code: 200
36
- message: OK
37
- headers:
38
- Content-Length:
39
- - "5"
40
- body:
41
- encoding: UTF-8
42
- string: Hello
43
- http_version: "1.1"
44
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
45
- recorded_with: VCR 2.0.0
46
- """
47
-
48
- Scenario: Previously recorded responses are replayed
49
- Given a file named "replay_recorded_response.rb" with:
50
- """ruby
51
- require 'vcr_config'
52
-
53
- VCR.use_cassette('example', :record => :none) do
54
- response = Net::HTTP.get_response('example.com', '/foo')
55
- puts "Response: #{response.body}"
56
- end
57
- """
58
- When I run `ruby replay_recorded_response.rb`
59
- Then it should pass with "Response: Hello"
60
-
61
- @exclude-jruby
62
- Scenario: New requests are prevented
63
- Given a file named "prevent_new_request.rb" with:
64
- """ruby
65
- require 'vcr_config'
66
-
67
- VCR.use_cassette('example', :record => :none) do
68
- Net::HTTP.get_response('example.com', '/bar')
69
- end
70
- """
71
- When I run `ruby prevent_new_request.rb`
72
- Then it should fail with "An HTTP request has been made that VCR does not know how to handle"
@@ -1,95 +0,0 @@
1
- Feature: :once
2
-
3
- The `:once` record mode will:
4
-
5
- - Replay previously recorded interactions.
6
- - Record new interactions if there is no cassette file.
7
- - Cause an error to be raised for new requests if there is a cassette file.
8
-
9
- It is similar to the `:new_episodes` record mode, but will prevent new,
10
- unexpected requests from being made (i.e. because the request URI changed
11
- or whatever).
12
-
13
- `:once` is the default record mode, used when you do not set one.
14
-
15
- Background:
16
- Given a file named "setup.rb" with:
17
- """ruby
18
- $server = start_sinatra_app do
19
- get('/') { 'Hello' }
20
- end
21
-
22
- require 'vcr'
23
-
24
- VCR.configure do |c|
25
- c.hook_into :webmock
26
- c.cassette_library_dir = 'cassettes'
27
- end
28
- """
29
- And a previously recorded cassette file "cassettes/example.yml" with:
30
- """
31
- ---
32
- http_interactions:
33
- - request:
34
- method: get
35
- uri: http://example.com/foo
36
- body:
37
- encoding: UTF-8
38
- string: ""
39
- headers: {}
40
- response:
41
- status:
42
- code: 200
43
- message: OK
44
- headers:
45
- Content-Length:
46
- - "20"
47
- body:
48
- encoding: UTF-8
49
- string: example.com response
50
- http_version: "1.1"
51
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
52
- recorded_with: VCR 2.0.0
53
- """
54
-
55
- Scenario: Previously recorded responses are replayed
56
- Given a file named "replay_recorded_response.rb" with:
57
- """ruby
58
- require 'setup'
59
-
60
- VCR.use_cassette('example', :record => :once) do
61
- response = Net::HTTP.get_response('example.com', '/foo')
62
- puts "Response: #{response.body}"
63
- end
64
- """
65
- When I run `ruby replay_recorded_response.rb`
66
- Then it should pass with "Response: example.com response"
67
-
68
- @exclude-jruby
69
- Scenario: New requests result in an error when the cassette file exists
70
- Given a file named "error_for_new_requests_when_cassette_exists.rb" with:
71
- """ruby
72
- require 'setup'
73
-
74
- VCR.use_cassette('example', :record => :once) do
75
- response = Net::HTTP.get_response('localhost', '/', $server.port)
76
- puts "Response: #{response.body}"
77
- end
78
- """
79
- When I run `ruby error_for_new_requests_when_cassette_exists.rb`
80
- Then it should fail with "An HTTP request has been made that VCR does not know how to handle"
81
-
82
- Scenario: New requests get recorded when there is no cassette file
83
- Given a file named "record_new_requests.rb" with:
84
- """ruby
85
- require 'setup'
86
-
87
- VCR.use_cassette('example', :record => :once) do
88
- response = Net::HTTP.get_response('localhost', '/', $server.port)
89
- puts "Response: #{response.body}"
90
- end
91
- """
92
- When I remove the file "cassettes/example.yml"
93
- And I run `ruby record_new_requests.rb`
94
- Then it should pass with "Response: Hello"
95
- And the file "cassettes/example.yml" should contain "Hello"
@@ -1,30 +0,0 @@
1
- In order to properly replay previously recorded requests, VCR must match new
2
- HTTP requests to a previously recorded one. By default, it matches on HTTP
3
- method and URI, since that is usually deterministic and fully identifies the
4
- resource and action for typical RESTful APIs.
5
-
6
- You can customize how VCR matches requests using the `:match_requests_on` cassette option.
7
- Specify an array of attributes to match on. Supported attributes are:
8
-
9
- - `:method` - The HTTP method (i.e. GET, POST, PUT or DELETE) of the request.
10
- - `:uri` - The full URI of the request.
11
- - `:host` - The host of the URI. You can use this (alone, or in combination
12
- with `:path`) as an alternative to `:uri` to cause VCR to match using a regex
13
- that matches the host.
14
- - `:path` - The path of the URI. You can use this (alone, or in combination
15
- with `:host`) as an alternative to `:uri` to cause VCR to match using a regex
16
- that matches the path.
17
- - `:query` - The query string values of the URI. The query string ordering does
18
- not affect matching results (it's order-agnostic).
19
- - `:body` - The body of the request.
20
- - `:headers` - The request headers.
21
-
22
- You can also register a custom request matcher. This particularly comes
23
- in handy for dealing with APIs that use non-deterministic URIs (i.e. by
24
- including a timestamp as a query parameter or whatever).
25
-
26
- When a cassette contains multiple HTTP interactions that match a request
27
- based on the configured `:match_requests_on` setting, the responses are
28
- sequenced: the first matching request will get the first response,
29
- the second matching request will get the second response, etc.
30
-
@@ -1,91 +0,0 @@
1
- Feature: Matching on Body
2
-
3
- Use the `:body` request matcher to match requests on the request body.
4
-
5
- Background:
6
- Given a previously recorded cassette file "cassettes/example.yml" with:
7
- """
8
- ---
9
- http_interactions:
10
- - request:
11
- method: post
12
- uri: http://example.net/some/long/path
13
- body:
14
- encoding: UTF-8
15
- string: body1
16
- headers: {}
17
- response:
18
- status:
19
- code: 200
20
- message: OK
21
- headers:
22
- Content-Length:
23
- - "14"
24
- body:
25
- encoding: UTF-8
26
- string: body1 response
27
- http_version: "1.1"
28
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
29
- - request:
30
- method: post
31
- uri: http://example.net/some/long/path
32
- body:
33
- encoding: UTF-8
34
- string: body2
35
- headers: {}
36
- response:
37
- status:
38
- code: 200
39
- message: OK
40
- headers:
41
- Content-Length:
42
- - "14"
43
- body:
44
- encoding: UTF-8
45
- string: body2 response
46
- http_version: "1.1"
47
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
48
- recorded_with: VCR 2.0.0
49
- """
50
-
51
- Scenario Outline: Replay interaction that matches the body
52
- And a file named "body_matching.rb" with:
53
- """ruby
54
- include_http_adapter_for("<http_lib>")
55
-
56
- require 'vcr'
57
-
58
- VCR.configure do |c|
59
- <configuration>
60
- c.cassette_library_dir = 'cassettes'
61
- end
62
-
63
- VCR.use_cassette('example', :match_requests_on => [:body]) do
64
- puts "Response for body2: " + response_body_for(:put, "http://example.com/", "body2")
65
- end
66
-
67
- VCR.use_cassette('example', :match_requests_on => [:body]) do
68
- puts "Response for body1: " + response_body_for(:put, "http://example.com/", "body1")
69
- end
70
- """
71
- When I run `ruby body_matching.rb`
72
- Then it should pass with:
73
- """
74
- Response for body2: body2 response
75
- Response for body1: body1 response
76
- """
77
-
78
- Examples:
79
- | configuration | http_lib |
80
- | c.hook_into :fakeweb | net/http |
81
- | c.hook_into :webmock | net/http |
82
- | c.hook_into :webmock | httpclient |
83
- | c.hook_into :webmock | curb |
84
- | c.hook_into :webmock | patron |
85
- | c.hook_into :webmock | em-http-request |
86
- | c.hook_into :webmock | typhoeus |
87
- | c.hook_into :typhoeus | typhoeus |
88
- | c.hook_into :excon | excon |
89
- | c.hook_into :faraday | faraday (w/ net_http) |
90
- | c.hook_into :faraday | faraday (w/ typhoeus) |
91
-
@@ -1,90 +0,0 @@
1
- Feature: Matching on Body
2
-
3
- Use the `:body_as_json` request matcher to match requests on the request body where the body is JSON.
4
-
5
- Background:
6
- Given a previously recorded cassette file "cassettes/example.yml" with:
7
- """
8
- ---
9
- http_interactions:
10
- - request:
11
- method: post
12
- uri: http://example.net/some/long/path
13
- body:
14
- encoding: UTF-8
15
- string: '{ "a" : "1" }'
16
- headers: {}
17
- response:
18
- status:
19
- code: 200
20
- message: OK
21
- headers:
22
- Content-Length:
23
- - "14"
24
- body:
25
- encoding: UTF-8
26
- string: body1 response
27
- http_version: "1.1"
28
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
29
- - request:
30
- method: post
31
- uri: http://example.net/some/long/path
32
- body:
33
- encoding: UTF-8
34
- string: '{ "a" : "1", "b" : "2" }'
35
- headers: {}
36
- response:
37
- status:
38
- code: 200
39
- message: OK
40
- headers:
41
- Content-Length:
42
- - "14"
43
- body:
44
- encoding: UTF-8
45
- string: body2 response
46
- http_version: "1.1"
47
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
48
- recorded_with: VCR 2.0.0
49
- """
50
-
51
- Scenario Outline: Replay interaction that matches the body as JSON
52
- And a file named "body_as_json_matching.rb" with:
53
- """ruby
54
- include_http_adapter_for("<http_lib>")
55
-
56
- require 'vcr'
57
-
58
- VCR.configure do |c|
59
- <configuration>
60
- c.cassette_library_dir = 'cassettes'
61
- end
62
-
63
- VCR.use_cassette('example', :match_requests_on => [:body_as_json]) do
64
- puts "Response for body as json 2: " + response_body_for(:put, "http://example.com/", '{ "a" : "1", "b" : "2" }')
65
- end
66
-
67
- VCR.use_cassette('example', :match_requests_on => [:body_as_json]) do
68
- puts "Response for body as json 1: " + response_body_for(:put, "http://example.com/", '{ "a" : "1" }')
69
- end
70
- """
71
- When I run `ruby body_as_json_matching.rb`
72
- Then it should pass with:
73
- """
74
- Response for body as json 2: body2 response
75
- Response for body as json 1: body1 response
76
- """
77
-
78
- Examples:
79
- | configuration | http_lib |
80
- | c.hook_into :fakeweb | net/http |
81
- | c.hook_into :webmock | net/http |
82
- | c.hook_into :webmock | httpclient |
83
- | c.hook_into :webmock | curb |
84
- | c.hook_into :webmock | patron |
85
- | c.hook_into :webmock | em-http-request |
86
- | c.hook_into :webmock | typhoeus |
87
- | c.hook_into :typhoeus | typhoeus |
88
- | c.hook_into :excon | excon |
89
- | c.hook_into :faraday | faraday (w/ net_http) |
90
- | c.hook_into :faraday | faraday (w/ typhoeus) |
@@ -1,135 +0,0 @@
1
- Feature: Register and use a custom matcher
2
-
3
- If the built-in matchers do not meet your needs, you can use a custom matcher.
4
-
5
- Any 2-argument callable (that is, an object that responds to #call and accepts
6
- 2 arguments) can be a matcher. Simply put the callable in your
7
- `:match_requests_on` array.
8
-
9
- In addition, you can register a named custom matcher with VCR, and use
10
- the name in your `:match_requests_on` array.
11
-
12
- Either way, your custom matcher should return a truthy value if the
13
- given requests should be considered equivalent.
14
-
15
- Background:
16
- Given a previously recorded cassette file "cassettes/example.yml" with:
17
- """
18
- ---
19
- http_interactions:
20
- - request:
21
- method: get
22
- uri: http://foo.com:9000/foo
23
- body:
24
- encoding: UTF-8
25
- string: ""
26
- headers: {}
27
- response:
28
- status:
29
- code: 200
30
- message: OK
31
- headers:
32
- Content-Length:
33
- - "18"
34
- body:
35
- encoding: UTF-8
36
- string: port 9000 response
37
- http_version: "1.1"
38
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
39
- - request:
40
- method: get
41
- uri: http://foo.com:8000/foo
42
- body:
43
- encoding: UTF-8
44
- string: ""
45
- headers: {}
46
- response:
47
- status:
48
- code: 200
49
- message: OK
50
- headers:
51
- Content-Length:
52
- - "18"
53
- body:
54
- encoding: UTF-8
55
- string: port 8000 response
56
- http_version: "1.1"
57
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
58
- recorded_with: VCR 2.0.0
59
- """
60
-
61
- Scenario Outline: Use a callable as a custom request matcher
62
- And a file named "callable_matcher.rb" with:
63
- """ruby
64
- include_http_adapter_for("<http_lib>")
65
-
66
- require 'vcr'
67
-
68
- VCR.configure do |c|
69
- <configuration>
70
- c.cassette_library_dir = 'cassettes'
71
- end
72
-
73
- port_matcher = lambda do |request_1, request_2|
74
- URI(request_1.uri).port == URI(request_2.uri).port
75
- end
76
-
77
- VCR.use_cassette('example', :match_requests_on => [:method, port_matcher]) do
78
- puts "Response for port 8000: " + response_body_for(:get, "http://example.com:8000/")
79
- end
80
-
81
- VCR.use_cassette('example', :match_requests_on => [:method, port_matcher]) do
82
- puts "Response for port 9000: " + response_body_for(:get, "http://example.com:9000/")
83
- end
84
- """
85
- When I run `ruby callable_matcher.rb`
86
- Then it should pass with:
87
- """
88
- Response for port 8000: port 8000 response
89
- Response for port 9000: port 9000 response
90
- """
91
-
92
- Examples:
93
- | configuration | http_lib |
94
- | c.hook_into :fakeweb | net/http |
95
- | c.hook_into :webmock | net/http |
96
- | c.hook_into :webmock | httpclient |
97
- | c.hook_into :webmock | curb |
98
- | c.hook_into :webmock | patron |
99
- | c.hook_into :webmock | em-http-request |
100
- | c.hook_into :webmock | typhoeus |
101
- | c.hook_into :typhoeus | typhoeus |
102
- | c.hook_into :excon | excon |
103
- | c.hook_into :faraday | faraday (w/ net_http) |
104
- | c.hook_into :faraday | faraday (w/ typhoeus) |
105
-
106
- Scenario: Register a named custom matcher
107
- And a file named "register_custom_matcher.rb" with:
108
- """ruby
109
- include_http_adapter_for("net/http")
110
-
111
- require 'vcr'
112
-
113
- VCR.configure do |c|
114
- c.hook_into :webmock
115
- c.cassette_library_dir = 'cassettes'
116
- c.register_request_matcher :port do |request_1, request_2|
117
- URI(request_1.uri).port == URI(request_2.uri).port
118
- end
119
- end
120
-
121
- VCR.use_cassette('example', :match_requests_on => [:method, :port]) do
122
- puts "Response for port 8000: " + response_body_for(:get, "http://example.com:8000/")
123
- end
124
-
125
- VCR.use_cassette('example', :match_requests_on => [:method, :port]) do
126
- puts "Response for port 9000: " + response_body_for(:get, "http://example.com:9000/")
127
- end
128
- """
129
- When I run `ruby register_custom_matcher.rb`
130
- Then it should pass with:
131
- """
132
- Response for port 8000: port 8000 response
133
- Response for port 9000: port 9000 response
134
- """
135
-
@@ -1,85 +0,0 @@
1
- Feature: Matching on Headers
2
-
3
- Use the `:headers` request matcher to match requests on the request headers.
4
-
5
- Scenario Outline: Replay interaction that matches the headers
6
- Given a previously recorded cassette file "cassettes/example.yml" with:
7
- """
8
- ---
9
- http_interactions:
10
- - request:
11
- method: post
12
- uri: http://example.net/some/long/path
13
- body:
14
- encoding: UTF-8
15
- string: ""
16
- headers:
17
- X-User-Id:
18
- - "1"
19
- response:
20
- status:
21
- code: 200
22
- message: OK
23
- headers:
24
- Content-Length:
25
- - "15"
26
- body:
27
- encoding: UTF-8
28
- string: user 1 response
29
- http_version: "1.1"
30
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
31
- - request:
32
- method: post
33
- uri: http://example.net/some/long/path
34
- body:
35
- encoding: UTF-8
36
- string: ""
37
- headers:
38
- X-User-Id:
39
- - "2"
40
- response:
41
- status:
42
- code: 200
43
- message: OK
44
- headers:
45
- Content-Length:
46
- - "15"
47
- body:
48
- encoding: UTF-8
49
- string: user 2 response
50
- http_version: "1.1"
51
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
52
- recorded_with: VCR 2.0.0
53
- """
54
- And a file named "header_matching.rb" with:
55
- """ruby
56
- include_http_adapter_for("<http_lib>")
57
-
58
- require 'vcr'
59
-
60
- VCR.configure do |c|
61
- <configuration>
62
- c.cassette_library_dir = 'cassettes'
63
- end
64
-
65
- VCR.use_cassette('example', :match_requests_on => [:headers]) do
66
- puts "Response for user 2: " + response_body_for(:get, "http://example.com/", nil, 'X-User-Id' => '2')
67
- end
68
-
69
- VCR.use_cassette('example', :match_requests_on => [:headers]) do
70
- puts "Response for user 1: " + response_body_for(:get, "http://example.com/", nil, 'X-User-Id' => '1')
71
- end
72
- """
73
- When I run `ruby header_matching.rb`
74
- Then it should pass with:
75
- """
76
- Response for user 2: user 2 response
77
- Response for user 1: user 1 response
78
- """
79
-
80
- Examples:
81
- | configuration | http_lib |
82
- | c.hook_into :webmock | curb |
83
- | c.hook_into :webmock | patron |
84
- | c.hook_into :webmock | em-http-request |
85
-