vcr 0.3.1 → 0.4.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 (70) hide show
  1. data/CHANGELOG.md +62 -0
  2. data/README.md +224 -0
  3. data/Rakefile +12 -5
  4. data/VERSION +1 -1
  5. data/benchmarks/http_stubbing_libraries.rb +59 -0
  6. data/features/fixtures/vcr_cassettes/1.8.6/cucumber_tags/replay_cassette1.yml +25 -25
  7. data/features/fixtures/vcr_cassettes/1.8.6/cucumber_tags/replay_cassette2.yml +32 -30
  8. data/features/fixtures/vcr_cassettes/1.8.6/cucumber_tags/replay_cassette3.yml +40 -40
  9. data/features/fixtures/vcr_cassettes/1.8.6/nested_replay_cassette.yml +16 -15
  10. data/features/fixtures/vcr_cassettes/1.8.6/not_the_real_response.yml +25 -25
  11. data/features/fixtures/vcr_cassettes/1.8.7/cucumber_tags/replay_cassette1.yml +23 -23
  12. data/features/fixtures/vcr_cassettes/1.8.7/cucumber_tags/replay_cassette2.yml +24 -22
  13. data/features/fixtures/vcr_cassettes/1.8.7/cucumber_tags/replay_cassette3.yml +36 -36
  14. data/features/fixtures/vcr_cassettes/1.8.7/nested_replay_cassette.yml +12 -11
  15. data/features/fixtures/vcr_cassettes/1.8.7/not_the_real_response.yml +23 -23
  16. data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette1.yml +24 -24
  17. data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette2.yml +26 -24
  18. data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette3.yml +38 -38
  19. data/features/fixtures/vcr_cassettes/1.9.1/nested_replay_cassette.yml +13 -12
  20. data/features/fixtures/vcr_cassettes/1.9.1/not_the_real_response.yml +24 -24
  21. data/features/record_response.feature +2 -2
  22. data/features/replay_recorded_response.feature +1 -1
  23. data/features/step_definitions/vcr_steps.rb +8 -8
  24. data/features/support/env.rb +6 -0
  25. data/lib/vcr.rb +16 -3
  26. data/lib/vcr/cassette.rb +49 -46
  27. data/lib/vcr/config.rb +8 -0
  28. data/lib/vcr/extensions/fake_web.rb +12 -26
  29. data/lib/vcr/extensions/net_http.rb +9 -26
  30. data/lib/vcr/http_stubbing_adapters/base.rb +34 -0
  31. data/lib/vcr/http_stubbing_adapters/fakeweb.rb +75 -0
  32. data/lib/vcr/http_stubbing_adapters/webmock.rb +80 -0
  33. data/lib/vcr/structs.rb +44 -0
  34. data/lib/vcr/task_runner.rb +47 -0
  35. data/lib/vcr/tasks/vcr.rake +9 -0
  36. data/spec/cassette_spec.rb +70 -71
  37. data/spec/config_spec.rb +27 -0
  38. data/spec/extensions/net_http_spec.rb +21 -17
  39. data/spec/fixtures/1.8.6/0_3_1_cassette.yml +29 -0
  40. data/spec/fixtures/1.8.6/cassette_spec/example.yml +110 -108
  41. data/spec/fixtures/1.8.6/example_net_http.yml +14 -0
  42. data/spec/fixtures/1.8.6/example_net_http_request.yml +12 -0
  43. data/spec/fixtures/1.8.6/example_net_http_response.yml +25 -0
  44. data/spec/fixtures/1.8.6/fake_example.com_responses.yml +90 -0
  45. data/spec/fixtures/1.8.7/0_3_1_cassette.yml +29 -0
  46. data/spec/fixtures/1.8.7/cassette_spec/example.yml +110 -108
  47. data/spec/fixtures/1.8.7/example_net_http.yml +14 -0
  48. data/spec/fixtures/1.8.7/example_net_http_request.yml +12 -0
  49. data/spec/fixtures/1.8.7/example_net_http_response.yml +25 -0
  50. data/spec/fixtures/1.8.7/fake_example.com_responses.yml +90 -0
  51. data/spec/fixtures/1.9.1/0_3_1_cassette.yml +29 -0
  52. data/spec/fixtures/1.9.1/cassette_spec/example.yml +62 -59
  53. data/spec/fixtures/1.9.1/example_net_http.yml +14 -0
  54. data/spec/fixtures/1.9.1/example_net_http_request.yml +12 -0
  55. data/spec/fixtures/1.9.1/example_net_http_response.yml +25 -0
  56. data/spec/fixtures/1.9.1/fake_example.com_responses.yml +90 -0
  57. data/spec/http_stubbing_adapters/fakeweb_spec.rb +24 -0
  58. data/spec/http_stubbing_adapters/webmock_spec.rb +23 -0
  59. data/spec/spec_helper.rb +5 -0
  60. data/spec/structs_spec.rb +95 -0
  61. data/spec/support/http_stubbing_adapter.rb +113 -0
  62. data/spec/task_runner_spec.rb +59 -0
  63. data/spec/vcr_spec.rb +37 -0
  64. data/vcr.gemspec +45 -15
  65. metadata +67 -26
  66. data/History.rdoc +0 -31
  67. data/README.rdoc +0 -222
  68. data/lib/vcr/recorded_response.rb +0 -4
  69. data/spec/extensions/fake_web_spec.rb +0 -63
  70. data/spec/recorded_response_spec.rb +0 -25
