vcr 2.0.0.beta1 → 2.0.0.beta2

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 (88) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +37 -2
  4. data/Gemfile +2 -2
  5. data/README.md +10 -1
  6. data/Rakefile +43 -7
  7. data/Upgrade.md +45 -0
  8. data/features/.nav +1 -0
  9. data/features/cassettes/automatic_re_recording.feature +19 -17
  10. data/features/cassettes/dynamic_erb.feature +32 -28
  11. data/features/cassettes/exclusive.feature +28 -24
  12. data/features/cassettes/format.feature +213 -31
  13. data/features/cassettes/update_content_length_header.feature +20 -18
  14. data/features/configuration/filter_sensitive_data.feature +4 -4
  15. data/features/configuration/hooks.feature +27 -23
  16. data/features/http_libraries/em_http_request.feature +79 -75
  17. data/features/record_modes/all.feature +14 -14
  18. data/features/record_modes/new_episodes.feature +15 -15
  19. data/features/record_modes/none.feature +15 -15
  20. data/features/record_modes/once.feature +15 -15
  21. data/features/request_matching/body.feature +25 -23
  22. data/features/request_matching/custom_matcher.feature +25 -23
  23. data/features/request_matching/headers.feature +32 -36
  24. data/features/request_matching/host.feature +27 -25
  25. data/features/request_matching/identical_request_sequence.feature +27 -25
  26. data/features/request_matching/method.feature +27 -25
  27. data/features/request_matching/path.feature +27 -25
  28. data/features/request_matching/playback_repeats.feature +27 -25
  29. data/features/request_matching/uri.feature +27 -25
  30. data/features/request_matching/uri_without_param.feature +28 -26
  31. data/features/step_definitions/cli_steps.rb +71 -17
  32. data/features/support/env.rb +3 -1
  33. data/features/support/http_lib_filters.rb +6 -3
  34. data/features/support/vcr_cucumber_helpers.rb +4 -2
  35. data/lib/vcr.rb +6 -2
  36. data/lib/vcr/cassette.rb +75 -51
  37. data/lib/vcr/cassette/migrator.rb +111 -0
  38. data/lib/vcr/cassette/serializers.rb +35 -0
  39. data/lib/vcr/cassette/serializers/json.rb +23 -0
  40. data/lib/vcr/cassette/serializers/psych.rb +24 -0
  41. data/lib/vcr/cassette/serializers/syck.rb +35 -0
  42. data/lib/vcr/cassette/serializers/yaml.rb +24 -0
  43. data/lib/vcr/configuration.rb +6 -1
  44. data/lib/vcr/errors.rb +1 -1
  45. data/lib/vcr/library_hooks/excon.rb +1 -7
  46. data/lib/vcr/library_hooks/typhoeus.rb +6 -22
  47. data/lib/vcr/library_hooks/webmock.rb +1 -1
  48. data/lib/vcr/middleware/faraday.rb +1 -1
  49. data/lib/vcr/request_matcher_registry.rb +43 -30
  50. data/lib/vcr/structs.rb +209 -0
  51. data/lib/vcr/tasks/vcr.rake +9 -0
  52. data/lib/vcr/version.rb +1 -1
  53. data/spec/fixtures/cassette_spec/1_x_cassette.yml +110 -0
  54. data/spec/fixtures/cassette_spec/example.yml +79 -78
  55. data/spec/fixtures/cassette_spec/with_localhost_requests.yml +79 -77
  56. data/spec/fixtures/fake_example.com_responses.yml +78 -76
  57. data/spec/fixtures/match_requests_on.yml +147 -145
  58. data/spec/monkey_patches.rb +5 -5
  59. data/spec/support/http_library_adapters.rb +48 -0
  60. data/spec/support/shared_example_groups/hook_into_http_library.rb +53 -20
  61. data/spec/support/sinatra_app.rb +12 -0
  62. data/spec/vcr/cassette/http_interaction_list_spec.rb +1 -1
  63. data/spec/vcr/cassette/migrator_spec.rb +183 -0
  64. data/spec/vcr/cassette/serializers_spec.rb +122 -0
  65. data/spec/vcr/cassette_spec.rb +147 -83
  66. data/spec/vcr/configuration_spec.rb +11 -1
  67. data/spec/vcr/library_hooks/typhoeus_spec.rb +3 -3
  68. data/spec/vcr/library_hooks/webmock_spec.rb +7 -1
  69. data/spec/vcr/request_ignorer_spec.rb +1 -1
  70. data/spec/vcr/request_matcher_registry_spec.rb +46 -4
  71. data/spec/vcr/structs_spec.rb +309 -0
  72. data/spec/vcr_spec.rb +7 -0
  73. data/vcr.gemspec +9 -12
  74. metadata +75 -61
  75. data/lib/vcr/structs/http_interaction.rb +0 -58
  76. data/lib/vcr/structs/normalizers/body.rb +0 -24
  77. data/lib/vcr/structs/normalizers/header.rb +0 -64
  78. data/lib/vcr/structs/normalizers/status_message.rb +0 -17
  79. data/lib/vcr/structs/normalizers/uri.rb +0 -34
  80. data/lib/vcr/structs/request.rb +0 -13
  81. data/lib/vcr/structs/response.rb +0 -13
  82. data/lib/vcr/structs/response_status.rb +0 -5
  83. data/lib/vcr/util/yaml.rb +0 -11
  84. data/spec/support/shared_example_groups/normalizers.rb +0 -94
  85. data/spec/vcr/structs/http_interaction_spec.rb +0 -89
  86. data/spec/vcr/structs/request_spec.rb +0 -39
  87. data/spec/vcr/structs/response_spec.rb +0 -44
  88. data/spec/vcr/structs/response_status_spec.rb +0 -9
