vcr 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/.gitmodules +3 -0
- data/CHANGELOG.md +58 -1
- data/Gemfile +2 -4
- data/Gemfile.lock +26 -49
- data/README.md +92 -23
- data/Rakefile +6 -3
- data/features/fixtures/vcr_cassettes/1.9.1/record_all.yml +62 -0
- data/features/fixtures/vcr_cassettes/not_1.9.1/record_all.yml +61 -0
- data/features/http_client.feature +2 -2
- data/features/net_http.feature +15 -4
- data/features/record_response.feature +36 -7
- data/features/replay_recorded_response.feature +8 -8
- data/features/rspec.feature +100 -0
- data/features/step_definitions/net_http_steps.rb +13 -1
- data/features/step_definitions/vcr_steps.rb +26 -16
- data/features/support/env.rb +13 -5
- data/features/webmock.feature +4 -4
- data/lib/vcr.rb +5 -5
- data/lib/vcr/cassette.rb +55 -19
- data/lib/vcr/extensions/net_http.rb +2 -4
- data/lib/vcr/http_stubbing_adapters/fakeweb.rb +0 -4
- data/lib/vcr/http_stubbing_adapters/webmock.rb +2 -9
- data/lib/vcr/internet_connection.rb +13 -0
- data/lib/vcr/ping.rb +26 -0
- data/lib/vcr/rspec.rb +39 -0
- data/lib/vcr/version.rb +1 -1
- data/spec/cassette_spec.rb +160 -69
- data/spec/config_spec.rb +1 -1
- data/spec/cucumber_tags_spec.rb +3 -2
- data/spec/deprecations_spec.rb +1 -1
- data/spec/extensions/net_http_response_spec.rb +2 -4
- data/spec/extensions/net_http_spec.rb +3 -1
- data/spec/fixtures/1.9.1/cassette_spec/with_localhost_requests.yml +23 -0
- data/spec/fixtures/not_1.9.1/cassette_spec/with_localhost_requests.yml +23 -0
- data/spec/http_stubbing_adapters/fakeweb_spec.rb +3 -9
- data/spec/http_stubbing_adapters/webmock_spec.rb +7 -18
- data/spec/internet_connection_spec.rb +19 -0
- data/spec/monkey_patches.rb +45 -6
- data/spec/request_matcher_spec.rb +1 -1
- data/spec/rspec_spec.rb +46 -0
- data/spec/spec_helper.rb +6 -11
- data/spec/structs_spec.rb +1 -1
- data/spec/support/fixnum_extension.rb +10 -0
- data/spec/support/http_library_adapters.rb +31 -2
- data/spec/support/ruby_interpreter.rb +7 -0
- data/spec/support/vcr_localhost_server.rb +86 -44
- data/spec/support/webmock_macros.rb +14 -0
- data/spec/vcr_spec.rb +1 -1
- data/spec/version_spec.rb +1 -1
- data/vcr.gemspec +10 -6
- metadata +155 -39
data/Rakefile
CHANGED
@@ -4,9 +4,12 @@ Bundler::GemHelper.install_tasks
|
|
4
4
|
|
5
5
|
require 'rake'
|
6
6
|
require "rspec/core/rake_task"
|
7
|
+
$LOAD_PATH.unshift 'spec'
|
8
|
+
|
9
|
+
require 'support/ruby_interpreter'
|
7
10
|
|
8
11
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
9
|
-
#t.
|
12
|
+
#t.rspec_opts = %w[--format documentation]
|
10
13
|
end
|
11
14
|
|
12
15
|
desc "Run all examples using rcov"
|
@@ -21,7 +24,7 @@ end
|
|
21
24
|
|
22
25
|
permutations = {
|
23
26
|
'fakeweb' => %w( net/http ),
|
24
|
-
'webmock' => %w( net/http httpclient patron em-http-request )
|
27
|
+
'webmock' => %w( net/http httpclient patron em-http-request curb )
|
25
28
|
}
|
26
29
|
|
27
30
|
require 'cucumber/rake/task'
|
@@ -31,7 +34,7 @@ namespace :features do
|
|
31
34
|
|
32
35
|
namespace http_stubbing_adapter do
|
33
36
|
http_libraries.each do |http_lib|
|
34
|
-
next if
|
37
|
+
next if RUBY_INTERPRETER != :mri && %w( patron em-http-request curb ).include?(http_lib)
|
35
38
|
|
36
39
|
sanitized_http_lib = http_lib.gsub('/', '_')
|
37
40
|
features_subtasks << "features:#{http_stubbing_adapter}:#{sanitized_http_lib}"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
:request: !ruby/struct:VCR::Request
|
4
|
+
:method: :get
|
5
|
+
:uri: http://example.com:80/a
|
6
|
+
:body:
|
7
|
+
:headers:
|
8
|
+
:response: !ruby/struct:VCR::Response
|
9
|
+
:status: !ruby/struct:VCR::ResponseStatus
|
10
|
+
:code: 200
|
11
|
+
:message: OK
|
12
|
+
:headers:
|
13
|
+
etag:
|
14
|
+
- "\"24ec5-1b6-4059a80bfd280\""
|
15
|
+
:body: a response 1
|
16
|
+
:http_version: "1.1"
|
17
|
+
- !ruby/struct:VCR::HTTPInteraction
|
18
|
+
:request: !ruby/struct:VCR::Request
|
19
|
+
:method: :get
|
20
|
+
:uri: http://example.com:80/a
|
21
|
+
:body:
|
22
|
+
:headers:
|
23
|
+
:response: !ruby/struct:VCR::Response
|
24
|
+
:status: !ruby/struct:VCR::ResponseStatus
|
25
|
+
:code: 200
|
26
|
+
:message: OK
|
27
|
+
:headers:
|
28
|
+
etag:
|
29
|
+
- "\"24ec5-1b6-4059a80bfd280\""
|
30
|
+
:body: a response 2
|
31
|
+
:http_version: "1.1"
|
32
|
+
- !ruby/struct:VCR::HTTPInteraction
|
33
|
+
:request: !ruby/struct:VCR::Request
|
34
|
+
:method: :get
|
35
|
+
:uri: http://example.com:80/b
|
36
|
+
:body:
|
37
|
+
:headers:
|
38
|
+
:response: !ruby/struct:VCR::Response
|
39
|
+
:status: !ruby/struct:VCR::ResponseStatus
|
40
|
+
:code: 200
|
41
|
+
:message: OK
|
42
|
+
:headers:
|
43
|
+
etag:
|
44
|
+
- "\"24ec5-1b6-4059a80bfd280\""
|
45
|
+
:body: b response 1
|
46
|
+
:http_version: "1.1"
|
47
|
+
- !ruby/struct:VCR::HTTPInteraction
|
48
|
+
:request: !ruby/struct:VCR::Request
|
49
|
+
:method: :get
|
50
|
+
:uri: http://example.com:80/b
|
51
|
+
:body:
|
52
|
+
:headers:
|
53
|
+
:response: !ruby/struct:VCR::Response
|
54
|
+
:status: !ruby/struct:VCR::ResponseStatus
|
55
|
+
:code: 200
|
56
|
+
:message: OK
|
57
|
+
:headers:
|
58
|
+
etag:
|
59
|
+
- "\"24ec5-1b6-4059a80bfd280\""
|
60
|
+
:body: b response 2
|
61
|
+
:http_version: "1.1"
|
62
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: http://example.com:80/a
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
response: !ruby/struct:VCR::Response
|
9
|
+
status: !ruby/struct:VCR::ResponseStatus
|
10
|
+
code: 200
|
11
|
+
message: OK
|
12
|
+
headers:
|
13
|
+
etag:
|
14
|
+
- "\"24ec5-1b6-4059a80bfd280\""
|
15
|
+
body: a response 1
|
16
|
+
http_version: "1.1"
|
17
|
+
- !ruby/struct:VCR::HTTPInteraction
|
18
|
+
request: !ruby/struct:VCR::Request
|
19
|
+
method: :get
|
20
|
+
uri: http://example.com:80/a
|
21
|
+
body:
|
22
|
+
headers:
|
23
|
+
response: !ruby/struct:VCR::Response
|
24
|
+
status: !ruby/struct:VCR::ResponseStatus
|
25
|
+
code: 200
|
26
|
+
message: OK
|
27
|
+
headers:
|
28
|
+
etag:
|
29
|
+
- "\"24ec5-1b6-4059a80bfd280\""
|
30
|
+
body: a response 2
|
31
|
+
http_version: "1.1"
|
32
|
+
- !ruby/struct:VCR::HTTPInteraction
|
33
|
+
request: !ruby/struct:VCR::Request
|
34
|
+
method: :get
|
35
|
+
uri: http://example.com:80/b
|
36
|
+
body:
|
37
|
+
headers:
|
38
|
+
response: !ruby/struct:VCR::Response
|
39
|
+
status: !ruby/struct:VCR::ResponseStatus
|
40
|
+
code: 200
|
41
|
+
message: OK
|
42
|
+
headers:
|
43
|
+
etag:
|
44
|
+
- "\"24ec5-1b6-4059a80bfd280\""
|
45
|
+
body: b response 1
|
46
|
+
http_version: "1.1"
|
47
|
+
- !ruby/struct:VCR::HTTPInteraction
|
48
|
+
request: !ruby/struct:VCR::Request
|
49
|
+
method: :get
|
50
|
+
uri: http://example.com:80/b
|
51
|
+
body:
|
52
|
+
headers:
|
53
|
+
response: !ruby/struct:VCR::Response
|
54
|
+
status: !ruby/struct:VCR::ResponseStatus
|
55
|
+
code: 200
|
56
|
+
message: OK
|
57
|
+
headers:
|
58
|
+
etag:
|
59
|
+
- "\"24ec5-1b6-4059a80bfd280\""
|
60
|
+
body: b response 2
|
61
|
+
http_version: "1.1"
|
@@ -6,11 +6,11 @@ Feature: HTTPClient
|
|
6
6
|
|
7
7
|
Scenario: Record an asynchronous request
|
8
8
|
Given we do not have a "temp/asynchronous" cassette
|
9
|
-
When I make an asynchronous HTTPClient get request to "http://example.com"
|
9
|
+
When I make an asynchronous HTTPClient get request to "http://example.com" while using the "temp/asynchronous" cassette
|
10
10
|
Then the "temp/asynchronous" library file should have a response for "http://example.com" that matches /You have reached this web page by typing.*example\.com/
|
11
11
|
|
12
12
|
@copy_not_the_real_response_to_temp
|
13
13
|
Scenario: Replay a response for an asynchronous request
|
14
14
|
Given the "temp/not_the_real_response" library file has a response for "http://example.com" that matches /This is not the real response from example\.com/
|
15
|
-
When I make an asynchronous HTTPClient get request to "http://example.com"
|
15
|
+
When I make an asynchronous HTTPClient get request to "http://example.com" while using the "temp/not_the_real_response" cassette
|
16
16
|
Then the response for "http://example.com" should match /This is not the real response from example\.com/
|
data/features/net_http.feature
CHANGED
@@ -6,22 +6,33 @@ Feature: Net::HTTP
|
|
6
6
|
|
7
7
|
Scenario: Record an asynchronous request (such as for mechanize)
|
8
8
|
Given we do not have a "temp/asynchronous" cassette
|
9
|
-
When I make an asynchronous Net::HTTP get request to "http://example.com"
|
9
|
+
When I make an asynchronous Net::HTTP get request to "http://example.com" while using the "temp/asynchronous" cassette
|
10
10
|
Then the "temp/asynchronous" library file should have a response for "http://example.com" that matches /You have reached this web page by typing.*example\.com/
|
11
11
|
|
12
12
|
@copy_not_the_real_response_to_temp
|
13
13
|
Scenario: Replay a response for an asynchronous request (such as for mechanize)
|
14
14
|
Given the "temp/not_the_real_response" library file has a response for "http://example.com" that matches /This is not the real response from example\.com/
|
15
|
-
When I make a replayed asynchronous Net::HTTP get request to "http://example.com"
|
15
|
+
When I make a replayed asynchronous Net::HTTP get request to "http://example.com" while using the "temp/not_the_real_response" cassette
|
16
16
|
Then the response for "http://example.com" should match /This is not the real response from example\.com/
|
17
17
|
|
18
18
|
Scenario: Record a recursive post request
|
19
19
|
Given we do not have a "temp/recursive_post" cassette
|
20
|
-
When I make a recursive Net::HTTP post request to "http://example.com"
|
20
|
+
When I make a recursive Net::HTTP post request to "http://example.com" while using the "temp/recursive_post" cassette
|
21
21
|
Then the "temp/recursive_post" library file should have a response for "http://example.com" that matches /You have reached this web page by typing.*example\.com/
|
22
22
|
And the "temp/recursive_post" library file should have exactly 1 response
|
23
23
|
|
24
24
|
Scenario: Record a request with a block with a return statement
|
25
25
|
Given we do not have a "temp/block_with_a_return" cassette
|
26
|
-
When I make a returning block Net::HTTP get request to "http://example.com"
|
26
|
+
When I make a returning block Net::HTTP get request to "http://example.com" while using the "temp/block_with_a_return" cassette
|
27
27
|
Then the "temp/block_with_a_return" library file should have a response for "http://example.com" that matches /You have reached this web page by typing.*example\.com/
|
28
|
+
|
29
|
+
Scenario: Record a request made with open uri
|
30
|
+
Given we do not have a "temp/open_uri" cassette
|
31
|
+
When I make an open uri Net::HTTP get request to "http://example.com" while using the "temp/open_uri" cassette
|
32
|
+
Then the "temp/open_uri" library file should have a response for "http://example.com" that matches /You have reached this web page by typing.*example\.com/
|
33
|
+
|
34
|
+
@copy_not_the_real_response_to_temp
|
35
|
+
Scenario: Replay a response for an open uri request
|
36
|
+
Given the "temp/not_the_real_response" library file has a response for "http://example.com" that matches /This is not the real response from example\.com/
|
37
|
+
When I make an open uri Net::HTTP get request to "http://example.com" while using the "temp/not_the_real_response" cassette
|
38
|
+
Then the response for "http://example.com" should match /This is not the real response from example\.com/
|
@@ -6,7 +6,7 @@ Feature: Record response
|
|
6
6
|
|
7
7
|
Scenario: Record a response using VCR.use_cassette
|
8
8
|
Given we do not have a "temp/cassette" cassette
|
9
|
-
When I make an HTTP get request to "http://example.com/"
|
9
|
+
When I make an HTTP get request to "http://example.com/" while using the "temp/cassette" cassette
|
10
10
|
Then the "temp/cassette" library file should have a response for "http://example.com/" that matches /You have reached this web page by typing.*example\.com/
|
11
11
|
And the "temp/cassette" library file should have normalized headers for all recorded interactions
|
12
12
|
|
@@ -27,7 +27,7 @@ Feature: Record response
|
|
27
27
|
And we do not have a "temp/nested" cassette
|
28
28
|
And this scenario is tagged with the vcr cassette tag: "@record_cassette2"
|
29
29
|
When I make an HTTP get request to "http://example.com/before_nested"
|
30
|
-
And I make an HTTP get request to "http://example.com/nested"
|
30
|
+
And I make an HTTP get request to "http://example.com/nested" while using the "temp/nested" cassette
|
31
31
|
And I make an HTTP get request to "http://example.com/after_nested"
|
32
32
|
Then I can test the scenario cassette's recorded responses in the next scenario, after the cassette has been ejected
|
33
33
|
And the "temp/nested" library file should have a response for "http://example.com/nested" that matches /The requested URL \/nested was not found/
|
@@ -37,14 +37,27 @@ Feature: Record response
|
|
37
37
|
Then the "cucumber_tags/record_cassette2" library file should have a response for "http://example.com/before_nested" that matches /The requested URL \/before_nested was not found/
|
38
38
|
And the "cucumber_tags/record_cassette2" library file should have a response for "http://example.com/after_nested" that matches /The requested URL \/after_nested was not found/
|
39
39
|
|
40
|
-
Scenario: Make an HTTP request in a cassette with record mode set to :all
|
40
|
+
Scenario: Make an HTTP request in a cassette with record mode set to :all when the cassette does not already exist
|
41
41
|
Given we do not have a "temp/record_all_cassette" cassette
|
42
|
-
When I make an HTTP get request to "http://example.com/"
|
42
|
+
When I make an HTTP get request to "http://example.com/" while using the "temp/record_all_cassette" cassette using cassette options: { :record => :all }
|
43
43
|
Then the "temp/record_all_cassette" library file should have a response for "http://example.com/" that matches /You have reached this web page by typing.*example\.com/
|
44
44
|
|
45
|
+
@copy_record_all_to_temp
|
46
|
+
Scenario: Make an HTTP request in a cassette with record mode set to :all when the cassette already exists
|
47
|
+
Given the "temp/record_all" library file has a response for "http://example.com/a" that matches /a response 1/
|
48
|
+
And the "temp/record_all" library file has a response for "http://example.com/a" that matches /a response 2/
|
49
|
+
And the "temp/record_all" library file has a response for "http://example.com/b" that matches /b response 1/
|
50
|
+
And the "temp/record_all" library file has a response for "http://example.com/b" that matches /b response 2/
|
51
|
+
When I make an HTTP get request to "http://example.com/a" while using the "temp/record_all" cassette using cassette options: { :record => :all }
|
52
|
+
Then the "temp/record_all" library file should have a response for "http://example.com/a" that matches /The requested URL \/a was not found/
|
53
|
+
And the "temp/record_all" library file should not have a response for "http://example.com/a" that matches /a response 1/
|
54
|
+
And the "temp/record_all" library file should not have a response for "http://example.com/a" that matches /a response 2/
|
55
|
+
And the "temp/record_all" library file should have a response for "http://example.com/b" that matches /b response 1/
|
56
|
+
And the "temp/record_all" library file should have a response for "http://example.com/b" that matches /b response 2/
|
57
|
+
|
45
58
|
Scenario: Make an HTTP request in a cassette with record mode set to :none
|
46
59
|
Given we do not have a "temp/record_none_cassette" cassette
|
47
|
-
When I make an HTTP get request to "http://example.com/"
|
60
|
+
When I make an HTTP get request to "http://example.com/" while using the "temp/record_none_cassette" cassette using cassette options: { :record => :none }
|
48
61
|
Then the HTTP get request to "http://example.com/" should result in an error that mentions VCR
|
49
62
|
And there should not be a "temp/record_none_cassette" library file
|
50
63
|
|
@@ -52,7 +65,7 @@ Feature: Record response
|
|
52
65
|
Scenario: Make an HTTP request in a cassette with record mode set to :new_episodes
|
53
66
|
Given we have a "temp/not_the_real_response" library file with a previously recorded response for "http://example.com/"
|
54
67
|
And we have a "temp/not_the_real_response" library file with no previously recorded response for "http://example.com/foo"
|
55
|
-
When I make HTTP get requests to "http://example.com/" and "http://example.com/foo"
|
68
|
+
When I make HTTP get requests to "http://example.com/" and "http://example.com/foo" while using the "temp/not_the_real_response" cassette
|
56
69
|
Then the "temp/not_the_real_response" library file should have a response for "http://example.com/" that matches /This is not the real response from example\.com/
|
57
70
|
And the "temp/not_the_real_response" library file should have a response for "http://example.com/foo" that matches /The requested URL \/foo was not found/
|
58
71
|
|
@@ -61,6 +74,22 @@ Feature: Record response
|
|
61
74
|
Given we do not have a "temp/localhost" cassette
|
62
75
|
And the ignore_localhost config setting is set to true
|
63
76
|
And a rack app is running on localhost that returns "hello world" for all requests
|
64
|
-
When I make an HTTP get request to the localhost rack app
|
77
|
+
When I make an HTTP get request to the localhost rack app while using the "temp/localhost" cassette
|
65
78
|
Then the response for the localhost rack app should match /hello world/
|
66
79
|
And there should not be a "temp/localhost" library file
|
80
|
+
|
81
|
+
@copy_not_the_real_response_to_temp
|
82
|
+
Scenario: The response is not automatically recorded when not enough time has passed
|
83
|
+
Given the "temp/not_the_real_response" library file has a response for "http://example.com/" that matches /This is not the real response from example.com/
|
84
|
+
And 6 days have passed since the "temp/not_the_real_response" library file last changed
|
85
|
+
When I make an HTTP get request to "http://example.com/" while using the "temp/not_the_real_response" cassette using cassette options: { :record => :none, :re_record_interval => 7.days }
|
86
|
+
Then the response for "http://example.com/" should match /This is not the real response from example.com/
|
87
|
+
And the "temp/not_the_real_response" library file should have a response for "http://example.com/" that matches /This is not the real response from example.com/
|
88
|
+
|
89
|
+
@copy_not_the_real_response_to_temp
|
90
|
+
Scenario: The response is automatically recorded when enough time has passed
|
91
|
+
Given the "temp/not_the_real_response" library file has a response for "http://example.com/" that matches /This is not the real response from example.com/
|
92
|
+
And 8 days have passed since the "temp/not_the_real_response" library file last changed
|
93
|
+
When I make an HTTP get request to "http://example.com/" while using the "temp/not_the_real_response" cassette using cassette options: { :record => :none, :re_record_interval => 7.days }
|
94
|
+
Then the response for "http://example.com/" should match /You have reached this web page by typing.*example\.com/
|
95
|
+
And the "temp/not_the_real_response" library file should have a response for "http://example.com/" that matches /You have reached this web page by typing.*example\.com/
|
@@ -6,7 +6,7 @@ Feature: Replay recorded response
|
|
6
6
|
|
7
7
|
Scenario: Replay recorded response for a request in a VCR.use_cassette block
|
8
8
|
Given the "not_the_real_response" library file has a response for "http://example.com/" that matches /This is not the real response from example\.com/
|
9
|
-
When I make an HTTP get request to "http://example.com/"
|
9
|
+
When I make an HTTP get request to "http://example.com/" while using the "not_the_real_response" cassette
|
10
10
|
Then the response for "http://example.com/" should match /This is not the real response from example\.com/
|
11
11
|
|
12
12
|
@replay_cassette1
|
@@ -23,7 +23,7 @@ Feature: Replay recorded response
|
|
23
23
|
And the "nested_replay_cassette" library file has a response for "http://example.com/nested" that matches /The nested response/
|
24
24
|
And the "cucumber_tags/replay_cassette2" library file has a response for "http://example.com/after_nested" that matches /The after_nested response/
|
25
25
|
When I make an HTTP get request to "http://example.com/before_nested"
|
26
|
-
And I make an HTTP get request to "http://example.com/nested"
|
26
|
+
And I make an HTTP get request to "http://example.com/nested" while using the "nested_replay_cassette" cassette
|
27
27
|
And I make an HTTP get request to "http://example.com/after_nested"
|
28
28
|
Then the response for "http://example.com/before_nested" should match /The before_nested response/
|
29
29
|
And the response for "http://example.com/nested" should match /The nested response/
|
@@ -33,7 +33,7 @@ Feature: Replay recorded response
|
|
33
33
|
Scenario: Make an HTTP request in a cassette with record mode set to :all
|
34
34
|
Given we have a "temp/not_the_real_response" library file with a previously recorded response for "http://example.com/"
|
35
35
|
And we have a "temp/not_the_real_response" library file with no previously recorded response for "http://example.com/foo"
|
36
|
-
When I make HTTP get requests to "http://example.com/" and "http://example.com/foo"
|
36
|
+
When I make HTTP get requests to "http://example.com/" and "http://example.com/foo" while using the "temp/not_the_real_response" cassette using cassette options: { :record => :all }
|
37
37
|
Then the response for "http://example.com/" should match /You have reached this web page by typing.*example\.com/
|
38
38
|
And the response for "http://example.com/foo" should match /The requested URL \/foo was not found/
|
39
39
|
|
@@ -41,7 +41,7 @@ Feature: Replay recorded response
|
|
41
41
|
Scenario: Make an HTTP request in a cassette with record mode set to :none
|
42
42
|
Given we have a "temp/not_the_real_response" library file with a previously recorded response for "http://example.com/"
|
43
43
|
And we have a "temp/not_the_real_response" library file with no previously recorded response for "http://example.com/foo"
|
44
|
-
When I make HTTP get requests to "http://example.com/" and "http://example.com/foo"
|
44
|
+
When I make HTTP get requests to "http://example.com/" and "http://example.com/foo" while using the "temp/not_the_real_response" cassette using cassette options: { :record => :none }
|
45
45
|
Then the response for "http://example.com/" should match /This is not the real response from example\.com/
|
46
46
|
And the HTTP get request to "http://example.com/foo" should result in an error that mentions VCR
|
47
47
|
|
@@ -49,7 +49,7 @@ Feature: Replay recorded response
|
|
49
49
|
Scenario: Make an HTTP request in a cassette with record mode set to :new_episodes
|
50
50
|
Given we have a "temp/not_the_real_response" library file with a previously recorded response for "http://example.com/"
|
51
51
|
And we have a "temp/not_the_real_response" library file with no previously recorded response for "http://example.com/foo"
|
52
|
-
When I make HTTP get requests to "http://example.com/" and "http://example.com/foo"
|
52
|
+
When I make HTTP get requests to "http://example.com/" and "http://example.com/foo" while using the "temp/not_the_real_response" cassette
|
53
53
|
Then the response for "http://example.com/" should match /This is not the real response from example\.com/
|
54
54
|
And the response for "http://example.com/foo" should match /The requested URL \/foo was not found/
|
55
55
|
|
@@ -76,7 +76,7 @@ Feature: Replay recorded response
|
|
76
76
|
|
77
77
|
Scenario: Replay recorded erb response
|
78
78
|
Given the "erb_cassette" library file has a response for "http://example.com/embedded_ruby_code" that matches /Some embedded ruby code[\S\s]*The value of some_variable is/
|
79
|
-
When I make an HTTP get request to "http://example.com/embedded_ruby_code"
|
79
|
+
When I make an HTTP get request to "http://example.com/embedded_ruby_code" while using the "erb_cassette" cassette using cassette options: { :record => :none, :erb => { :some_variable => 'foo-bar' } }
|
80
80
|
Then the response for "http://example.com/embedded_ruby_code" should match /Some embedded ruby code: 7[\S\s]*The value of some_variable is: foo-bar/
|
81
81
|
|
82
82
|
@create_replay_localhost_cassette @spawns_localhost_server
|
@@ -84,7 +84,7 @@ Feature: Replay recorded response
|
|
84
84
|
Given the ignore_localhost config setting is set to false
|
85
85
|
And the "temp/replay_localhost_cassette" library file has a response for localhost that matches /This is a fake response/
|
86
86
|
And a rack app is running on localhost that returns "localhost response" for all requests
|
87
|
-
When I make an HTTP get request to the localhost rack app
|
87
|
+
When I make an HTTP get request to the localhost rack app while using the "temp/replay_localhost_cassette" cassette
|
88
88
|
Then the response for the localhost rack app should match /This is a fake response/
|
89
89
|
|
90
90
|
@create_replay_localhost_cassette @spawns_localhost_server
|
@@ -92,5 +92,5 @@ Feature: Replay recorded response
|
|
92
92
|
Given the ignore_localhost config setting is set to true
|
93
93
|
And the "temp/replay_localhost_cassette" library file has a response for localhost that matches /This is a fake response/
|
94
94
|
And a rack app is running on localhost that returns "localhost response" for all requests
|
95
|
-
When I make an HTTP get request to the localhost rack app
|
95
|
+
When I make an HTTP get request to the localhost rack app while using the "temp/replay_localhost_cassette" cassette
|
96
96
|
Then the response for the localhost rack app should match /localhost response/
|
@@ -0,0 +1,100 @@
|
|
1
|
+
@fakeweb
|
2
|
+
Feature: RSpec integration
|
3
|
+
In order to easily use VCR with RSpec
|
4
|
+
As a user of both VCR and RSpec
|
5
|
+
I want a simple macro that uses a cassette for an example group
|
6
|
+
|
7
|
+
Scenario: `use_vcr_cassette` macro for RSpec 2
|
8
|
+
Given the following files do not exist:
|
9
|
+
| cassettes/VCR-RSpec_integration/without_an_explicit_cassette_name.yml |
|
10
|
+
| cassettes/net_http_example.yml |
|
11
|
+
And a file named "use_vcr_cassette_for_rspec_2_spec.rb" with:
|
12
|
+
"""
|
13
|
+
require 'vcr'
|
14
|
+
|
15
|
+
VCR.config do |c|
|
16
|
+
c.cassette_library_dir = 'cassettes'
|
17
|
+
c.http_stubbing_library = :fakeweb
|
18
|
+
c.default_cassette_options = { :record => :new_episodes }
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec.configure do |c|
|
22
|
+
c.extend VCR::RSpec::Macros
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "VCR-RSpec integration" do
|
26
|
+
def make_http_request
|
27
|
+
Net::HTTP.get_response('example.com', '/').body
|
28
|
+
end
|
29
|
+
|
30
|
+
context "without an explicit cassette name" do
|
31
|
+
use_vcr_cassette
|
32
|
+
|
33
|
+
it 'records an http request' do
|
34
|
+
make_http_request.should =~ /You have reached this web page by typing.*example\.com/
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with an explicit cassette name" do
|
39
|
+
use_vcr_cassette "net_http_example"
|
40
|
+
|
41
|
+
it 'records an http request' do
|
42
|
+
make_http_request.should =~ /You have reached this web page by typing.*example\.com/
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
"""
|
47
|
+
When I run "rspec ./use_vcr_cassette_for_rspec_2_spec.rb"
|
48
|
+
Then the output should contain "2 examples, 0 failures"
|
49
|
+
And the file "cassettes/VCR-RSpec_integration/without_an_explicit_cassette_name.yml" should contain "You have reached this web page by typing"
|
50
|
+
And the file "cassettes/net_http_example.yml" should contain "You have reached this web page by typing"
|
51
|
+
|
52
|
+
Scenario: `use_vcr_cassette` macro for RSpec 1
|
53
|
+
Given the following files do not exist:
|
54
|
+
| cassettes/VCR-RSpec_integration/without_an_explicit_cassette_name.yml |
|
55
|
+
| cassettes/net_http_example.yml |
|
56
|
+
And a file named "use_vcr_cassette_for_rspec_1_spec.rb" with:
|
57
|
+
"""
|
58
|
+
$LOAD_PATH.unshift(File.join(%w[ .. .. vendor rspec-1 lib ]))
|
59
|
+
|
60
|
+
require 'spec'
|
61
|
+
require 'spec/autorun'
|
62
|
+
|
63
|
+
require 'vcr'
|
64
|
+
|
65
|
+
VCR.config do |c|
|
66
|
+
c.cassette_library_dir = 'cassettes'
|
67
|
+
c.http_stubbing_library = :fakeweb
|
68
|
+
c.default_cassette_options = { :record => :new_episodes }
|
69
|
+
end
|
70
|
+
|
71
|
+
Spec::Runner.configure do |c|
|
72
|
+
c.extend VCR::RSpec::Macros
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "VCR-RSpec integration" do
|
76
|
+
def make_http_request
|
77
|
+
Net::HTTP.get_response('example.com', '/').body
|
78
|
+
end
|
79
|
+
|
80
|
+
context "without an explicit cassette name" do
|
81
|
+
use_vcr_cassette
|
82
|
+
|
83
|
+
it 'records an http request' do
|
84
|
+
make_http_request.should =~ /You have reached this web page by typing.*example\.com/
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "with an explicit cassette name" do
|
89
|
+
use_vcr_cassette "net_http_example"
|
90
|
+
|
91
|
+
it 'records an http request' do
|
92
|
+
make_http_request.should =~ /You have reached this web page by typing.*example\.com/
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
"""
|
97
|
+
When I run "ruby -I'../../lib' ./use_vcr_cassette_for_rspec_1_spec.rb"
|
98
|
+
Then the output should contain "2 examples, 0 failures"
|
99
|
+
And the file "cassettes/VCR-RSpec_integration/without_an_explicit_cassette_name.yml" should contain "You have reached this web page by typing"
|
100
|
+
And the file "cassettes/net_http_example.yml" should contain "You have reached this web page by typing"
|