@@ -1,12 +1,15 @@
1
1
  ---
2
- - !ruby/struct:VCR::RecordedResponse
3
- method: :get
4
- uri: http://example.com:80/nested
5
- response: !ruby/object:Net::HTTPNotFound
6
- body: The nested response
7
- body_exist: true
8
- code: "404"
9
- header:
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://example.com:80/nested
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 404
11
+ message: Not Found
12
+ headers:
10
13
  content-type:
11
14
  - text/html; charset=iso-8859-1
12
15
  connection:
@@ -17,7 +20,5 @@
17
20
  - Thu, 25 Feb 2010 15:19:40 GMT
18
21
  content-length:
19
22
  - "280"
23
+ body: The nested response
20
24
  http_version: "1.1"
21
- message: Not Found
22
- read: true
23
- socket:
@@ -1,24 +1,15 @@
1
1
  ---
2
- - !ruby/struct:VCR::RecordedResponse
3
- method: :get
4
- uri: http://example.com:80/
5
- response: !ruby/object:Net::HTTPOK
6
- body: |
7
- <HTML>
8
- <HEAD>
9
- <TITLE>Example Web Page</TITLE>
10
- </HEAD>
11
- <body>
12
- <p>
13
- This is not the real response from example.com
14
- </p>
15
- </BODY>
16
- </HTML>
17
-
18
-
19
- body_exist: true
20
- code: "200"
21
- header:
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://example.com:80/
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
22
13
  etag:
23
14
  - "\"24ec5-1b6-4059a80bfd280\""
24
15
  last-modified:
@@ -37,7 +28,16 @@
37
28
  - "2546"
38
29
  accept-ranges:
39
30
  - bytes
31
+ body: |
32
+ <HTML>
33
+ <HEAD>
34
+ <TITLE>Example Web Page</TITLE>
35
+ </HEAD>
36
+ <body>
37
+ <p>
38
+ This is not the real response from example.com
39
+ </p>
40
+ </BODY>
41
+ </HTML>
42
+
40
43
  http_version: "1.1"
41
- message: OK
42
- read: true
43
- socket:
@@ -1,24 +1,15 @@
1
1
  ---
2
- - !ruby/struct:VCR::RecordedResponse
3
- :method: :get
4
- :uri: http://example.com:80/
5
- :response: !ruby/object:Net::HTTPOK
6
- body: |
7
- <HTML>
8
- <HEAD>
9
- <TITLE>Example Web Page</TITLE>
10
- </HEAD>
11
- <body>
12
- <p>
13
- This is not the real response from example.com
14
- </p>
15
- </BODY>
16
- </HTML>
17
-
18
-
19
- body_exist: true
20
- code: "200"
21
- header:
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ :request: !ruby/struct:VCR::Request
4
+ :method: :get
5
+ :uri: http://example.com:80/
6
+ :body:
7
+ :headers:
8
+ :response: !ruby/struct:VCR::Response
9
+ :status: !ruby/struct:VCR::ResponseStatus
10
+ :code: 200
11
+ :message: OK
12
+ :headers:
22
13
  server:
23
14
  - Apache/2.2.3 (Red Hat)
24
15
  last-modified:
@@ -37,7 +28,16 @@
37
28
  - "1696"
38
29
  content-length:
39
30
  - "438"
40
- http_version: "1.1"
41
- message: OK
42
- read: true
43
- socket:
31
+ :body: |
32
+ <HTML>
33
+ <HEAD>
34
+ <TITLE>Example Web Page</TITLE>
35
+ </HEAD>
36
+ <body>
37
+ <p>
38
+ This is not the real response from example.com
39
+ </p>
40
+ </BODY>
41
+ </HTML>
42
+
43
+ :http_version: "1.1"
@@ -1,12 +1,15 @@
1
1
  ---
2
- - !ruby/struct:VCR::RecordedResponse
3
- :method: :get
4
- :uri: http://example.com:80/before_nested
5
- :response: !ruby/object:Net::HTTPOK
6
- body: The before_nested response
7
- body_exist: true
8
- code: "200"
9
- header:
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ :request: !ruby/struct:VCR::Request
4
+ :method: :get
5
+ :uri: http://example.com:80/before_nested
6
+ :body:
7
+ :headers:
8
+ :response: !ruby/struct:VCR::Response
9
+ :status: !ruby/struct:VCR::ResponseStatus
10
+ :code: 200
11
+ :message: OK
12
+ :headers:
10
13
  server:
11
14
  - Apache/2.2.3 (Red Hat)
12
15
  last-modified:
@@ -25,18 +28,19 @@
25
28
  - "1696"
26
29
  content-length:
27
30
  - "438"
28
- http_version: "1.1"
29
- message: OK
30
- read: true
31
- socket:
32
- - !ruby/struct:VCR::RecordedResponse
33
- :method: :get
34
- :uri: http://example.com:80/after_nested
35
- :response: !ruby/object:Net::HTTPOK
36
- body: The after_nested response
37
- body_exist: true
38
- code: "200"
39
- header:
31
+ :body: The before_nested response
32
+ :http_version: "1.1"
33
+ - !ruby/struct:VCR::HTTPInteraction
34
+ :request: !ruby/struct:VCR::Request
35
+ :method: :get
36
+ :uri: http://example.com:80/after_nested
37
+ :body:
38
+ :headers:
39
+ :response: !ruby/struct:VCR::Response
40
+ :status: !ruby/struct:VCR::ResponseStatus
41
+ :code: 200
42
+ :message: OK
43
+ :headers:
40
44
  server:
41
45
  - Apache/2.2.3 (Red Hat)
42
46
  last-modified:
@@ -55,7 +59,5 @@
55
59
  - "1696"
56
60
  content-length:
57
61
  - "438"
58
- http_version: "1.1"
59
- message: OK
60
- read: true
61
- socket:
62
+ :body: The after_nested response
63
+ :http_version: "1.1"
@@ -1,24 +1,15 @@
1
1
  ---
2
- - !ruby/struct:VCR::RecordedResponse
3
- :method: :get
4
- :uri: http://example.com:80/
5
- :response: !ruby/object:Net::HTTPOK
6
- body: |
7
- <HTML>
8
- <HEAD>
9
- <TITLE>Example Web Page</TITLE>
10
- </HEAD>
11
- <body>
12
- <p>
13
- This is not the real response from example.com
14
- </p>
15
- </BODY>
16
- </HTML>
17
-
18
-
19
- body_exist: true
20
- code: "200"
21
- header:
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ :request: !ruby/struct:VCR::Request
4
+ :method: :get
5
+ :uri: http://example.com:80/
6
+ :body:
7
+ :headers:
8
+ :response: !ruby/struct:VCR::Response
9
+ :status: !ruby/struct:VCR::ResponseStatus
10
+ :code: 200
11
+ :message: OK
12
+ :headers:
22
13
  server:
23
14
  - Apache/2.2.3 (Red Hat)
24
15
  last-modified:
@@ -37,30 +28,30 @@
37
28
  - "1696"
38
29
  content-length:
39
30
  - "438"
40
- http_version: "1.1"
41
- message: OK
42
- read: true
43
- socket:
44
- - !ruby/struct:VCR::RecordedResponse
45
- :method: :get
46
- :uri: http://example.com:80/
47
- :response: !ruby/object:Net::HTTPOK
48
- body: |
31
+ :body: |
49
32
  <HTML>