@@ -2,47 +2,47 @@ Feature: Matching on Headers
2
2
 
3
3
  Use the `:headers` request matcher to match requests on the request headers.
4
4
 
5
- Background:
5
+ Scenario Outline: Replay interaction that matches the headers
6
6
  Given a previously recorded cassette file "cassettes/example.yml" with:
7
7
  """
8
- ---
9
- - !ruby/struct:VCR::HTTPInteraction
10
- request: !ruby/struct:VCR::Request
11
- method: :post
12
- uri: http://example.net:80/some/long/path
13
- body:
14
- headers:
15
- x-user-id:
16
- - "1"
17
- response: !ruby/struct:VCR::Response
18
- status: !ruby/struct:VCR::ResponseStatus
8
+ ---
9
+ http_interactions:
10
+ - request:
11
+ method: post
12
+ uri: http://example.net/some/long/path
13
+ body: ''
14
+ headers:
15
+ X-User-Id:
16
+ - '1'
17
+ response:
18
+ status:
19
19
  code: 200
20
20
  message: OK
21
- headers:
22
- content-length:
23
- - "15"
21
+ headers:
22
+ Content-Length:
23
+ - '15'
24
24
  body: user 1 response
25
- http_version: "1.1"
26
- - !ruby/struct:VCR::HTTPInteraction
27
- request: !ruby/struct:VCR::Request
28
- method: :post
29
- uri: http://example.net:80/some/long/path
30
- body:
31
- headers:
32
- x-user-id:
33
- - "2"
34
- response: !ruby/struct:VCR::Response
35
- status: !ruby/struct:VCR::ResponseStatus
25
+ http_version: '1.1'
26
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
27
+ - request:
28
+ method: post
29
+ uri: http://example.net/some/long/path
30
+ body: ''
31
+ headers:
32
+ X-User-Id:
33
+ - '2'
34
+ response:
35
+ status:
36
36
  code: 200
37
37
  message: OK
38
- headers:
39
- content-length:
40
- - "15"
38
+ headers:
39
+ Content-Length:
40
+ - '15'
41
41
  body: user 2 response
42
- http_version: "1.1"
42
+ http_version: '1.1'
43
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
44
+ recorded_with: VCR 2.0.0
43
45
  """
44
-
45
- Scenario Outline: Replay interaction that matches the headers
46
46
  And a file named "header_matching.rb" with:
