vcr 0.1.2 → 0.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.
- data/History.rdoc +4 -0
- data/README.rdoc +31 -2
- data/VERSION +1 -1
- data/features/record_response.feature +6 -0
- data/features/step_definitions/vcr_steps.rb +4 -4
- data/lib/vcr/cassette.rb +14 -1
- data/lib/vcr/config.rb +8 -4
- data/lib/vcr/extensions/fake_web.rb +10 -0
- data/lib/vcr/extensions/net_http.rb +25 -16
- data/spec/cassette_spec.rb +40 -15
- data/spec/config_spec.rb +26 -6
- data/spec/extensions/fake_web_spec.rb +30 -0
- data/spec/extensions/net_http_spec.rb +39 -27
- data/spec/spec_helper.rb +7 -0
- data/spec/support/disable_warnings.rb +12 -0
- data/spec/vcr_spec.rb +0 -9
- data/vcr.gemspec +4 -2
- metadata +5 -3
data/History.rdoc
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== 0.2.0 March 9, 2010
|
2
|
+
* Added <tt>:allow_real_http</tt> cassette option, which allows VCR to work with capybara and a javascript driver.
|
3
|
+
Bug reported by {Ben Hutton}[http://github.com/benhutton].
|
4
|
+
* Deprecated the default_cassette_record_mode option. Use default_cassette_options instead.
|
1
5
|
|
2
6
|
== 0.1.2 March 4, 2010
|
3
7
|
* Added explanatory note about VCR to FakeWeb::NetConnectNotAllowedError#message.
|
data/README.rdoc
CHANGED
@@ -69,8 +69,11 @@ modes are:
|
|
69
69
|
# the cache_dir is where the cassette yml files will be saved.
|
70
70
|
c.cache_dir = File.join(Rails.root, 'features', 'fixtures', 'vcr_cassettes')
|
71
71
|
|
72
|
-
#
|
73
|
-
c.
|
72
|
+
# these options will be used as defaults for your cassettes, but you can override them in each individual cassette.
|
73
|
+
c.default_cassette_options = {
|
74
|
+
:record => :none,
|
75
|
+
:allow_real_http => :localhost
|
76
|
+
}
|
74
77
|
end
|
75
78
|
|
76
79
|
This can go pretty much wherever, as long as this code is run before your tests, specs or scenarios. I tend
|
@@ -101,6 +104,27 @@ Alternately, you can create and destroy the cassette with individual method call
|
|
101
104
|
In both of these cases, VCR would use the file geocoding/Seattle_WA.yml within the configured
|
102
105
|
cache dir. The :record setting is optional--if you leave it blank, your configured default will be used.
|
103
106
|
|
107
|
+
Besides the :record option, cassettes also support the :allow_real_http option. You can use this to make the cassette
|
108
|
+
allow some real HTTP requests. You can specify it with a lambda:
|
109
|
+
|
110
|
+
VCR.with_cassette('my cassette', :allow_real_http => lambda { |uri| uri.host == 'google.com' }) do
|
111
|
+
# do something that causes an HTTP request.
|
112
|
+
end
|
113
|
+
|
114
|
+
In this case, any google HTTP requests will be made for real, regardless of your <tt>FakeWeb.allow_net_connect</tt> setting,
|
115
|
+
your current record mode, and whether or not you are recording or replaying this cassette. Non-google requests will do
|
116
|
+
the appropriate recording/replaying as usual. You can also use the special <tt>:localhost</tt> option:
|
117
|
+
|
118
|
+
VCR.with_cassette('my cassette', :allow_real_http => :localhost) do
|
119
|
+
# do something that causes an HTTP request.
|
120
|
+
end
|
121
|
+
|
122
|
+
This is equivalent to using a lambda like:
|
123
|
+
|
124
|
+
lambda { |uri| uri.host == 'localhost' }
|
125
|
+
|
126
|
+
This is needed for using VCR with {capybara}[http://github.com/jnicklas/capybara] and any of the javascript drivers (see below for more info).
|
127
|
+
|
104
128
|
== Usage with Cucumber
|
105
129
|
|
106
130
|
VCR provides special support for cucumber. You can of course use <tt>VCR.with_cassette</tt> within a step definition,
|
@@ -125,6 +149,11 @@ For each of the tags you specify in your cucumber_tags block, VCR will set up th
|
|
125
149
|
for the entire scenario. The tag (minus the '@') will be used as the cassette name, and it'll
|
126
150
|
go in the cucumber_tags subdirectory of the configured cache dir.
|
127
151
|
|
152
|
+
== Usage with Capybara
|
153
|
+
|
154
|
+
When you use any of the javascript-enabled drivers (selenium, celerity, culerity) with {capybara}[http://github.com/jnicklas/capybara],
|
155
|
+
it'll need to ping the app running on localhost. You can use the <tt>:allow_real_http => :localhost</tt> option to allow this.
|
156
|
+
|
128
157
|
== Suggested Workflow
|
129
158
|
|
130
159
|
First, configure VCR and FakeWeb as I have above. I like setting <tt>FakeWeb.allow_net_connect</tt> to <tt>false</tt>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -64,3 +64,9 @@ Feature: Record response
|
|
64
64
|
When I make a recursive HTTP post request to "http://example.com" within the "temp/recursive_post" unregistered cassette
|
65
65
|
Then the "temp/recursive_post" cache file should have a response for "http://example.com" that matches /You have reached this web page by typing.*example\.com/
|
66
66
|
And the "temp/recursive_post" cache file should have exactly 1 response
|
67
|
+
|
68
|
+
Scenario: Make an allowed HTTP request in a cassette with record mode set to :none
|
69
|
+
Given we do not have a "temp/record_none_cassette" cassette
|
70
|
+
When I make an HTTP get request to "http://example.com" within the "temp/record_none_cassette" none cassette, allowing requests matching /example.com/
|
71
|
+
Then the response for "http://example.com" should match /You have reached this web page by typing.*example\.com/
|
72
|
+
And there should not be a "temp/record_none_cassette" cache file
|
@@ -67,11 +67,11 @@ When /^I make an(.*)? HTTP (?:get|post) request to "([^\"]*)"$/ do |request_type
|
|
67
67
|
@http_requests[url] += [result]
|
68
68
|
end
|
69
69
|
|
70
|
-
When /^I make(?: an)?(.*)? HTTP (get|post) requests? to "([^\"]*)"(?: and "([^\"]*)")? within the "([^\"]*)" ?(#{VCR::Cassette::VALID_RECORD_MODES.join('|')})? cassette
|
71
|
-
record_mode
|
72
|
-
|
70
|
+
When /^I make(?: an)?(.*)? HTTP (get|post) requests? to "([^\"]*)"(?: and "([^\"]*)")? within the "([^\"]*)" ?(#{VCR::Cassette::VALID_RECORD_MODES.join('|')})? cassette(?:, allowing requests matching \/([^\/]+)\/)?$/ do |request_type, method, url1, url2, cassette_name, record_mode, allowed|
|
71
|
+
options = { :record => (record_mode ? record_mode.to_sym : :unregistered) }
|
72
|
+
options[:allow_real_http] = lambda { |uri| uri.to_s =~ /#{allowed}/ } if allowed.to_s.size > 0
|
73
73
|
urls = [url1, url2].select { |u| u.to_s.size > 0 }
|
74
|
-
VCR.with_cassette(cassette_name,
|
74
|
+
VCR.with_cassette(cassette_name, options) do
|
75
75
|
urls.each do |url|
|
76
76
|
When %{I make an#{request_type} HTTP #{method} request to "#{url}"}
|
77
77
|
end
|
data/lib/vcr/cassette.rb
CHANGED
@@ -9,7 +9,8 @@ module VCR
|
|
9
9
|
|
10
10
|
def initialize(name, options = {})
|
11
11
|
@name = name
|
12
|
-
@record_mode = options[:record] || VCR::Config.
|
12
|
+
@record_mode = options[:record] || VCR::Config.default_cassette_options[:record]
|
13
|
+
@allow_real_http_lambda = allow_real_http_lambda_for(options[:allow_real_http] || VCR::Config.default_cassette_options[:allow_real_http])
|
13
14
|
self.class.raise_error_unless_valid_record_mode(record_mode)
|
14
15
|
set_fakeweb_allow_net_connect
|
15
16
|
load_recorded_responses
|
@@ -39,6 +40,10 @@ module VCR
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
43
|
+
def allow_real_http_requests_to?(uri)
|
44
|
+
@allow_real_http_lambda ? @allow_real_http_lambda.call(uri) : false
|
45
|
+
end
|
46
|
+
|
42
47
|
private
|
43
48
|
|
44
49
|
def new_recorded_responses
|
@@ -93,5 +98,13 @@ module VCR
|
|
93
98
|
FakeWeb.remove_from_registry(rr.method, rr.uri)
|
94
99
|
end
|
95
100
|
end
|
101
|
+
|
102
|
+
def allow_real_http_lambda_for(allow_option)
|
103
|
+
if allow_option == :localhost
|
104
|
+
lambda { |uri| uri.host == 'localhost' }
|
105
|
+
else
|
106
|
+
allow_option
|
107
|
+
end
|
108
|
+
end
|
96
109
|
end
|
97
110
|
end
|
data/lib/vcr/config.rb
CHANGED
@@ -9,10 +9,14 @@ module VCR
|
|
9
9
|
FileUtils.mkdir_p(cache_dir) if cache_dir
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
def
|
14
|
-
|
15
|
-
|
12
|
+
attr_writer :default_cassette_options
|
13
|
+
def default_cassette_options
|
14
|
+
@default_cassette_options ||= {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def default_cassette_record_mode=(value)
|
18
|
+
warn %Q{WARNING: #default_cassette_record_mode is deprecated. Instead, use: "default_cassette_options = { :record => :#{value.to_s} }"}
|
19
|
+
default_cassette_options.merge!(:record => value)
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
@@ -5,6 +5,16 @@ module FakeWeb
|
|
5
5
|
Registry.instance.remove(method, url)
|
6
6
|
end
|
7
7
|
|
8
|
+
def self.with_allow_net_connect_set_to(value)
|
9
|
+
original_value = FakeWeb.allow_net_connect?
|
10
|
+
begin
|
11
|
+
FakeWeb.allow_net_connect = value
|
12
|
+
yield
|
13
|
+
ensure
|
14
|
+
FakeWeb.allow_net_connect = original_value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
8
18
|
class Registry #:nodoc:
|
9
19
|
def remove(method, url)
|
10
20
|
uri_map.delete_if do |uri, method_hash|
|
@@ -4,9 +4,14 @@ module Net
|
|
4
4
|
class HTTP
|
5
5
|
def request_with_vcr(request, body = nil, &block)
|
6
6
|
@__request_with_vcr_call_count = (@__request_with_vcr_call_count || 0) + 1
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
uri = URI.parse(__vcr_uri__(request))
|
8
|
+
if (cassette = VCR.current_cassette) && cassette.allow_real_http_requests_to?(uri)
|
9
|
+
FakeWeb.with_allow_net_connect_set_to(true) { request_without_vcr(request, body, &block) }
|
10
|
+
else
|
11
|
+
response = request_without_vcr(request, body, &block)
|
12
|
+
__store_response_with_vcr__(response, request) if @__request_with_vcr_call_count == 1
|
13
|
+
response
|
14
|
+
end
|
10
15
|
ensure
|
11
16
|
@__request_with_vcr_call_count -= 1
|
12
17
|
end
|
@@ -15,22 +20,26 @@ module Net
|
|
15
20
|
|
16
21
|
private
|
17
22
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
protocol = use_ssl? ? "https" : "http"
|
23
|
+
def __vcr_uri__(request)
|
24
|
+
# Copied from: http://github.com/chrisk/fakeweb/blob/fakeweb-1.2.8/lib/fake_web/ext/net_http.rb#L39-52
|
25
|
+
protocol = use_ssl? ? "https" : "http"
|
22
26
|
|
23
|
-
|
24
|
-
|
27
|
+
path = request.path
|
28
|
+
path = URI.parse(request.path).request_uri if request.path =~ /^http/
|
25
29
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
if request["authorization"] =~ /^Basic /
|
31
|
+
userinfo = FakeWeb::Utility.decode_userinfo_from_header(request["authorization"])
|
32
|
+
userinfo = FakeWeb::Utility.encode_unsafe_chars_in_userinfo(userinfo) + "@"
|
33
|
+
else
|
34
|
+
userinfo = ""
|
35
|
+
end
|
32
36
|
|
33
|
-
|
37
|
+
"#{protocol}://#{userinfo}#{self.address}:#{self.port}#{path}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def __store_response_with_vcr__(response, request)
|
41
|
+
if cassette = VCR.current_cassette
|
42
|
+
uri = __vcr_uri__(request)
|
34
43
|
method = request.method.downcase.to_sym
|
35
44
|
|
36
45
|
unless FakeWeb.registered_uri?(method, uri)
|
data/spec/cassette_spec.rb
CHANGED
@@ -1,19 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe VCR::Cassette do
|
4
|
-
before(:all) do
|
5
|
-
@orig_default_cassette_record_mode = VCR::Config.default_cassette_record_mode
|
6
|
-
VCR::Config.default_cassette_record_mode = :unregistered
|
7
|
-
end
|
8
|
-
|
9
|
-
after(:all) do
|
10
|
-
VCR::Config.default_cassette_record_mode = :unregistered
|
11
|
-
end
|
12
|
-
|
13
|
-
before(:each) do
|
14
|
-
FakeWeb.clean_registry
|
15
|
-
end
|
16
|
-
|
17
4
|
describe '#cache_file' do
|
18
5
|
temp_dir File.expand_path(File.dirname(__FILE__) + '/fixtures/cache_file'), :assign_to_cache_dir => true
|
19
6
|
|
@@ -55,8 +42,8 @@ describe VCR::Cassette do
|
|
55
42
|
end
|
56
43
|
|
57
44
|
VCR::Cassette::VALID_RECORD_MODES.each do |mode|
|
58
|
-
it "defaults the record mode to #{mode} when VCR::Config.
|
59
|
-
VCR::Config.
|
45
|
+
it "defaults the record mode to #{mode} when VCR::Config.default_cassette_options[:record] is #{mode}" do
|
46
|
+
VCR::Config.default_cassette_options = { :record => mode }
|
60
47
|
cassette = VCR::Cassette.new(:test)
|
61
48
|
cassette.record_mode.should == mode
|
62
49
|
end
|
@@ -116,6 +103,44 @@ describe VCR::Cassette do
|
|
116
103
|
end
|
117
104
|
end
|
118
105
|
|
106
|
+
describe '#allow_real_http_requests_to?' do
|
107
|
+
it 'delegates to the :allow_real_http lambda' do
|
108
|
+
[true, false].each do |value|
|
109
|
+
yielded_uri = nil
|
110
|
+
c = VCR::Cassette.new('example', :allow_real_http => lambda { |uri| yielded_uri = uri; value })
|
111
|
+
c.allow_real_http_requests_to?(:the_uri).should == value
|
112
|
+
yielded_uri.should == :the_uri
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'returns true for localhost requests when the :allow_real_http option is set to :localhost' do
|
117
|
+
c = VCR::Cassette.new('example', :allow_real_http => :localhost)
|
118
|
+
c.allow_real_http_requests_to?(URI('http://localhost')).should be_true
|
119
|
+
c.allow_real_http_requests_to?(URI('http://example.com')).should be_false
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'returns false when no option is set' do
|
123
|
+
c = VCR::Cassette.new('example')
|
124
|
+
c.allow_real_http_requests_to?(URI('http://localhost')).should be_false
|
125
|
+
c.allow_real_http_requests_to?(URI('http://example.com')).should be_false
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'delegates to the default :allow_real_http lambda' do
|
129
|
+
[true, false].each do |value|
|
130
|
+
yielded_uri = nil
|
131
|
+
VCR::Config.default_cassette_options.merge!(:allow_real_http => lambda { |uri| yielded_uri = uri; value })
|
132
|
+
c = VCR::Cassette.new('example')
|
133
|
+
c.allow_real_http_requests_to?(:the_uri).should == value
|
134
|
+
yielded_uri.should == :the_uri
|
135
|
+
end
|
136
|
+
|
137
|
+
VCR::Config.default_cassette_options.merge!(:allow_real_http => :localhost)
|
138
|
+
c = VCR::Cassette.new('example')
|
139
|
+
c.allow_real_http_requests_to?(URI('http://localhost')).should be_true
|
140
|
+
c.allow_real_http_requests_to?(URI('http://example.com')).should be_false
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
119
144
|
describe '#destroy!' do
|
120
145
|
temp_dir File.expand_path(File.dirname(__FILE__) + '/fixtures/cassette_spec_destroy'), :assign_to_cache_dir => true
|
121
146
|
|
data/spec/config_spec.rb
CHANGED
@@ -13,15 +13,35 @@ describe VCR::Config do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe '#
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
describe '#default_cassette_options' do
|
17
|
+
it 'always has a hash, even if it is set to nil' do
|
18
|
+
VCR::Config.default_cassette_options = nil
|
19
|
+
VCR::Config.default_cassette_options.should == {}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#default_cassette_record_mode=' do
|
24
|
+
disable_warnings
|
25
|
+
|
26
|
+
it 'sets the default_cassette_options[:record] option' do
|
27
|
+
VCR::Cassette::VALID_RECORD_MODES.each do |mode|
|
28
|
+
VCR::Config.default_cassette_options = nil
|
29
|
+
VCR::Config.default_cassette_record_mode = mode
|
30
|
+
VCR::Config.default_cassette_options[:record].should == mode
|
20
31
|
end
|
21
32
|
end
|
22
33
|
|
23
|
-
it
|
24
|
-
|
34
|
+
it 'merges the :record option with the existing default_cassette_record options' do
|
35
|
+
VCR::Config.default_cassette_options = { :an => :option }
|
36
|
+
VCR::Config.default_cassette_record_mode = :all
|
37
|
+
VCR::Config.default_cassette_options.should == { :an => :option, :record => :all }
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'warns the user that it is deprecated' do
|
41
|
+
VCR::Cassette::VALID_RECORD_MODES.each do |mode|
|
42
|
+
VCR::Config.should_receive(:warn).with(%Q{WARNING: #default_cassette_record_mode is deprecated. Instead, use: "default_cassette_options = { :record => :#{mode.to_s} }"})
|
43
|
+
VCR::Config.default_cassette_record_mode = mode
|
44
|
+
end
|
25
45
|
end
|
26
46
|
end
|
27
47
|
end
|
@@ -30,4 +30,34 @@ describe "FakeWeb Extensions" do
|
|
30
30
|
'The fakeweb error message. You can use VCR to automatically record this request and replay it later with fakeweb. For more details, see the VCR README at: http://github.com/myronmarston/vcr'
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
describe "#with_allow_net_connect_set_to" do
|
35
|
+
it 'sets allow_net_connect for the duration of the block to the provided value' do
|
36
|
+
[true, false].each do |expected|
|
37
|
+
yielded_value = :not_set
|
38
|
+
FakeWeb.with_allow_net_connect_set_to(expected) { yielded_value = FakeWeb.allow_net_connect? }
|
39
|
+
yielded_value.should == expected
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns the value returned by the block' do
|
44
|
+
FakeWeb.with_allow_net_connect_set_to(true) { :return_value }.should == :return_value
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'reverts allow_net_connect when the block completes' do
|
48
|
+
[true, false].each do |expected|
|
49
|
+
FakeWeb.allow_net_connect = expected
|
50
|
+
FakeWeb.with_allow_net_connect_set_to(true) { }
|
51
|
+
FakeWeb.allow_net_connect?.should == expected
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'reverts allow_net_connect when the block completes, even if an error is raised' do
|
56
|
+
[true, false].each do |expected|
|
57
|
+
FakeWeb.allow_net_connect = expected
|
58
|
+
lambda { FakeWeb.with_allow_net_connect_set_to(true) { raise RuntimeError } }.should raise_error(RuntimeError)
|
59
|
+
FakeWeb.allow_net_connect?.should == expected
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
33
63
|
end
|
@@ -1,45 +1,57 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe "Net::HTTP Extensions" do
|
4
|
-
before(:
|
5
|
-
@
|
6
|
-
|
4
|
+
before(:each) do
|
5
|
+
VCR.stub!(:current_cassette).and_return(@current_cassette = mock)
|
6
|
+
@uri = URI.parse('http://example.com')
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
it 'works when there is no current cassette' do
|
10
|
+
VCR.stub!(:current_cassette).and_return(nil)
|
11
|
+
lambda { Net::HTTP.get(@uri) }.should_not raise_error
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
FakeWeb.clean_registry
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'a request that is not registered with FakeWeb' do
|
20
|
-
it 'calls #store_recorded_response! on the current cassette' do
|
21
|
-
recorded_response = VCR::RecordedResponse.new(:get, 'http://example.com:80/', :example_response)
|
22
|
-
VCR::RecordedResponse.should_receive(:new).with(:get, 'http://example.com:80/', an_instance_of(Net::HTTPOK)).and_return(recorded_response)
|
23
|
-
@current_cassette.should_receive(:store_recorded_response!).with(recorded_response)
|
24
|
-
Net::HTTP.get(URI.parse('http://example.com'))
|
14
|
+
context 'when current_cassette.allow_real_http_requests_to? returns false' do
|
15
|
+
before(:each) do
|
16
|
+
@current_cassette.should_receive(:allow_real_http_requests_to?).at_least(:once).with(@uri).and_return(false)
|
25
17
|
end
|
26
18
|
|
27
|
-
|
28
|
-
|
29
|
-
|
19
|
+
describe 'a request that is not registered with FakeWeb' do
|
20
|
+
it 'calls #store_recorded_response! on the current cassette' do
|
21
|
+
recorded_response = VCR::RecordedResponse.new(:get, 'http://example.com:80/', :example_response)
|
22
|
+
VCR::RecordedResponse.should_receive(:new).with(:get, 'http://example.com:80/', an_instance_of(Net::HTTPOK)).and_return(recorded_response)
|
23
|
+
@current_cassette.should_receive(:store_recorded_response!).with(recorded_response)
|
24
|
+
Net::HTTP.get(@uri)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'calls #store_recorded_response! only once, even when Net::HTTP internally recursively calls #request' do
|
28
|
+
@current_cassette.should_receive(:store_recorded_response!).once
|
29
|
+
Net::HTTP.new('example.com', 80).post('/', nil)
|
30
|
+
end
|
30
31
|
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
describe 'a request that is registered with FakeWeb' do
|
34
|
+
it 'does not call #store_recorded_response! on the current cassette' do
|
35
|
+
FakeWeb.register_uri(:get, 'http://example.com', :body => 'example.com response')
|
36
|
+
@current_cassette.should_not_receive(:store_recorded_response!)
|
37
|
+
Net::HTTP.get(@uri)
|
38
|
+
end
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
|
-
|
42
|
+
context 'when current_cassette.allow_real_http_requests_to? returns true' do
|
43
|
+
before(:each) do
|
44
|
+
@current_cassette.should_receive(:allow_real_http_requests_to?).with(@uri).and_return(true)
|
45
|
+
end
|
46
|
+
|
39
47
|
it 'does not call #store_recorded_response! on the current cassette' do
|
40
|
-
|
41
|
-
|
42
|
-
|
48
|
+
@current_cassette.should_receive(:store_recorded_response!).never
|
49
|
+
Net::HTTP.get(@uri)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'uses FakeWeb.with_allow_net_connect_set_to(true) to make the request' do
|
53
|
+
FakeWeb.should_receive(:with_allow_net_connect_set_to).with(true).and_yield
|
54
|
+
Net::HTTP.get(@uri)
|
43
55
|
end
|
44
56
|
end
|
45
57
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -19,4 +19,11 @@ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].e
|
|
19
19
|
|
20
20
|
Spec::Runner.configure do |config|
|
21
21
|
config.extend TempCacheDir
|
22
|
+
config.extend DisableWarnings
|
23
|
+
|
24
|
+
config.before(:each) do
|
25
|
+
VCR::Config.default_cassette_options = { :record => :unregistered }
|
26
|
+
FakeWeb.allow_net_connect = true
|
27
|
+
FakeWeb.clean_registry
|
28
|
+
end
|
22
29
|
end
|
data/spec/vcr_spec.rb
CHANGED
@@ -1,15 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe VCR do
|
4
|
-
before(:all) do
|
5
|
-
@orig_default_cassette_record_mode = VCR::Config.default_cassette_record_mode
|
6
|
-
VCR::Config.default_cassette_record_mode = :unregistered
|
7
|
-
end
|
8
|
-
|
9
|
-
after(:all) do
|
10
|
-
VCR::Config.default_cassette_record_mode = :unregistered
|
11
|
-
end
|
12
|
-
|
13
4
|
def create_cassette
|
14
5
|
VCR.create_cassette!(:cassette_test)
|
15
6
|
end
|
data/vcr.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{vcr}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Myron Marston"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-09}
|
13
13
|
s.description = %q{VCR provides helpers to record HTTP requests for URIs that are not registered with fakeweb, and replay them later. It provides built-in support for cucumber, but works with any ruby testing framework.}
|
14
14
|
s.email = %q{myron.marston@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -63,6 +63,7 @@ Gem::Specification.new do |s|
|
|
63
63
|
"spec/recorded_response_spec.rb",
|
64
64
|
"spec/spec.opts",
|
65
65
|
"spec/spec_helper.rb",
|
66
|
+
"spec/support/disable_warnings.rb",
|
66
67
|
"spec/support/temp_cache_dir.rb",
|
67
68
|
"spec/vcr_spec.rb",
|
68
69
|
"vcr.gemspec"
|
@@ -81,6 +82,7 @@ Gem::Specification.new do |s|
|
|
81
82
|
"spec/extensions/net_read_adapter_spec.rb",
|
82
83
|
"spec/recorded_response_spec.rb",
|
83
84
|
"spec/spec_helper.rb",
|
85
|
+
"spec/support/disable_warnings.rb",
|
84
86
|
"spec/support/temp_cache_dir.rb",
|
85
87
|
"spec/vcr_spec.rb"
|
86
88
|
]
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
- 1
|
8
7
|
- 2
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Myron Marston
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-09 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- spec/recorded_response_spec.rb
|
116
116
|
- spec/spec.opts
|
117
117
|
- spec/spec_helper.rb
|
118
|
+
- spec/support/disable_warnings.rb
|
118
119
|
- spec/support/temp_cache_dir.rb
|
119
120
|
- spec/vcr_spec.rb
|
120
121
|
- vcr.gemspec
|
@@ -157,5 +158,6 @@ test_files:
|
|
157
158
|
- spec/extensions/net_read_adapter_spec.rb
|
158
159
|
- spec/recorded_response_spec.rb
|
159
160
|
- spec/spec_helper.rb
|
161
|
+
- spec/support/disable_warnings.rb
|
160
162
|
- spec/support/temp_cache_dir.rb
|
161
163
|
- spec/vcr_spec.rb
|