50
33
  <HEAD>
51
34
  <TITLE>Example Web Page</TITLE>
52
35
  </HEAD>
53
36
  <body>
54
37
  <p>
55
- This is another fake response from example.com
38
+ This is not the real response from example.com
56
39
  </p>
57
40
  </BODY>
58
41
  </HTML>
59
-
60
42
 
61
- body_exist: true
62
- code: "200"
63
- header:
43
+ :http_version: "1.1"
44
+ - !ruby/struct:VCR::HTTPInteraction
45
+ :request: !ruby/struct:VCR::Request
46
+ :method: :get
47
+ :uri: http://example.com:80/
48
+ :body:
49
+ :headers:
50
+ :response: !ruby/struct:VCR::Response
51
+ :status: !ruby/struct:VCR::ResponseStatus
52
+ :code: 200
53
+ :message: OK
54
+ :headers:
64
55
  server:
65
56
  - Apache/2.2.3 (Red Hat)
66
57
  last-modified:
@@ -79,7 +70,16 @@
79
70
  - "1696"
80
71
  content-length:
81
72
  - "438"
82
- http_version: "1.1"
83
- message: OK
84
- read: true
85
- socket:
73
+ :body: |
74
+ <HTML>
75
+ <HEAD>
76
+ <TITLE>Example Web Page</TITLE>
77
+ </HEAD>
78
+ <body>
79
+ <p>
80
+ This is another fake response from example.com
81
+ </p>
82
+ </BODY>
83
+ </HTML>
84
+
85
+ :http_version: "1.1"
@@ -1,12 +1,15 @@
1
1
  ---
2
- - !ruby/struct:VCR::RecordedResponse
3
- :method: :get
4
- :uri: http://example.com:80/nested
5
- :response: !ruby/object:Net::HTTPOK
6
- body: The nested response
7
- body_exist: true
8
- code: "200"
9
- header:
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ :request: !ruby/struct:VCR::Request
4
+ :method: :get
5
+ :uri: http://example.com:80/nested
6
+ :body:
7
+ :headers:
8
+ :response: !ruby/struct:VCR::Response
9
+ :status: !ruby/struct:VCR::ResponseStatus
10
+ :code: 200
11
+ :message: OK
12
+ :headers:
10
13
  server:
11
14
  - Apache/2.2.3 (Red Hat)
12
15
  last-modified:
@@ -25,7 +28,5 @@
25
28
  - "1696"
26
29
  content-length:
27
30
  - "438"
28
- http_version: "1.1"
29
- message: OK
30
- read: true
31
- socket:
31
+ :body: The nested response
32
+ :http_version: "1.1"
@@ -1,24 +1,15 @@
1
1
  ---
2
- - !ruby/struct:VCR::RecordedResponse
3
- :method: :get
4
- :uri: http://example.com:80/
5
- :response: !ruby/object:Net::HTTPOK
6
- body: |
7
- <HTML>
8
- <HEAD>
9
- <TITLE>Example Web Page</TITLE>
10
- </HEAD>
11
- <body>
12
- <p>
13
- This is not the real response from example.com
14
- </p>
15
- </BODY>
16
- </HTML>
17
-
18
-
19
- body_exist: true
20
- code: "200"
21
- header:
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ :request: !ruby/struct:VCR::Request
4
+ :method: :get
5
+ :uri: http://example.com:80/
6
+ :body:
7
+ :headers:
8
+ :response: !ruby/struct:VCR::Response
9
+ :status: !ruby/struct:VCR::ResponseStatus
10
+ :code: 200
11
+ :message: OK
12
+ :headers:
22
13
  server:
23
14
  - Apache/2.2.3 (Red Hat)
24
15
  last-modified:
@@ -37,7 +28,16 @@
37
28
  - "1696"
38
29
  content-length:
39
30
  - "438"
40
- http_version: "1.1"
41
- message: OK
42
- read: true
43
- socket:
31
+ :body: |
32
+ <HTML>
33
+ <HEAD>
34
+ <TITLE>Example Web Page</TITLE>
35
+ </HEAD>
36
+ <body>
37
+ <p>
38
+ This is not the real response from example.com
39
+ </p>
40
+ </BODY>
41
+ </HTML>
42
+
43
+ :http_version: "1.1"
@@ -1,7 +1,7 @@
1
1
  Feature: Record response