47
47
  """ruby
48
48
  include_http_adapter_for("<http_lib>")
@@ -71,14 +71,10 @@ Feature: Matching on Headers
71
71
 
72
72
  Examples:
73
73
  | configuration | http_lib |
74
- | c.hook_into :fakeweb | net/http |
75
- | c.hook_into :webmock | net/http |
76
74
  | c.hook_into :webmock | httpclient |
77
75
  | c.hook_into :webmock | curb |
78
76
  | c.hook_into :webmock | patron |
79
77
  | c.hook_into :webmock | em-http-request |
80
- | c.hook_into :webmock | typhoeus |
81
- | c.hook_into :typhoeus | typhoeus |
82
78
  | c.hook_into :excon | excon |
83
79
  | | faraday (w/ net_http) |
84
80
  | | faraday (w/ typhoeus) |
@@ -9,37 +9,39 @@ Feature: Matching on Host
9
9
  Background:
10
10
  Given a previously recorded cassette file "cassettes/example.yml" with:
11
11
  """
12
- ---
13
- - !ruby/struct:VCR::HTTPInteraction
14
- request: !ruby/struct:VCR::Request
15
- method: :post
16
- uri: http://host1.com:80/some/long/path
17
- body:
18
- headers:
19
- response: !ruby/struct:VCR::Response
20
- status: !ruby/struct:VCR::ResponseStatus
12
+ ---
13
+ http_interactions:
14
+ - request:
15
+ method: post
16
+ uri: http://host1.com/some/long/path
17
+ body: ''
18
+ headers: {}
19
+ response:
20
+ status:
21
21
  code: 200
22
22
  message: OK
23
- headers:
24
- content-length:
25
- - "14"
23
+ headers:
24
+ Content-Length:
25
+ - '14'
26
26
  body: host1 response
27
- http_version: "1.1"
28
- - !ruby/struct:VCR::HTTPInteraction
29
- request: !ruby/struct:VCR::Request
30
- method: :post
31
- uri: http://host2.com:80/some/other/long/path
32
- body:
33
- headers:
34
- response: !ruby/struct:VCR::Response
35
- status: !ruby/struct:VCR::ResponseStatus
27
+ http_version: '1.1'
28
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
29
+ - request:
30
+ method: post
31
+ uri: http://host2.com/some/other/long/path
32
+ body: ''
33
+ headers: {}
34
+ response:
35
+ status:
36
36
  code: 200
37
37
  message: OK
38
- headers:
39
- content-length:
40
- - "16"
38
+ headers:
39
+ Content-Length:
40
+ - '16'
41
41
  body: host2 response
42
- http_version: "1.1"
42
+ http_version: '1.1'
43
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
44
+ recorded_with: VCR 2.0.0
43
45
  """
44
46
 
45
47
  Scenario Outline: Replay interaction that matches the host
@@ -8,37 +8,39 @@ Feature: Identical requests are replayed in sequence
8
8
  Scenario Outline: identical requests are replayed in sequence
9
9
  Given a previously recorded cassette file "cassettes/example.yml" with:
10
10
  """
11
- ---
12
- - !ruby/struct:VCR::HTTPInteraction
13
- request: !ruby/struct:VCR::Request
14
- method: :get
15
- uri: http://example.com:80/foo
16
- body:
17
- headers:
18
- response: !ruby/struct:VCR::Response
19
- status: !ruby/struct:VCR::ResponseStatus
11
+ ---
12
+ http_interactions:
13
+ - request:
14
+ method: get
15
+ uri: http://example.com/foo
16
+ body: ''
17
+ headers: {}
18
+ response:
19
+ status:
20
20
  code: 200
21
21
  message: OK
22
- headers:
23
- content-length:
24
- - "10"
22
+ headers:
23
+ Content-Length:
24
+ - '10'
25
25
  body: Response 1
26
- http_version: "1.1"
27
- - !ruby/struct:VCR::HTTPInteraction
28
- request: !ruby/struct:VCR::Request
29
- method: :get
30
- uri: http://example.com:80/foo
31
- body:
32
- headers:
33
- response: !ruby/struct:VCR::Response
34
- status: !ruby/struct:VCR::ResponseStatus
26
+ http_version: '1.1'
27
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
28
+ - request:
29
+ method: get
30
+ uri: http://example.com/foo
31
+ body: ''
32
+ headers: {}
33
+ response:
34
+ status:
35
35
  code: 200
