vcr 1.1.2 → 1.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/.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/.gitignore
CHANGED
data/.gitmodules
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,28 @@
|
|
1
|
-
#Changelog
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 1.2.0 (October 13, 2010)
|
4
|
+
|
5
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.1.2...v1.2.0)
|
6
|
+
|
7
|
+
* Improved the `:all` record mode so that it keeps previously recorded interactions that do not match the
|
8
|
+
new recorded interactions. Previously, all of the previously recorded interactions were deleted.
|
9
|
+
* Added `:re_record_interval` cassette option. This option causes a cassette to be re-recorded when the
|
10
|
+
existing file is older than the specified interval.
|
11
|
+
* Improved RSpec support. Added #use_vcr_cassette RSpec macro method that sets up a cassette for an RSpec
|
12
|
+
example group.
|
13
|
+
* Fixed VCR/Net::HTTP/WebMock integration so that VCR no longer loads its Net::HTTP monkey patch when
|
14
|
+
WebMock is used, and relies upon WebMock's after_request callback to record Net::HTTP instead. This
|
15
|
+
fixes [a bug](http://github.com/myronmarston/vcr/issues/14) when using WebMock and Open URI.
|
16
|
+
* Consider 0.0.0.0 to be a localhost alias (previously only "localhost" and 127.0.0.1 were considered).
|
17
|
+
* Added spec and feature coverage for Curb integration. Works out of the box with no changes required
|
18
|
+
to VCR due to [Pete Higgins'](http://github.com/phiggins) great work to add Curb support to WebMock.
|
19
|
+
* Got specs and features to pass on rubinius.
|
20
|
+
* Changed WebMock version requirement to 1.4.0.
|
2
21
|
|
3
22
|
## 1.1.2 (September 9, 2010)
|
4
23
|
|
24
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.1.1...v1.1.2)
|
25
|
+
|
5
26
|
* Fixed a minor bug with the WebMock integration: WebMock extends each `Net::HTTPResponse` with an extension
|
6
27
|
module after reading the body, and VCR was doing the same thing, leading to some slight deviance from
|
7
28
|
standard Net::HTTP behavior. The fix prevents VCR from adding the same extension to a `Net::HTTPResponse`
|
@@ -14,6 +35,8 @@
|
|
14
35
|
|
15
36
|
## 1.1.1 (August 26, 2010)
|
16
37
|
|
38
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.1.0...v1.1.1)
|
39
|
+
|
17
40
|
* Updated to use and require FakeWeb 1.3.0. It includes a fix for a bug related to multiple values for the
|
18
41
|
same response header.
|
19
42
|
* Use new `FakeWeb::Utility.request_uri_as_string` method rather than our own logic to construct a request uri.
|
@@ -27,6 +50,8 @@
|
|
27
50
|
|
28
51
|
## 1.1.0 (August 22, 2010)
|
29
52
|
|
53
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.0.3...v1.1.0)
|
54
|
+
|
30
55
|
* Added `:match_requests_on` cassette option, which determines how VCR matches requests.
|
31
56
|
* Removed VCR::TaskRunner and the corresponding rake task definition. The rake task migrated cassettes from the
|
32
57
|
0.3.1 format to the 0.4+ format. If you are still on 0.3.1 or earlier, I recommend you upgrade to 0.4.1 first,
|
@@ -40,6 +65,8 @@
|
|
40
65
|
|
41
66
|
## 1.0.3 (August 5, 2010)
|
42
67
|
|
68
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.0.2...v1.0.3)
|
69
|
+
|
43
70
|
* Upgraded VCR specs to RSpec 2.
|
44
71
|
* Updated `VCR::CucumberTags` so that it uses an `around` hook rather than a `before` hook and an `after` hook.
|
45
72
|
Around hooks were added to Cucumber in the 0.7.3 release, so you'll have to be on that version or higher to use
|
@@ -50,6 +77,8 @@
|
|
50
77
|
|
51
78
|
## 1.0.2 (July 6, 2010)
|
52
79
|
|
80
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.0.1...v1.0.2)
|
81
|
+
|
53
82
|
* Fixed VCR to work with [rest-client](http://github.com/archiloque/rest-client). Rest-client extends the Net::HTTP
|
54
83
|
response body string with a module containing additional data, which got serialized to the cassette file YAML
|
55
84
|
and occasionally caused problems when the YAML was deserialized. Bug reported by
|
@@ -58,6 +87,8 @@
|
|
58
87
|
|
59
88
|
## 1.0.1 (July 1, 2010)
|
60
89
|
|
90
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.0.0...v1.0.1)
|
91
|
+
|
61
92
|
* Fixed specs and features so they pass on MRI 1.9.2-preview3 and JRuby 1.5.1.
|
62
93
|
* Normalized response and request headers so that they are stored the same (i.e. lower case keys, arrays of values)
|
63
94
|
in the cassette yaml files, regardless of which HTTP library is used. This is the same way Net::HTTP normalizes
|
@@ -68,6 +99,8 @@
|
|
68
99
|
|
69
100
|
## 1.0.0 (June 22, 2010)
|
70
101
|
|
102
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v0.4.1...v1.0.0)
|
103
|
+
|
71
104
|
* New Features
|
72
105
|
* Added support for [HTTPClient](http://github.com/nahi/httpclient), [Patron](http://github.com/toland/patron) and
|
73
106
|
[em-http-request](http://github.com/igrigorik/em-http-request) when WebMock is used. Any future http libraries
|
@@ -101,11 +134,17 @@
|
|
101
134
|
* Removed some extensions that are no longer necessary.
|
102
135
|
|
103
136
|
## 0.4.1 May 11, 2010
|
137
|
+
|
138
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v0.4.0...v0.4.1)
|
139
|
+
|
104
140
|
* Fixed a bug: when `Net::HTTPResponse#read_body` was called after VCR had read the body to record a new request,
|
105
141
|
it raised an error (`IOError: Net::HTTPResponse#read_body called twice`). My fix extends Net::HTTPResponse
|
106
142
|
so that it no longer raises this error.
|
107
143
|
|
108
144
|
## 0.4.0 April 28, 2010
|
145
|
+
|
146
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v0.3.1...v0.4.0)
|
147
|
+
|
109
148
|
* Added support for webmock. All the fakeweb-specific code is now in an adapter (as is the webmock code).
|
110
149
|
|
111
150
|
* Changed the format of the VCR cassettes. The old format was tied directly to Net::HTTP, but webmock supports
|
@@ -131,9 +170,15 @@
|
|
131
170
|
* Lots of other refactoring.
|
132
171
|
|
133
172
|
## 0.3.1 April 10, 2010
|
173
|
+
|
174
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v0.3.0...v0.3.1)
|
175
|
+
|
134
176
|
* Fixed a bug: when `Net::HTTP#request` was called with a block that had a return statement, the response was not being recorded.
|
135
177
|
|
136
178
|
## 0.3.0 March 24, 2010
|
179
|
+
|
180
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v0.2.0...v0.3.0)
|
181
|
+
|
137
182
|
* Renamed a bunch of methods, replacing them with method names that more clearly fit the VCR/cassette metaphor:
|
138
183
|
* `VCR.create_cassette!` => `VCR.insert_cassette`
|
139
184
|
* `VCR.destroy_cassette!` => `VCR.eject_cassette`
|
@@ -146,12 +191,18 @@
|
|
146
191
|
* All the old methods still work, but you'll get deprecation warnings.
|
147
192
|
|
148
193
|
## 0.2.0 March 9, 2010
|
194
|
+
|
195
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v0.1.2...v0.2.0)
|
196
|
+
|
149
197
|
* Added `:allow_real_http` cassette option, which allows VCR to work with capybara and a javascript driver.
|
150
198
|
Bug reported by [Ben Hutton](http://github.com/benhutton).
|
151
199
|
|
152
200
|
* Deprecated the `default_cassette_record_mode` option. Use `default_cassette_options[:record_mode]` instead.
|
153
201
|
|
154
202
|
## 0.1.2 March 4, 2010
|
203
|
+
|
204
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v0.1.1...v0.1.2)
|
205
|
+
|
155
206
|
* Added explanatory note about VCR to `FakeWeb::NetConnectNotAllowedError#message`.
|
156
207
|
|
157
208
|
* Got things to work for when a cassette records multiple requests made to the same URL with the same HTTP verb,
|
@@ -161,7 +212,13 @@
|
|
161
212
|
Internally, `Net::HTTP#request` recursively calls itself (passing slightly different arguments) in certain circumstances.
|
162
213
|
|
163
214
|
## 0.1.1 February 25, 2010
|
215
|
+
|
216
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v0.1.0...v0.1.1)
|
217
|
+
|
164
218
|
* Handle asynchronous HTTP requests (such as for mechanize). Bug reported by [Thibaud Guillaume-Gentil](http://github.com/thibaudgg).
|
165
219
|
|
166
220
|
## 0.1.0 February 25, 2010
|
221
|
+
|
222
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/d2577f79247d7db60bf160881b1b64e9fa10e4fd...v0.1.0)
|
223
|
+
|
167
224
|
* Initial release. Basic recording and replaying of responses works.
|
data/Gemfile
CHANGED
@@ -2,19 +2,17 @@ source :rubygems
|
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
group :development do
|
5
|
-
# Our specs rely on something in rspec-core master that hasn't been released yet.
|
6
|
-
gem 'rspec-core', :git => 'git://github.com/rspec/rspec-core.git'
|
7
|
-
|
8
5
|
# patron and em-http-request can't install on JRuby, so we have to limit their platform here.
|
9
6
|
platforms :ruby do
|
10
7
|
gem 'patron', '~> 0.4.6'
|
11
8
|
gem 'em-http-request', '~> 0.2.7'
|
9
|
+
gem 'curb', '~> 0.7.8'
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
13
|
# Additional gems that are useful, but not required for development.
|
16
14
|
group :extras do
|
17
|
-
platforms :mri
|
15
|
+
platforms :mri do
|
18
16
|
gem 'rcov'
|
19
17
|
end
|
20
18
|
|
data/Gemfile.lock
CHANGED
@@ -1,27 +1,15 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/rspec/rspec-core.git
|
3
|
-
revision: 6258abe
|
4
|
-
specs:
|
5
|
-
rspec-core (2.0.0.beta.20)
|
6
|
-
|
7
1
|
PATH
|
8
2
|
remote: .
|
9
3
|
specs:
|
10
|
-
vcr (1.
|
4
|
+
vcr (1.2.0)
|
11
5
|
|
12
6
|
GEM
|
13
7
|
remote: http://rubygems.org/
|
14
8
|
specs:
|
15
|
-
addressable (2.2.
|
9
|
+
addressable (2.2.2)
|
16
10
|
archive-tar-minitar (0.5.2)
|
11
|
+
aruba (0.2.1)
|
17
12
|
builder (2.1.2)
|
18
|
-
capybara (0.3.9)
|
19
|
-
culerity (>= 0.2.4)
|
20
|
-
mime-types (>= 1.16)
|
21
|
-
nokogiri (>= 1.3.3)
|
22
|
-
rack (>= 1.0.0)
|
23
|
-
rack-test (>= 0.5.4)
|
24
|
-
selenium-webdriver (>= 0.0.3)
|
25
13
|
columnize (0.3.1)
|
26
14
|
crack (0.1.8)
|
27
15
|
cucumber (0.8.5)
|
@@ -30,16 +18,13 @@ GEM
|
|
30
18
|
gherkin (~> 2.1.4)
|
31
19
|
json_pure (~> 1.4.3)
|
32
20
|
term-ansicolor (~> 1.0.4)
|
33
|
-
|
21
|
+
curb (0.7.8)
|
34
22
|
diff-lcs (1.1.2)
|
35
|
-
em-http-request (0.2.
|
23
|
+
em-http-request (0.2.12)
|
36
24
|
addressable (>= 2.0.0)
|
37
25
|
eventmachine (>= 0.12.9)
|
38
26
|
eventmachine (0.12.10)
|
39
27
|
fakeweb (1.3.0)
|
40
|
-
ffi (0.6.3)
|
41
|
-
rake (>= 0.8.7)
|
42
|
-
ffi (0.6.3-java)
|
43
28
|
gherkin (2.1.5)
|
44
29
|
trollop (~> 1.16.2)
|
45
30
|
gherkin (2.1.5-java)
|
@@ -49,24 +34,20 @@ GEM
|
|
49
34
|
linecache (0.43)
|
50
35
|
linecache19 (0.5.11)
|
51
36
|
ruby_core_source (>= 0.1.4)
|
52
|
-
|
53
|
-
|
54
|
-
nokogiri (1.4.3.1-java)
|
55
|
-
weakling (>= 0.0.3)
|
56
|
-
patron (0.4.6)
|
57
|
-
rack (1.2.0)
|
58
|
-
rack-test (0.5.4)
|
59
|
-
rack (>= 1.0)
|
37
|
+
patron (0.4.9)
|
38
|
+
rack (1.1.0)
|
60
39
|
rake (0.8.7)
|
61
|
-
rcov (0.9.
|
62
|
-
|
63
|
-
|
64
|
-
rspec-
|
65
|
-
rspec-
|
66
|
-
|
67
|
-
rspec-expectations (2.0.0
|
40
|
+
rcov (0.9.9)
|
41
|
+
rspec (2.0.0)
|
42
|
+
rspec-core (= 2.0.0)
|
43
|
+
rspec-expectations (= 2.0.0)
|
44
|
+
rspec-mocks (= 2.0.0)
|
45
|
+
rspec-core (2.0.0)
|
46
|
+
rspec-expectations (2.0.0)
|
68
47
|
diff-lcs (>= 1.1.2)
|
69
|
-
rspec-mocks (2.0.0
|
48
|
+
rspec-mocks (2.0.0)
|
49
|
+
rspec-core (= 2.0.0)
|
50
|
+
rspec-expectations (= 2.0.0)
|
70
51
|
ruby-debug (0.10.3)
|
71
52
|
columnize (>= 0.1)
|
72
53
|
ruby-debug-base (~> 0.10.3.0)
|
@@ -82,16 +63,11 @@ GEM
|
|
82
63
|
ruby-debug-base19 (>= 0.11.19)
|
83
64
|
ruby_core_source (0.1.4)
|
84
65
|
archive-tar-minitar (>= 0.5.2)
|
85
|
-
rubyzip (0.9.4)
|
86
|
-
selenium-webdriver (0.0.28)
|
87
|
-
ffi (>= 0.6.1)
|
88
|
-
json_pure
|
89
|
-
rubyzip
|
90
66
|
term-ansicolor (1.0.5)
|
67
|
+
timecop (0.3.5)
|
91
68
|
trollop (1.16.2)
|
92
|
-
|
93
|
-
|
94
|
-
addressable (>= 2.1.1)
|
69
|
+
webmock (1.4.0)
|
70
|
+
addressable (>= 2.2.2)
|
95
71
|
crack (>= 0.1.7)
|
96
72
|
|
97
73
|
PLATFORMS
|
@@ -99,20 +75,21 @@ PLATFORMS
|
|
99
75
|
ruby
|
100
76
|
|
101
77
|
DEPENDENCIES
|
78
|
+
aruba (~> 0.2.1)
|
102
79
|
bundler (~> 1.0.0)
|
103
|
-
capybara (~> 0.3.9)
|
104
80
|
cucumber (~> 0.8.5)
|
81
|
+
curb (~> 0.7.8)
|
105
82
|
em-http-request (~> 0.2.7)
|
106
83
|
fakeweb (~> 1.3.0)
|
107
84
|
httpclient (~> 2.1.5.2)
|
108
85
|
patron (~> 0.4.6)
|
109
|
-
rack (= 1.
|
86
|
+
rack (= 1.1.0)
|
110
87
|
rake (~> 0.8.7)
|
111
88
|
rcov
|
112
|
-
rspec (~> 2.0.0
|
113
|
-
rspec-core!
|
89
|
+
rspec (~> 2.0.0)
|
114
90
|
ruby-debug
|
115
91
|
ruby-debug-base19 (= 0.11.23)
|
116
92
|
ruby-debug19
|
93
|
+
timecop (~> 0.3.5)
|
117
94
|
vcr!
|
118
|
-
webmock (~> 1.
|
95
|
+
webmock (~> 1.4.0)
|
data/README.md
CHANGED
@@ -43,19 +43,24 @@ maintenance) and accurate (the response from example.com will contain the same h
|
|
43
43
|
* Automatically records and replays your HTTP interactions with minimal setup/configuration code.
|
44
44
|
* Supports multiple HTTP stubbing libraries. Currently FakeWeb and WebMock are supported, and the adapter interface
|
45
45
|
is easy to implement for any future libraries.
|
46
|
-
* Supports multiple HTTP libraries:
|
47
|
-
|
48
|
-
[
|
49
|
-
[
|
46
|
+
* Supports multiple HTTP libraries:
|
47
|
+
* [Patron](http://github.com/toland/patron) (WebMock)
|
48
|
+
* [Curb](http://github.com/taf2/curb) (WebMock)
|
49
|
+
* [HTTPClient](http://github.com/nahi/httpclient) (WebMock)
|
50
|
+
* [em-http-request](http://github.com/igrigorik/em-http-request) (WebMock)
|
51
|
+
* [Net::HTTP](http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html) (FakeWeb and WebMock)
|
52
|
+
* And of course any library built on Net::HTTP, such as [Mechanize](http://github.com/tenderlove/mechanize),
|
53
|
+
[HTTParty](http://github.com/jnunemaker/httparty) or [Rest Client](http://github.com/archiloque/rest-client).
|
50
54
|
* Request matching is configurable based on HTTP method, URI, host, path, body and headers.
|
51
55
|
* The same request can receive different responses in different tests--just use different cassettes.
|
52
56
|
* The recorded requests and responses are stored on disk as YAML and can easily be inspected and edited.
|
53
57
|
* Dynamic responses are supported using ERB.
|
58
|
+
* Automatically re-records cassettes on a configurable regular interval to keep them fresh and current.
|
54
59
|
* Disables all HTTP requests that you don't explicitly allow.
|
55
60
|
* Simple cucumber integration is provided using tags.
|
56
|
-
* Known to work well with many popular ruby libraries including RSpec, Cucumber, Test::Unit,
|
57
|
-
Rest-Client.
|
58
|
-
* Extensively tested on
|
61
|
+
* Known to work well with many popular ruby libraries including RSpec 1 & 2, Cucumber, Test::Unit,
|
62
|
+
Capybara, Mechanize and Rest-Client.
|
63
|
+
* Extensively tested on 7 different ruby interpretters.
|
59
64
|
|
60
65
|
## Development
|
61
66
|
|
@@ -74,11 +79,15 @@ a cassette that contains previously recorded HTTP interactions, it registers the
|
|
74
79
|
library of your choice (fakeweb or webmock) so that HTTP requests get the recorded response. Between test
|
75
80
|
runs, cassettes are stored on disk as YAML files in your configured cassette library directory.
|
76
81
|
|
77
|
-
Each cassette
|
82
|
+
Each cassette acts a bit like a sandbox: it has an effect on HTTP requests during the current test while it
|
83
|
+
is inserted, but has no effect on the rest of your test suite.
|
84
|
+
|
85
|
+
Cassettes can be configured with a few options:
|
78
86
|
|
79
87
|
* `:record`: Specifies a record mode for this cassette.
|
80
88
|
* `:erb`: Used for dynamic cassettes (see below for more details).
|
81
89
|
* `:match_requests_on`: An array of request attributes to match on (see below for more details).
|
90
|
+
* `:re_record_interval`: Controls automatic re-recording of the cassette (see below for more details).
|
82
91
|
|
83
92
|
## Record modes
|
84
93
|
|
@@ -86,8 +95,18 @@ VCR supports 3 record modes. You can set a default record mode in your configur
|
|
86
95
|
and a per-cassette record mode when inserting a cassette. The record modes are:
|
87
96
|
|
88
97
|
* `:new_episodes`: Previously recorded HTTP interactions will be replayed. New HTTP interactions will be recorded.
|
98
|
+
This is generally the most useful mode. VCR will automatically record and replay new HTTP requests as your
|
99
|
+
codebase evolves to make new requests.
|
89
100
|
* `:all`: Previously recorded HTTP interactions will be ignored. All HTTP interactions will be recorded.
|
101
|
+
This is useful if you're interested in using VCR to log your HTTP interactions but don't care to ever replay
|
102
|
+
them. Alternately, you can temporarily change your record mode to `:all` to force it to re-record all requests.
|
90
103
|
* `:none`: Previously recorded HTTP interactions will be replayed. New HTTP interactions will result in an error.
|
104
|
+
This mode is useful when your code makes potentially dangerous HTTP requests (i.e. it hits a production
|
105
|
+
server rather than a sandbox/staging server), as it will prevent any new requests from completing, raising
|
106
|
+
an error instead. Generally, you will temporarily use the `:new_episodes` or `:all` record modes
|
107
|
+
to perform the initial recording before changing it to `:none`.
|
108
|
+
|
109
|
+
When no cassette is inserted, all HTTP requests will result in a `Real HTTP connections are disabled` error.
|
91
110
|
|
92
111
|
## Request Matching
|
93
112
|
|
@@ -139,9 +158,7 @@ configuration options:
|
|
139
158
|
`RAILS_ROOT/test/fixtures`. Rails will assume your cassette YAML files are ActiveRecord fixtures and raise an
|
140
159
|
error when the content doesn't conform to its expectations.
|
141
160
|
* `http_stubbing_library`: Which http stubbing library to use. Currently `:fakeweb` and `:webmock` are supported.
|
142
|
-
|
143
|
-
constants, but this is mostly done to assist users upgrading from VCR 0.3.1, which only worked with fakeweb and
|
144
|
-
didn't have this option. I recommend you explicitly configure this.
|
161
|
+
VCR will automatically configure FakeWeb/WebMock for you; you do not need to reference either one at all.
|
145
162
|
* `ignore_localhost`: Defaults to false. Setting it true does the following:
|
146
163
|
* Localhost requests will proceed as normal. The "Real HTTP connections are disabled" error will not occur.
|
147
164
|
* Localhost requests will not be recorded.
|
@@ -157,32 +174,66 @@ VCR can easily be used with any ruby test or spec framework. Usually, you'll wa
|
|
157
174
|
# do something that makes an HTTP request
|
158
175
|
end
|
159
176
|
|
160
|
-
Alternately, you can insert and eject a
|
177
|
+
Alternately, with a framework like [shoulda](http://github.com/thoughtbot/shoulda), you can insert and eject a
|
178
|
+
cassette with individual method calls from setup and teardown:
|
161
179
|
|
162
|
-
|
163
|
-
|
180
|
+
context "Some object that makes an HTTP request" do
|
181
|
+
setup do
|
164
182
|
VCR.insert_cassette('geocoding/Seattle, WA', :record => :new_episodes)
|
165
183
|
end
|
166
184
|
|
167
|
-
|
185
|
+
should "make an HTTP request" do
|
186
|
+
# ...
|
187
|
+
end
|
168
188
|
|
169
|
-
|
189
|
+
should "make another HTTP request" do
|
190
|
+
# ...
|
191
|
+
end
|
170
192
|
|
171
|
-
|
193
|
+
teardown do
|
172
194
|
VCR.eject_cassette
|
173
195
|
end
|
174
196
|
end
|
175
197
|
|
176
|
-
|
198
|
+
## Usage with RSpec
|
199
|
+
|
200
|
+
If you're using RSpec, you can use a special macro provided by VCR:
|
201
|
+
|
202
|
+
describe MyApiClient do
|
203
|
+
context "create" do
|
204
|
+
# Pass use_vcr_cassette the same args you would pass VCR.use_cassette.
|
205
|
+
use_vcr_cassette "my_api_client/create", :record => :new_episodes
|
177
206
|
|
178
|
-
|
179
|
-
|
180
|
-
VCR.use_cassette('geocoding/Seattle, WA', :record => :new_episodes, &example)
|
207
|
+
it "makes an HTTP request"
|
208
|
+
it "makes another HTTP request"
|
181
209
|
end
|
182
210
|
|
183
|
-
|
211
|
+
context "destroy" do
|
212
|
+
# You can leave off the cassette name and it will be inferred from the example group
|
213
|
+
# descriptions--in this case "MyApiClient/destroy".
|
214
|
+
# You can also leave off the options hash--the configured default options will be used.
|
215
|
+
use_vcr_cassette :record => :new_episodes, :match_requests_on => [:uri, :method, :body]
|
216
|
+
|
217
|
+
it "makes an HTTP request"
|
218
|
+
it "makes another HTTP request"
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
To use this, you need to configure RSpec to make the `use_vcr_cassette` available as a macro.
|
223
|
+
Here's how to do that for RSpec 1:
|
224
|
+
|
225
|
+
require 'vcr'
|
226
|
+
|
227
|
+
Spec::Runner.configure do |c|
|
228
|
+
c.extend VCR::RSpec::Macros
|
229
|
+
end
|
230
|
+
|
231
|
+
Or for RSpec 2:
|
232
|
+
|
233
|
+
require 'vcr'
|
184
234
|
|
185
|
-
|
235
|
+
RSpec.configure do |c|
|
236
|
+
c.extend VCR::RSpec::Macros
|
186
237
|
end
|
187
238
|
|
188
239
|
## Usage with Cucumber
|
@@ -274,6 +325,21 @@ In your cassette:
|
|
274
325
|
...
|
275
326
|
body: Hello, <%= user.name %>!
|
276
327
|
|
328
|
+
## Automatic cassette re-recording
|
329
|
+
|
330
|
+
Over time, your cassettes may get out-of-date. APIs change and sites you scrape get updated. VCR provides
|
331
|
+
a facility to automatically re-record your cassettes. You enable re-recording using the
|
332
|
+
`:re_record_interval` option:
|
333
|
+
|
334
|
+
A_WEEK = 7 * 24 * 60 * 60 # or use 7.days if you're using ActiveSupport
|
335
|
+
|
336
|
+
VCR.use_cassette('my_cassette', :re_record_interval => A_WEEK) { ... }
|
337
|
+
|
338
|
+
If the cassette file was last modified more than 7 days ago, VCR will use the `:all` record mode (regardless
|
339
|
+
of the configured record mode) to allow new HTTP requests and record them. VCR will check to make sure you
|
340
|
+
have an internet connection before doing this, so if you are running the tests without one, the automatic
|
341
|
+
re-recording will not kick in.
|
342
|
+
|
277
343
|
## FakeWeb or WebMock?
|
278
344
|
|
279
345
|
VCR works fine with either FakeWeb or WebMock. Overall, WebMock has more features, and you'll need to use
|
@@ -333,6 +399,7 @@ VCR has been tested on the following ruby interpreters:
|
|
333
399
|
* MRI 1.9.2-p0
|
334
400
|
* REE 1.8.7-2010.02
|
335
401
|
* JRuby 1.5.1
|
402
|
+
* Rubinius 1.1
|
336
403
|
|
337
404
|
## Notes, etc.
|
338
405
|
|
@@ -373,6 +440,8 @@ how VCR could be improved. You may also want to try one of these similar librar
|
|
373
440
|
* [Stale Fish](http://github.com/jsmestad/stale_fish)
|
374
441
|
* [NetRecorder](http://github.com/chrisyoung/netrecorder)
|
375
442
|
* [Ephemeral Response](http://github.com/sandro/ephemeral_response)
|
443
|
+
* [Net::HTTP Spy](http://github.com/martinbtt/net-http-spy)
|
444
|
+
* [WebFixtures](http://github.com/trydionel/web_fixtures)
|
376
445
|
|
377
446
|
## Copyright
|
378
447
|
|