2
2
  In order to have deterministic, fast tests that do not depend on an internet connection
3
3
  As a TDD/BDD developer
4
- I want to record responses for requests to URIs that are not registered with fakeweb so I can use them with fakeweb in the future
4
+ I want to record responses for new requests so I can replay them in future test runs
5
5
 
6
6
  Scenario: Record a response using VCR.use_cassette
7
7
  Given we do not have a "temp/cassette" cassette
@@ -43,7 +43,7 @@ Feature: Record response
43
43
  Scenario: Make an HTTP request in a cassette with record mode set to :none
44
44
  Given we do not have a "temp/record_none_cassette" cassette
45
45
  When I make an HTTP get request to "http://example.com" within the "temp/record_none_cassette" none cassette
46
- Then the HTTP get request to "http://example.com" should result in a fakeweb error that mentions VCR
46
+ Then the HTTP get request to "http://example.com" should result in an error that mentions VCR
47
47
  And there should not be a "temp/record_none_cassette" library file
48
48
 
49
49
  @copy_not_the_real_response_to_temp
@@ -42,7 +42,7 @@ Feature: Replay recorded response
42
42
  And we have a "temp/not_the_real_response" library file with no previously recorded response for "http://example.com/foo"
43
43
  When I make HTTP get requests to "http://example.com" and "http://example.com/foo" within the "temp/not_the_real_response" none cassette
44
44
  Then the response for "http://example.com" should match /This is not the real response from example\.com/
45
- And the HTTP get request to "http://example.com/foo" should result in a fakeweb error that mentions VCR
45
+ And the HTTP get request to "http://example.com/foo" should result in an error that mentions VCR
46
46
 
47
47
  @copy_not_the_real_response_to_temp
48
48
  Scenario: Make an HTTP request in a cassette with record mode set to :new_episodes
@@ -9,10 +9,10 @@ module VCRHelpers
9
9
  end
10
10
  end
11
11
 
12
- def recorded_responses_for(cassette_name)
12
+ def recorded_interactions_for(cassette_name)
13
13
  yaml_file = File.join(VCR::Config.cassette_library_dir, "#{cassette_name}.yml")
14
14
  yaml = File.open(yaml_file, 'r') { |f| f.read }
15
- responses = YAML.load(yaml)
15
+ interactions = YAML.load(yaml)
16
16
  end
17
17
 
18
18
  def capture_response(url)
@@ -112,22 +112,22 @@ When /^I make (.*HTTP (?:get|post)) requests? to "([^\"]*)"(?: and "([^\"]*)")?
112
112
  end
113
113
 
114
114
  Then /^the "([^\"]*)" library file should have a response for "([^\"]*)" that matches \/(.+)\/$/ do |cassette_name, url, regex_str|
115
- responses = recorded_responses_for(cassette_name)
116
- responses.should have_expected_response(url, regex_str)
115
+ interactions = recorded_interactions_for(cassette_name)
116
+ interactions.should have_expected_response(url, regex_str)
117
117
  end
118
118
 
119
119
  Then /^the "([^\"]*)" library file should have exactly (\d+) response$/ do |cassette_name, response_count|
120
- responses = recorded_responses_for(cassette_name)
121
- responses.should have(response_count.to_i).responses
120
+ interactions = recorded_interactions_for(cassette_name)
121
+ interactions.should have(response_count.to_i).responses
122
122
  end
123
123
 
124
124
  Then /^I can test the scenario cassette's recorded responses in the next scenario, after the cassette has been ejected$/ do
125
125
  # do nothing...
126
126
  end
127
127
 
128
- Then /^the HTTP get request to "([^\"]*)" should result in a fakeweb error that mentions VCR$/ do |url|
128
+ Then /^the HTTP get request to "([^\"]*)" should result in an error that mentions VCR$/ do |url|
129
129
  result = @http_requests[url][0]
130
- result.should be_instance_of(FakeWeb::NetConnectNotAllowedError)
130
+ result.should be_a(StandardError)
131
131
  result.message.should =~ /VCR/
132
132
  end
133
133