36
36
  message: OK
37
- headers:
38
- content-length:
39
- - "10"
37
+ headers:
38
+ Content-Length:
39
+ - '10'
40
40
  body: Response 2
41
- http_version: "1.1"
41
+ http_version: '1.1'
42
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
43
+ recorded_with: VCR 2.0.0
42
44
  """
43
45
  And a file named "rotate_responses.rb" with:
44
46
  """ruby
@@ -10,37 +10,39 @@ Feature: Matching on Method
10
10
  Background:
11
11
  Given a previously recorded cassette file "cassettes/example.yml" with:
12
12
  """
13
- ---
14
- - !ruby/struct:VCR::HTTPInteraction
15
- request: !ruby/struct:VCR::Request
16
- method: :post
17
- uri: http://post-request.com:80/
18
- body:
19
- headers:
20
- response: !ruby/struct:VCR::Response
21
- status: !ruby/struct:VCR::ResponseStatus
13
+ ---
14
+ http_interactions:
15
+ - request:
16
+ method: post
17
+ uri: http://post-request.com/
18
+ body: ''
19
+ headers: {}
20
+ response:
21
+ status:
22
22
  code: 200
23
23
  message: OK
24
- headers:
25
- content-length:
26
- - "13"
24
+ headers:
25
+ Content-Length:
26
+ - '13'
27
27
  body: post response
28
- http_version: "1.1"
29
- - !ruby/struct:VCR::HTTPInteraction
30
- request: !ruby/struct:VCR::Request
31
- method: :get
32
- uri: http://get-request.com:80/
33
- body:
34
- headers:
35
- response: !ruby/struct:VCR::Response
36
- status: !ruby/struct:VCR::ResponseStatus
28
+ http_version: '1.1'
29
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
30
+ - request:
31
+ method: get
32
+ uri: http://get-request.com/
33
+ body: ''
34
+ headers: {}
35
+ response:
36
+ status:
37
37
  code: 200
38
38
  message: OK
39
- headers:
40
- content-length:
41
- - "12"
39
+ headers:
40
+ Content-Length:
41
+ - '12'
42
42
  body: get response
43
- http_version: "1.1"
43
+ http_version: '1.1'
44
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
45
+ recorded_with: VCR 2.0.0
44
46
  """
45
47
 
46
48
  Scenario Outline: Replay interaction that matches the HTTP method
@@ -10,37 +10,39 @@ Feature: Matching on Path
10
10
  Background:
11
11
  Given a previously recorded cassette file "cassettes/example.yml" with:
12
12
  """
13
- ---
14
- - !ruby/struct:VCR::HTTPInteraction
15
- request: !ruby/struct:VCR::Request
16
- method: :post
17
- uri: http://host1.com:80/about?date=2011-09-01
18
- body:
19
- headers:
20
- response: !ruby/struct:VCR::Response
21
- status: !ruby/struct:VCR::ResponseStatus
13
+ ---
14
+ http_interactions:
15
+ - request:
16
+ method: post
17
+ uri: http://host1.com/about?date=2011-09-01
18
+ body: ''
19
+ headers: {}
20
+ response:
21
+ status:
22
22
  code: 200
23
23
  message: OK
24
- headers:
25
- content-length:
26
- - "14"
24
+ headers:
25
+ Content-Length:
26
+ - '14'
27
27
  body: about response
28
- http_version: "1.1"
29
- - !ruby/struct:VCR::HTTPInteraction
30
- request: !ruby/struct:VCR::Request
31
- method: :post
32
- uri: http://host2.com:80/home?date=2011-09-01
33
- body:
34
- headers:
35
- response: !ruby/struct:VCR::Response
36
- status: !ruby/struct:VCR::ResponseStatus
28
+ http_version: '1.1'
29
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
30
+ - request:
31
+ method: post
32
+ uri: http://host2.com/home?date=2011-09-01
33
+ body: ''
34
+ headers: {}
35
+ response:
36
+ status:
37
37
  code: 200
38
38
  message: OK
39
- headers:
40
- content-length:
41
- - "15"
39
+ headers:
40
+ Content-Length:
41
+ - '15'
42
42
  body: home response
43
- http_version: "1.1"
43
+ http_version: '1.1'
44
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
45
+ recorded_with: VCR 2.0.0
44
46
  """
