vcr 2.0.0.rc1 → 2.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/.gitignore +2 -0
  2. data/.limited_red +1 -0
  3. data/.travis.yml +10 -1
  4. data/.yardopts +9 -0
  5. data/CHANGELOG.md +51 -1
  6. data/Gemfile +5 -1
  7. data/LICENSE +1 -1
  8. data/README.md +23 -28
  9. data/Rakefile +63 -18
  10. data/Upgrade.md +200 -0
  11. data/features/.nav +2 -0
  12. data/features/cassettes/automatic_re_recording.feature +19 -15
  13. data/features/cassettes/dynamic_erb.feature +12 -4
  14. data/features/cassettes/exclusive.feature +31 -23
  15. data/features/cassettes/format.feature +54 -30
  16. data/features/cassettes/naming.feature +1 -1
  17. data/features/cassettes/update_content_length_header.feature +16 -12
  18. data/features/configuration/allow_http_connections_when_no_cassette.feature +1 -1
  19. data/features/configuration/debug_logging.feature +52 -0
  20. data/features/configuration/filter_sensitive_data.feature +4 -4
  21. data/features/configuration/hook_into.feature +5 -2
  22. data/features/configuration/ignore_request.feature +5 -3
  23. data/features/configuration/preserve_exact_body_bytes.feature +103 -0
  24. data/features/hooks/after_http_request.feature +17 -4
  25. data/features/hooks/around_http_request.feature +2 -1
  26. data/features/hooks/before_http_request.feature +25 -8
  27. data/features/hooks/before_playback.feature +16 -12
  28. data/features/hooks/before_record.feature +2 -2
  29. data/features/http_libraries/em_http_request.feature +82 -58
  30. data/features/http_libraries/net_http.feature +6 -6
  31. data/features/middleware/faraday.feature +2 -1
  32. data/features/middleware/rack.feature +2 -2
  33. data/features/record_modes/all.feature +19 -15
  34. data/features/record_modes/new_episodes.feature +17 -13
  35. data/features/record_modes/none.feature +15 -11
  36. data/features/record_modes/once.feature +16 -12
  37. data/features/request_matching/body.feature +28 -20
  38. data/features/request_matching/custom_matcher.feature +28 -20
  39. data/features/request_matching/headers.feature +34 -26
  40. data/features/request_matching/host.feature +28 -20
  41. data/features/request_matching/identical_request_sequence.feature +28 -20
  42. data/features/request_matching/method.feature +28 -20
  43. data/features/request_matching/path.feature +28 -20
  44. data/features/request_matching/playback_repeats.feature +28 -20
  45. data/features/request_matching/uri.feature +28 -20
  46. data/features/request_matching/uri_without_param.feature +28 -20
  47. data/features/support/env.rb +7 -6
  48. data/features/support/vcr_cucumber_helpers.rb +1 -0
  49. data/features/test_frameworks/cucumber.feature +8 -8
  50. data/features/test_frameworks/rspec_macro.feature +4 -4
  51. data/features/test_frameworks/rspec_metadata.feature +6 -6
  52. data/features/test_frameworks/shoulda.feature +1 -1
  53. data/features/test_frameworks/test_unit.feature +1 -1
  54. data/lib/vcr.rb +156 -5
  55. data/lib/vcr/cassette.rb +80 -30
  56. data/lib/vcr/cassette/http_interaction_list.rb +33 -4
  57. data/lib/vcr/cassette/migrator.rb +2 -3
  58. data/lib/vcr/cassette/reader.rb +1 -0
  59. data/lib/vcr/cassette/serializers.rb +22 -0
  60. data/lib/vcr/cassette/serializers/json.rb +27 -2
  61. data/lib/vcr/cassette/serializers/psych.rb +26 -2
  62. data/lib/vcr/cassette/serializers/syck.rb +28 -2
  63. data/lib/vcr/cassette/serializers/yaml.rb +28 -2
  64. data/lib/vcr/configuration.rb +348 -10
  65. data/lib/vcr/deprecations.rb +8 -0
  66. data/lib/vcr/errors.rb +40 -0
  67. data/lib/vcr/extensions/net_http_response.rb +12 -11
  68. data/lib/vcr/library_hooks.rb +1 -0
  69. data/lib/vcr/library_hooks/excon.rb +24 -3
  70. data/lib/vcr/library_hooks/fakeweb.rb +32 -16
  71. data/lib/vcr/library_hooks/faraday.rb +3 -0
  72. data/lib/vcr/library_hooks/typhoeus.rb +40 -37
  73. data/lib/vcr/library_hooks/webmock.rb +54 -34
  74. data/lib/vcr/middleware/faraday.rb +13 -0
  75. data/lib/vcr/middleware/rack.rb +35 -0
  76. data/lib/vcr/request_handler.rb +60 -8
  77. data/lib/vcr/request_ignorer.rb +1 -0
  78. data/lib/vcr/request_matcher_registry.rb +28 -0
  79. data/lib/vcr/structs.rb +245 -38
  80. data/lib/vcr/test_frameworks/cucumber.rb +10 -0
  81. data/lib/vcr/test_frameworks/rspec.rb +26 -1
  82. data/lib/vcr/util/hooks.rb +29 -27
  83. data/lib/vcr/util/internet_connection.rb +2 -0
  84. data/lib/vcr/util/logger.rb +25 -0
  85. data/lib/vcr/util/variable_args_block_caller.rb +1 -0
  86. data/lib/vcr/util/version_checker.rb +1 -0
  87. data/lib/vcr/version.rb +8 -1
  88. data/spec/capture_warnings.rb +3 -3
  89. data/spec/monkey_patches.rb +28 -13
  90. data/spec/spec_helper.rb +17 -0
  91. data/spec/support/http_library_adapters.rb +7 -4
  92. data/spec/support/shared_example_groups/hook_into_http_library.rb +96 -32
  93. data/spec/support/shared_example_groups/request_hooks.rb +9 -8
  94. data/spec/support/sinatra_app.rb +3 -1
  95. data/spec/support/vcr_localhost_server.rb +1 -0
  96. data/spec/vcr/cassette/http_interaction_list_spec.rb +119 -54
  97. data/spec/vcr/cassette/migrator_spec.rb +19 -6
  98. data/spec/vcr/cassette/serializers_spec.rb +51 -6
  99. data/spec/vcr/cassette_spec.rb +44 -19
  100. data/spec/vcr/configuration_spec.rb +91 -6
  101. data/spec/vcr/library_hooks/excon_spec.rb +54 -16
  102. data/spec/vcr/library_hooks/fakeweb_spec.rb +12 -21
  103. data/spec/vcr/library_hooks/typhoeus_spec.rb +2 -29
  104. data/spec/vcr/library_hooks/webmock_spec.rb +4 -18
  105. data/spec/vcr/middleware/faraday_spec.rb +1 -16
  106. data/spec/vcr/structs_spec.rb +194 -61
  107. data/spec/vcr/test_frameworks/rspec_spec.rb +10 -0
  108. data/spec/vcr/util/hooks_spec.rb +104 -56
  109. data/spec/vcr/util/version_checker_spec.rb +45 -0
  110. data/spec/vcr_spec.rb +11 -0
  111. data/vcr.gemspec +30 -34
  112. metadata +149 -95
  113. data/spec/support/shared_example_groups/version_checking.rb +0 -34