45
47
 
46
48
  Scenario Outline: Replay interaction that matches the path
@@ -15,37 +15,39 @@ Feature: Playback repeats
15
15
  Scenario: Responses do not repeat by default
16
16
  Given a previously recorded cassette file "cassettes/example.yml" with:
17
17
  """
18
- ---
19
- - !ruby/struct:VCR::HTTPInteraction
20
- request: !ruby/struct:VCR::Request
21
- method: :get
22
- uri: http://example.com:80/foo
23
- body:
24
- headers:
25
- response: !ruby/struct:VCR::Response
26
- status: !ruby/struct:VCR::ResponseStatus
18
+ ---
19
+ http_interactions:
20
+ - request:
21
+ method: get
22
+ uri: http://example.com/foo
23
+ body: ''
24
+ headers: {}
25
+ response:
26
+ status:
27
27
  code: 200
28
28
  message: OK
29
- headers:
30
- content-length:
31
- - "10"
29
+ headers:
30
+ Content-Length:
31
+ - '10'
32
32
  body: Response 1
33
- http_version: "1.1"
34
- - !ruby/struct:VCR::HTTPInteraction
35
- request: !ruby/struct:VCR::Request
36
- method: :get
37
- uri: http://example.com:80/foo
38
- body:
39
- headers:
40
- response: !ruby/struct:VCR::Response
41
- status: !ruby/struct:VCR::ResponseStatus
33
+ http_version: '1.1'
34
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
35
+ - request:
36
+ method: get
37
+ uri: http://example.com/foo
38
+ body: ''
39
+ headers: {}
40
+ response:
41
+ status:
42
42
  code: 200
43
43
  message: OK
44
- headers:
45
- content-length:
46
- - "10"
44
+ headers:
45
+ Content-Length:
46
+ - '10'
47
47
  body: Response 2
48
- http_version: "1.1"
48
+ http_version: '1.1'
49
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
50
+ recorded_with: VCR 2.0.0
49
51
  """
50
52
  And a file named "playback_repeats.rb" with:
51
53
  """ruby
@@ -8,37 +8,39 @@ Feature: Matching on URI
8
8
  Background:
9
9
  Given a previously recorded cassette file "cassettes/example.yml" with:
10
10
  """
11
- ---
12
- - !ruby/struct:VCR::HTTPInteraction
13
- request: !ruby/struct:VCR::Request
14
- method: :post
15
- uri: http://example.com:80/foo
16
- body:
17
- headers:
18
- response: !ruby/struct:VCR::Response
19
- status: !ruby/struct:VCR::ResponseStatus
11
+ ---
12
+ http_interactions:
13
+ - request:
14
+ method: post
15
+ uri: http://example.com/foo
16
+ body: ''
17
+ headers: {}
18
+ response:
19
+ status:
20
20
  code: 200
21
21
  message: OK
22
- headers:
23
- content-length:
24
- - "12"
22
+ headers:
23
+ Content-Length:
24
+ - '12'
25
25
  body: foo response
26
- http_version: "1.1"
27
- - !ruby/struct:VCR::HTTPInteraction
28
- request: !ruby/struct:VCR::Request
29
- method: :post
30
- uri: http://example.com:80/bar
31
- body:
32
- headers:
33
- response: !ruby/struct:VCR::Response
34
- status: !ruby/struct:VCR::ResponseStatus
26
+ http_version: '1.1'
27
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
28
+ - request:
29
+ method: post
30
+ uri: http://example.com/bar
31
+ body: ''
32
+ headers: {}
33
+ response:
34
+ status:
35
35
  code: 200
36
36
  message: OK
37
- headers:
38
- content-length:
39
- - "12"
37
+ headers:
38
+ Content-Length:
39
+ - '12'
40
40
  body: bar response
41
- http_version: "1.1"
41
+ http_version: '1.1'
42
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
43
+ recorded_with: VCR 2.0.0
42
44
  """
43
45
 
44
46
  Scenario Outline: Replay interaction that matches the request URI