@@ -33,7 +33,7 @@ Feature: Net::HTTP
33
33
  """
34
34
  When I run `ruby vcr_net_http.rb --with-server`
35
35
  Then the output should contain "VCR works with Net::HTTP posts!"
36
- And the file "cassettes/net_http.yml" should contain "body: VCR works with Net::HTTP posts!"
36
+ And the file "cassettes/net_http.yml" should contain "VCR works with Net::HTTP posts!"
37
37
 
38
38
  When I run `ruby vcr_net_http.rb`
39
39
  Then the output should contain "VCR works with Net::HTTP posts!"
@@ -65,7 +65,7 @@ Feature: Net::HTTP
65
65
  """
66
66
  When I run `ruby vcr_net_http.rb --with-server`
67
67
  Then the output should contain "VCR works with Net::HTTP gets!"
68
- And the file "cassettes/net_http.yml" should contain "body: VCR works with Net::HTTP gets!"
68
+ And the file "cassettes/net_http.yml" should contain "VCR works with Net::HTTP gets!"
69
69
 
70
70
  When I run `ruby vcr_net_http.rb`
71
71
  Then the output should contain "VCR works with Net::HTTP gets!"
@@ -97,7 +97,7 @@ Feature: Net::HTTP
97
97
  """
98
98
  When I run `ruby vcr_net_http.rb --with-server`
99
99
  Then the output should contain "VCR works with Net::HTTP gets!"
100
- And the file "cassettes/net_http.yml" should contain "body: VCR works with Net::HTTP gets!"
100
+ And the file "cassettes/net_http.yml" should contain "VCR works with Net::HTTP gets!"
101
101
 
102
102
  When I run `ruby vcr_net_http.rb`
103
103
  Then the output should contain "VCR works with Net::HTTP gets!"
@@ -124,7 +124,7 @@ Feature: Net::HTTP
124
124
  """
125
125
  When I run `ruby vcr_net_http.rb --with-server`
126
126
  Then the output should contain "VCR works with Net::HTTP gets!"
127
- And the file "cassettes/net_http.yml" should contain "body: VCR works with Net::HTTP gets!"
127
+ And the file "cassettes/net_http.yml" should contain "VCR works with Net::HTTP gets!"
128
128
 
129
129
  When I run `ruby vcr_net_http.rb`
130
130
  Then the output should contain "VCR works with Net::HTTP gets!"
@@ -157,9 +157,9 @@ Feature: Net::HTTP
157
157
  """
158
158
  When I run `ruby vcr_https.rb`
159
159
  Then the output should contain "VCR gist"
160
- And the file "cassettes/https.yml" should contain "body: VCR gist"
160
+ And the file "cassettes/https.yml" should contain "VCR gist"
161
161
 
162
- When I modify the file "cassettes/https.yml" to replace "body: VCR gist" with "body: HTTPS replaying works"
162
+ When I modify the file "cassettes/https.yml" to replace "VCR gist" with "HTTPS replaying works"
163
163
  And I run `ruby vcr_https.rb`
164
164
  Then the output should contain "HTTPS replaying works"
165
165
 
@@ -23,6 +23,7 @@ Feature: Faraday middleware
23
23
  require 'vcr'
24
24
 
25
25
  VCR.configure do |c|
26
+ c.default_cassette_options = { :serialize_with => :syck }
26
27
  c.cassette_library_dir = 'cassettes'
27
28
  end
28
29
 
@@ -45,7 +46,7 @@ Feature: Faraday middleware
45
46
  Response 1: Hello foo 1
46
47
  Response 2: Hello foo 1
47
48
  """
48
- And the file "cassettes/example.yml" should contain "body: Hello foo 1"
49
+ And the file "cassettes/example.yml" should contain "Hello foo 1"
49
50
 
50
51
  Examples:
51
52
  | adapter |
@@ -61,7 +61,7 @@ Feature: Rack
61
61
  Response 1: Hello foo 1
62
62
  Response 2: Hello foo 1
63
63
  """
64
- And the file "cassettes/proxied.yml" should contain "body: Hello foo 1"
64
+ And the file "cassettes/proxied.yml" should contain "Hello foo 1"
65
65
 
66
66
  Scenario: Set cassette name based on rack request env
67
67
  Given a file named "proxy_server.rb" with:
@@ -88,5 +88,5 @@ Feature: Rack
88
88
  Response 1: Hello foo 1
89
89
  Response 2: Hello foo 1
90
90
  """
91
- And the file "cassettes/localhost.yml" should contain "body: Hello foo 1"
91
+ And the file "cassettes/localhost.yml" should contain "Hello foo 1"
92
92
 
@@ -26,22 +26,26 @@ Feature: :all
26
26
  """
27
27
  And a previously recorded cassette file "cassettes/example.yml" with:
28
28
  """
29
- ---
30
- http_interactions:
31
- - request:
29
+ ---
30
+ http_interactions:
31
+ - request:
32
32
  method: get
33
33
  uri: http://localhost:7777/
34
- body: ''
34
+ body:
35
+ encoding: UTF-8
36
+ string: ""
35
37
  headers: {}
36
- response:
37
- status:
38
+ response:
39
+ status:
38
40
  code: 200
39
41
  message: OK
40
- headers:
41
- Content-Length:
42
- - '20'
43
- body: old response
44
- http_version: '1.1'
42
+ headers:
43
+ Content-Length:
44
+ - "20"
45
+ body:
46
+ encoding: UTF-8
47
+ string: old response
48
+ http_version: "1.1"
45
49
  recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
46
50
  recorded_with: VCR 2.0.0
47
51
  """
@@ -58,8 +62,8 @@ Feature: :all
58
62
  """
59
63
  When I run `ruby re_record.rb`
60
64
  Then it should pass with "Response: Hello"
61
- And the file "cassettes/example.yml" should contain "body: Hello"
62
- But the file "cassettes/example.yml" should not contain "body: old response"
65
+ And the file "cassettes/example.yml" should contain "Hello"
66
+ But the file "cassettes/example.yml" should not contain "old response"
63
67
 
64
68
  Scenario: Record new request
65
69
  Given a file named "record_new.rb" with:
@@ -74,5 +78,5 @@ Feature: :all
74
78
  When I run `ruby record_new.rb`
75
79
  Then it should pass with "Response: Goodbye"
76
80
  And the file "cassettes/example.yml" should contain each of these:
77
- | body: old response |
78
- | body: Goodbye |
81
+ | old response |
82
+ | Goodbye |
@@ -25,22 +25,26 @@ Feature: :new_episodes
25
25
  """
26
26
  And a previously recorded cassette file "cassettes/example.yml" with:
27
27
  """
28
- ---
29
- http_interactions:
30
- - request:
28
+ ---
29
+ http_interactions:
30
+ - request:
31
31
  method: get
32
32
  uri: http://example.com/foo
33
- body: ''
33
+ body:
34
+ encoding: UTF-8
35
+ string: ""
34
36
  headers: {}
35
- response:
36
- status:
37
+ response:
38
+ status:
37
39
  code: 200
38
40
  message: OK
39
- headers:
40
- Content-Length:
41
- - '20'
42
- body: example.com response
43
- http_version: '1.1'
41
+ headers:
42
+ Content-Length:
43
+ - "20"
44
+ body:
45
+ encoding: UTF-8
46
+ string: example.com response
47
+ http_version: "1.1"
44
48
  recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
45
49
  recorded_with: VCR 2.0.0
46
50
  """
@@ -71,5 +75,5 @@ Feature: :new_episodes
71
75
  When I run `ruby record_new_requests.rb`
72
76
  Then it should pass with "Response: Hello"
73
77
  And the file "cassettes/example.yml" should contain each of these:
74
- | body: example.com response |
75
- | body: Hello |
78
+ | example.com response |
79
+ | Hello |
@@ -21,22 +21,26 @@ Feature: :none
21
21
  """
22
22
  And a previously recorded cassette file "cassettes/example.yml" with:
23
23
  """
24
- ---
25
- http_interactions:
26
- - request:
24
+ ---
25
+ http_interactions:
26
+ - request:
27
27
  method: get
28
28
  uri: http://example.com/foo
29
- body: ''
29
+ body:
30
+ encoding: UTF-8
31
+ string: ""
30
32
  headers: {}
31
- response:
32
- status:
33
+ response:
34
+ status:
33
35
  code: 200
34
36
  message: OK
35
- headers:
36
- Content-Length:
37
- - '5'
38
- body: Hello
39
- http_version: '1.1'
37
+ headers:
38
+ Content-Length:
39
+ - "5"
40
+ body:
41
+ encoding: UTF-8
42
+ string: Hello
43
+ http_version: "1.1"
40
44
  recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
41
45
  recorded_with: VCR 2.0.0
42
46
  """
@@ -28,22 +28,26 @@ Feature: :once
28
28
  """
29
29
  And a previously recorded cassette file "cassettes/example.yml" with:
30
30
  """
31
- ---
32
- http_interactions:
33
- - request:
31
+ ---
32
+ http_interactions:
33
+ - request:
34
34
  method: get
35
35
  uri: http://example.com/foo
36
- body: ''
36
+ body:
37
+ encoding: UTF-8
38
+ string: ""
37
39
  headers: {}
38
- response:
39
- status:
40
+ response:
41
+ status:
40
42
  code: 200
41
43
  message: OK
42
- headers:
43
- Content-Length:
44
- - '20'
45
- body: example.com response
46
- http_version: '1.1'
44
+ headers:
45
+ Content-Length:
46
+ - "20"
47
+ body:
48
+ encoding: UTF-8
49
+ string: example.com response
50
+ http_version: "1.1"
47
51
  recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
48
52
  recorded_with: VCR 2.0.0
49
53
  """
@@ -88,4 +92,4 @@ Feature: :once
88
92
  When I remove the file "cassettes/example.yml"
89
93
  And I run `ruby record_new_requests.rb`
90
94
  Then it should pass with "Response: Hello"
91
- And the file "cassettes/example.yml" should contain "body: Hello"
95
+ And the file "cassettes/example.yml" should contain "Hello"
@@ -5,37 +5,45 @@ Feature: Matching on Body
5
5
  Background:
6
6
  Given a previously recorded cassette file "cassettes/example.yml" with:
7
7
  """
8
- ---
9
- http_interactions:
10
- - request:
8
+ ---
9
+ http_interactions:
10
+ - request:
11
11
  method: post
12
12
  uri: http://example.net/some/long/path
13
- body: body1
13
+ body:
14
+ encoding: UTF-8
15
+ string: body1
14
16
  headers: {}
15
- response:
16
- status:
17
+ response:
18
+ status:
17
19
  code: 200
18
20
  message: OK
19
- headers:
20
- Content-Length:
21
- - '14'
22
- body: body1 response
23
- http_version: '1.1'
21
+ headers:
22
+ Content-Length:
23
+ - "14"
24
+ body:
25
+ encoding: UTF-8
26
+ string: body1 response
27
+ http_version: "1.1"
24
28
  recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
25
- - request:
29
+ - request:
26
30
  method: post
27
31
  uri: http://example.net/some/long/path
28
- body: body2
32
+ body:
33
+ encoding: UTF-8
34
+ string: body2
29
35
  headers: {}
30
- response:
31
- status:
36
+ response:
37
+ status:
32
38
  code: 200
33
39
  message: OK
34
- headers:
35
- Content-Length:
36
- - '14'
37
- body: body2 response
38
- http_version: '1.1'
40
+ headers:
41
+ Content-Length:
42
+ - "14"
43
+ body:
44
+ encoding: UTF-8
45
+ string: body2 response
46
+ http_version: "1.1"
39
47
  recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
40
48
  recorded_with: VCR 2.0.0
41
49
  """
@@ -15,37 +15,45 @@ Feature: Register and use a custom matcher
15
15
  Background:
16
16
  Given a previously recorded cassette file "cassettes/example.yml" with:
17
17
  """
18
- ---
19
- http_interactions:
20
- - request:
18
+ ---
19
+ http_interactions:
20
+ - request:
21
21
  method: get
22
22
  uri: http://foo.com:9000/foo
23
- body: ''
23
+ body:
24
+ encoding: UTF-8
25
+ string: ""
24
26
  headers: {}
25
- response:
26
- status:
27
+ response:
28
+ status:
27
29
  code: 200
28
30
  message: OK
29
- headers:
30
- Content-Length:
31
- - '18'
32
- body: port 9000 response
33
- http_version: '1.1'
31
+ headers:
32
+ Content-Length:
33
+ - "18"
34
+ body:
35
+ encoding: UTF-8
36
+ string: port 9000 response
37
+ http_version: "1.1"
34
38
  recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
35
- - request:
39
+ - request:
36
40
  method: get
37
41
  uri: http://foo.com:8000/foo
38
- body: ''
42
+ body:
43
+ encoding: UTF-8
44
+ string: ""
39
45
  headers: {}
40
- response:
41
- status:
46
+ response:
47
+ status:
42
48
  code: 200
43
49
  message: OK
44
- headers:
45
- Content-Length:
46
- - '18'
47
- body: port 8000 response
48
- http_version: '1.1'
50
+ headers:
51
+ Content-Length:
52
+ - "18"
53
+ body:
54
+ encoding: UTF-8
55
+ string: port 8000 response
56
+ http_version: "1.1"
49
57
  recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
50
58
  recorded_with: VCR 2.0.0
51
59
  """
@@ -5,41 +5,49 @@ Feature: Matching on Headers
5
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
- http_interactions:
10
- - request:
8
+ ---
9
+ http_interactions:
10
+ - request:
11
11
  method: post
12
12
  uri: http://example.net/some/long/path
13
- body: ''
14
- headers:
15
- X-User-Id:
16
- - '1'
17
- response:
18
- status:
13
+ body:
14
+ encoding: UTF-8
15
+ string: ""
16
+ headers:
17
+ X-User-Id:
18
+ - "1"
19
+ response:
20
+ status:
19
21
  code: 200
20
22
  message: OK
21
- headers:
22
- Content-Length:
23
- - '15'
24
- body: user 1 response
25
- http_version: '1.1'
23
+ headers:
24
+ Content-Length:
25
+ - "15"
26
+ body:
27
+ encoding: UTF-8
28
+ string: user 1 response
29
+ http_version: "1.1"
26
30
  recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
27
- - request:
31
+ - request:
28
32
  method: post
29
33
  uri: http://example.net/some/long/path
30
- body: ''
31
- headers:
32
- X-User-Id:
33
- - '2'
34
- response:
35
- status:
34
+ body:
35
+ encoding: UTF-8
36
+ string: ""
37
+ headers:
38
+ X-User-Id:
39
+ - "2"
40
+ response:
41
+ status:
36
42
  code: 200
37
43
  message: OK
38
- headers:
39
- Content-Length:
40
- - '15'
41
- body: user 2 response
42
- http_version: '1.1'
44
+ headers:
45
+ Content-Length:
46
+ - "15"
47
+ body:
48
+ encoding: UTF-8
49
+ string: user 2 response
50
+ http_version: "1.1"
43
51
  recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
44
52
  recorded_with: VCR 2.0.0
45
53
  """