vcr 1.4.0 → 1.5.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/CHANGELOG.md +23 -0
- data/Gemfile +0 -2
- data/Gemfile.lock +15 -14
- data/Guardfile +2 -3
- data/LICENSE +1 -1
- data/README.md +5 -1
- data/features/.nav +28 -0
- data/features/README.md +1 -1
- data/features/cassettes/automatic_re_recording.feature +2 -2
- data/features/cassettes/format.feature +2 -2
- data/features/cassettes/no_cassette.feature +3 -3
- data/features/cassettes/request_matching.feature +8 -8
- data/features/configuration/allow_http_connections_when_no_cassette.feature +1 -1
- data/features/configuration/cassette_library_dir.feature +1 -1
- data/features/configuration/default_cassette_options.feature +2 -2
- data/features/configuration/hooks.feature +276 -0
- data/features/configuration/ignore_localhost.feature +1 -1
- data/features/configuration/stub_with.feature +19 -20
- data/features/middleware/rack.feature +6 -6
- data/features/{cassettes/record_modes → record_modes}/all.feature +2 -2
- data/features/{cassettes/record_modes → record_modes}/new_episodes.feature +3 -3
- data/features/{cassettes/record_modes → record_modes}/none.feature +4 -4
- data/features/support/vcr_cucumber_helpers.rb +1 -1
- data/features/test_frameworks/cucumber.feature +11 -11
- data/features/test_frameworks/rspec.feature +12 -12
- data/features/test_frameworks/shoulda.feature +1 -1
- data/lib/vcr.rb +8 -4
- data/lib/vcr/cassette.rb +28 -39
- data/lib/vcr/cassette/reader.rb +58 -0
- data/lib/vcr/config.rb +45 -40
- data/lib/vcr/deprecations.rb +1 -1
- data/lib/vcr/extensions/net_http.rb +6 -1
- data/lib/vcr/hooks.rb +45 -0
- data/lib/vcr/http_stubbing_adapters/common.rb +16 -13
- data/lib/vcr/http_stubbing_adapters/fakeweb.rb +4 -4
- data/lib/vcr/http_stubbing_adapters/faraday.rb +4 -4
- data/lib/vcr/http_stubbing_adapters/typhoeus.rb +4 -4
- data/lib/vcr/http_stubbing_adapters/webmock.rb +4 -4
- data/lib/vcr/structs.rb +8 -0
- data/lib/vcr/{basic_object.rb → util/basic_object.rb} +0 -0
- data/lib/vcr/{internet_connection.rb → util/internet_connection.rb} +1 -1
- data/lib/vcr/{ping.rb → util/ping.rb} +0 -0
- data/lib/vcr/version.rb +1 -1
- data/script/FullBuildRakeFile +6 -0
- data/script/full_build +1 -1
- data/script/spec +1 -0
- data/spec/fixtures/1.9.1/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/not_1.9.1/cassette_spec/empty.yml +0 -0
- data/spec/spec_helper.rb +7 -4
- data/spec/support/http_library_adapters.rb +8 -0
- data/spec/support/http_stubbing_adapter.rb +2 -2
- data/spec/vcr/cassette/reader_spec.rb +59 -0
- data/spec/{cassette_spec.rb → vcr/cassette_spec.rb} +115 -54
- data/spec/{config_spec.rb → vcr/config_spec.rb} +0 -0
- data/spec/{cucumber_tags_spec.rb → vcr/cucumber_tags_spec.rb} +0 -0
- data/spec/{deprecations_spec.rb → vcr/deprecations_spec.rb} +0 -0
- data/spec/{extensions → vcr/extensions}/net_http_response_spec.rb +0 -0
- data/spec/{extensions → vcr/extensions}/net_http_spec.rb +0 -0
- data/spec/vcr/hooks_spec.rb +95 -0
- data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/fakeweb_spec.rb +0 -0
- data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/faraday_spec.rb +5 -3
- data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/multi_object_proxy_spec.rb +0 -0
- data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/typhoeus_spec.rb +0 -0
- data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/webmock_spec.rb +0 -0
- data/spec/{middleware → vcr/middleware}/cassette_arguments_spec.rb +0 -0
- data/spec/{middleware → vcr/middleware}/faraday_spec.rb +0 -0
- data/spec/{middleware → vcr/middleware}/rack_spec.rb +0 -0
- data/spec/{request_matcher_spec.rb → vcr/request_matcher_spec.rb} +0 -0
- data/spec/{rspec_spec.rb → vcr/rspec_spec.rb} +0 -0
- data/spec/{structs_spec.rb → vcr/structs_spec.rb} +15 -4
- data/spec/{internet_connection_spec.rb → vcr/util/internet_connection_spec.rb} +0 -0
- data/spec/{version_spec.rb → vcr/version_spec.rb} +0 -0
- data/spec/vcr_spec.rb +10 -3
- data/vcr.gemspec +3 -3
- metadata +123 -101
- data/spec/fixtures/1.9.1/cassette_spec/erb_with_no_vars.yml +0 -32
- data/spec/fixtures/1.9.1/cassette_spec/erb_with_vars.yml +0 -32
- data/spec/fixtures/not_1.9.1/cassette_spec/erb_with_no_vars.yml +0 -32
- data/spec/fixtures/not_1.9.1/cassette_spec/erb_with_vars.yml +0 -32
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## In git
|
4
|
+
|
5
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.5.0...master)
|
6
|
+
|
7
|
+
## 1.5.0 (January 12, 2011)
|
8
|
+
|
9
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.4.0...v1.5.0)
|
10
|
+
|
11
|
+
* Fix VCR::Cassette so it does not raise an error when a cassette file is
|
12
|
+
empty. Bug reported and fixed by [Karl Baum](https://github.com/kbaum).
|
13
|
+
* Lots of code cleanup.
|
14
|
+
* Fix the stubbing adapters so that they use the cassette instance
|
15
|
+
rather than the cassette name to create and restore checkpoints.
|
16
|
+
* Raise an appropriate error when a nested cassette is inserted with the
|
17
|
+
same name as a cassette that is already in the stack (VCR's design
|
18
|
+
doesn't allow this and you would get weird errors later on).
|
19
|
+
* Raise an appropriate error when restoring a stubs checkpoint if the
|
20
|
+
checkpoint cannot be found.
|
21
|
+
* Add `before_record` and `before_playback` hooks. Idea and initial
|
22
|
+
implementation by [Oliver Searle-Barnes](https://github.com/opsb);
|
23
|
+
futher suggestions, testing and feedback by
|
24
|
+
[Nathaniel Bibler](https://github.com/nbibler).
|
25
|
+
|
3
26
|
## 1.4.0 (December 3, 2010)
|
4
27
|
|
5
28
|
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.3.3...v1.4.0)
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vcr (1.
|
4
|
+
vcr (1.5.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
@@ -29,12 +29,13 @@ GEM
|
|
29
29
|
addressable (>= 2.0.0)
|
30
30
|
eventmachine (>= 0.12.9)
|
31
31
|
eventmachine (0.12.10)
|
32
|
+
eventmachine (0.12.10-java)
|
32
33
|
fakeweb (1.3.0)
|
33
34
|
faraday (0.5.3)
|
34
35
|
addressable (~> 2.2.2)
|
35
36
|
multipart-post (~> 1.0.1)
|
36
37
|
rack (>= 1.1.0, < 2)
|
37
|
-
fuubar (0.0.
|
38
|
+
fuubar (0.0.3)
|
38
39
|
rspec (~> 2.0)
|
39
40
|
rspec-instafail (~> 0.1.4)
|
40
41
|
ruby-progressbar (~> 0.0.9)
|
@@ -73,21 +74,21 @@ GEM
|
|
73
74
|
rake (0.8.7)
|
74
75
|
rb-fsevent (0.3.6)
|
75
76
|
rcov (0.9.9)
|
76
|
-
relish (0.
|
77
|
+
relish (0.2.0)
|
77
78
|
archive-tar-minitar (~> 0.5.2)
|
78
79
|
json (~> 1.4.6)
|
79
80
|
rest-client (~> 1.6.1)
|
80
81
|
rest-client (1.6.1)
|
81
82
|
mime-types (>= 1.16)
|
82
|
-
rspec (2.
|
83
|
-
rspec-core (~> 2.
|
84
|
-
rspec-expectations (~> 2.
|
85
|
-
rspec-mocks (~> 2.
|
86
|
-
rspec-core (2.
|
87
|
-
rspec-expectations (2.
|
83
|
+
rspec (2.4.0)
|
84
|
+
rspec-core (~> 2.4.0)
|
85
|
+
rspec-expectations (~> 2.4.0)
|
86
|
+
rspec-mocks (~> 2.4.0)
|
87
|
+
rspec-core (2.4.0)
|
88
|
+
rspec-expectations (2.4.0)
|
88
89
|
diff-lcs (~> 1.1.2)
|
89
|
-
rspec-instafail (0.1.
|
90
|
-
rspec-mocks (2.
|
90
|
+
rspec-instafail (0.1.5)
|
91
|
+
rspec-mocks (2.4.0)
|
91
92
|
ruby-debug (0.10.3)
|
92
93
|
columnize (>= 0.1)
|
93
94
|
ruby-debug-base (~> 0.10.3.0)
|
@@ -113,7 +114,7 @@ GEM
|
|
113
114
|
tilt (1.1)
|
114
115
|
timecop (0.3.5)
|
115
116
|
typhoeus (0.2.0)
|
116
|
-
webmock (1.6.
|
117
|
+
webmock (1.6.2)
|
117
118
|
addressable (>= 2.2.2)
|
118
119
|
crack (>= 0.1.7)
|
119
120
|
|
@@ -141,11 +142,11 @@ DEPENDENCIES
|
|
141
142
|
rb-fsevent
|
142
143
|
rcov
|
143
144
|
relish
|
144
|
-
rspec (~> 2.
|
145
|
+
rspec (~> 2.4.0)
|
145
146
|
ruby-debug
|
146
147
|
ruby-debug-base19 (= 0.11.23)
|
147
148
|
ruby-debug19
|
148
|
-
shoulda
|
149
|
+
shoulda (~> 2.9.2)
|
149
150
|
sinatra (~> 1.1.0)
|
150
151
|
timecop (~> 0.3.5)
|
151
152
|
typhoeus (~> 0.2.0)
|
data/Guardfile
CHANGED
@@ -3,9 +3,8 @@
|
|
3
3
|
|
4
4
|
guard 'rspec', :version => 2 do
|
5
5
|
watch('^spec/(.*)_spec.rb')
|
6
|
-
watch('^lib/
|
7
|
-
watch('^
|
8
|
-
watch('^spec/spec_helper.rb') { "spec" }
|
6
|
+
watch('^lib/(.*)\.rb') { |m| "spec/#{m[1]}_spec.rb" }
|
7
|
+
watch('^spec/spec_helper.rb') { "spec" }
|
9
8
|
end
|
10
9
|
|
11
10
|
guard 'cucumber' do
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,7 @@ Record your test suite's HTTP interactions and replay them during future test ru
|
|
4
4
|
|
5
5
|
## Synopsis
|
6
6
|
|
7
|
+
require 'rubygems'
|
7
8
|
require 'test/unit'
|
8
9
|
require 'vcr'
|
9
10
|
|
@@ -87,7 +88,10 @@ Thanks also to the following people who have contributed patches or helpful sugg
|
|
87
88
|
* [Bartosz Blimke](http://github.com/bblimke)
|
88
89
|
* [Ben Hutton](http://github.com/benhutton)
|
89
90
|
* [Eric Allam](http://github.com/rubymaverick)
|
91
|
+
* [Karl Baum](https://github.com/kbaum)
|
92
|
+
* [Nathaniel Bibler](https://github.com/nbibler)
|
93
|
+
* [Oliver Searle-Barnes](https://github.com/opsb)
|
90
94
|
|
91
95
|
## Copyright
|
92
96
|
|
93
|
-
Copyright (c) 2010 Myron Marston. See LICENSE for details.
|
97
|
+
Copyright (c) 2010-2011 Myron Marston. See LICENSE for details.
|
data/features/.nav
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
- cassettes:
|
2
|
+
- format.feature
|
3
|
+
- no_cassette.feature
|
4
|
+
- request_matching.feature
|
5
|
+
- dynamic_erb.feature
|
6
|
+
- automatic_re_recording.feature
|
7
|
+
- record_modes:
|
8
|
+
- new_episodes.feature
|
9
|
+
- none.feature
|
10
|
+
- all.feature
|
11
|
+
- configuration:
|
12
|
+
- cassette_library_dir.feature
|
13
|
+
- stub_with.feature
|
14
|
+
- default_cassette_options.feature
|
15
|
+
- ignore_localhost.feature
|
16
|
+
- hooks.feature
|
17
|
+
- allow_http_connections_when_no_cassette.feature
|
18
|
+
- test_frameworks:
|
19
|
+
- test_unit.feature
|
20
|
+
- shoulda.feature
|
21
|
+
- rspec.feature
|
22
|
+
- cucumber.feature
|
23
|
+
- middleware:
|
24
|
+
- rack.feature
|
25
|
+
- faraday.feature
|
26
|
+
- http_libraries:
|
27
|
+
- net_http.feature
|
28
|
+
- em_http_request.feature
|
data/features/README.md
CHANGED
@@ -12,7 +12,7 @@ provided by `vcr_cucumber_helpers.rb`:
|
|
12
12
|
the replaying of a recorded HTTP response.
|
13
13
|
* `include_http_adapter_for`: includes a module that implements a common
|
14
14
|
HTTP interface for the given HTTP library. The `response_body_for`
|
15
|
-
method will make an HTTP request using the given
|
15
|
+
method will make an HTTP request using the given library. This
|
16
16
|
allows scenarios to be run against each different supported HTTP
|
17
17
|
library.
|
18
18
|
|
@@ -2,12 +2,12 @@ Feature: Automatic Re-recording
|
|
2
2
|
|
3
3
|
Over time, your cassettes may get out-of-date. APIs change and sites you
|
4
4
|
scrape get updated. VCR provides a facility to automatically re-record your
|
5
|
-
cassettes. Enable re-recording using the
|
5
|
+
cassettes. Enable re-recording using the `:re_record_interval` option.
|
6
6
|
|
7
7
|
The value provided should be an interval (expressed in seconds) that
|
8
8
|
determines how often VCR will re-record the cassette. When a cassette
|
9
9
|
is used, VCR checks the file modification time; if more time than the
|
10
|
-
interval has passed, VCR will use the
|
10
|
+
interval has passed, VCR will use the `:all` record mode to cause it be
|
11
11
|
re-recorded.
|
12
12
|
|
13
13
|
Background:
|
@@ -5,8 +5,8 @@ Feature: Cassette format
|
|
5
5
|
human-readable/editable format. A cassette contains an array
|
6
6
|
of HTTP interactions, each of which has the following:
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
- Request method, uri, body, headers
|
9
|
+
- Response status (code & message), headers, body, http version
|
10
10
|
|
11
11
|
Scenario Outline: Request/Response data is saved to disk as YAML
|
12
12
|
Given a file named "cassette_format.rb" with:
|
@@ -11,9 +11,9 @@ Feature: Error for HTTP request made when no cassette is in use
|
|
11
11
|
(see configuration/allow_http_connections_when_no_cassette.feature) or
|
12
12
|
you can temporarily turn VCR off:
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
- `VCR.turn_off!` => turn VCR off so HTTP requests are allowed
|
15
|
+
- `VCR.turn_on!` => turn VCR back on
|
16
|
+
- `VCR.turned_off { ... }` => turn VCR off for the duration of the
|
17
17
|
provided block.
|
18
18
|
|
19
19
|
Scenario Outline: Error for request when no cassette is in use
|
@@ -8,16 +8,16 @@ Feature: Request matching
|
|
8
8
|
You can customize how VCR matches requests using the `:match_requests_on` option.
|
9
9
|
Specify an array of attributes to match on. Supported attributes are:
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
with
|
11
|
+
- `:method` - The HTTP method (i.e. GET, POST, PUT or DELETE) of the request.
|
12
|
+
- `:uri` - The full URI of the request.
|
13
|
+
- `:host` - The host of the URI. You can use this (alone, or in combination
|
14
|
+
with `:path`) as an alternative to `:uri` to cause VCR to match using a regex
|
15
15
|
that matches the host.
|
16
|
-
|
17
|
-
with
|
16
|
+
- `:path` - The path of the URI. You can use this (alone, or in combination
|
17
|
+
with `:host`) as an alternative to `:uri` to cause VCR to match using a regex
|
18
18
|
that matches the path.
|
19
|
-
|
20
|
-
|
19
|
+
- `:body` - The body of the request. (Unsupported when you use FakeWeb.)
|
20
|
+
- `:headers` - The request headers. (Unsupported when you use FakeWeb.)
|
21
21
|
|
22
22
|
Alternately, you can manually edit a cassette and change a URI to the YAML
|
23
23
|
of a regular expression.
|
@@ -1,10 +1,10 @@
|
|
1
|
-
Feature: default_cassette_options
|
1
|
+
Feature: default_cassette_options
|
2
2
|
|
3
3
|
The `default_cassette_options` configuration option takes a hash
|
4
4
|
that provides defaults for each cassette you use. Any cassette
|
5
5
|
can override the defaults as well as set additional options.
|
6
6
|
|
7
|
-
The `:match_requests_on` option defaults to [:method, :uri] when
|
7
|
+
The `:match_requests_on` option defaults to `[:method, :uri]` when
|
8
8
|
it has not been set.
|
9
9
|
|
10
10
|
Background:
|
@@ -0,0 +1,276 @@
|
|
1
|
+
Feature: Hooks
|
2
|
+
|
3
|
+
VCR provides two global hooks that you can use to customize recording and
|
4
|
+
playback:
|
5
|
+
|
6
|
+
- `before_record`: Called before a cassette is written to disk.
|
7
|
+
- `before_playback`: Called before a cassette sets up its stubs for playback.
|
8
|
+
|
9
|
+
To use these, call `config.before_record` or `config.before_playback` in
|
10
|
+
your `VCR.config` block. Provide a block that accepts 0, 1 or 2 arguments.
|
11
|
+
|
12
|
+
The first argument, if the block accepts it, will be an HTTP interaction.
|
13
|
+
Changes you make to the interaction will be reflected in the recording or
|
14
|
+
playback. You can also call `#ignore!` on the interaction to cause VCR to
|
15
|
+
ignore it. It will not be recorded or played back (depending on which
|
16
|
+
kind of hook you use).
|
17
|
+
|
18
|
+
The second argument, if the block accepts it, will be the
|
19
|
+
`VCR::Cassette` instance. This may be useful for hooks that you want to
|
20
|
+
behave differently for different cassettes.
|
21
|
+
|
22
|
+
You can also use tagging to apply hooks to particular cassettes. Consider
|
23
|
+
this code:
|
24
|
+
|
25
|
+
VCR.config do |c|
|
26
|
+
c.before_record(:twitter) { ... } # modify the interactions somehow
|
27
|
+
end
|
28
|
+
|
29
|
+
VCR.use_cassette('cassette_1', :tag => :twitter) { ... }
|
30
|
+
VCR.use_cassette('cassette_2') { ... }
|
31
|
+
|
32
|
+
In this example, the hook would apply to the first cassette but not the
|
33
|
+
second cassette.
|
34
|
+
|
35
|
+
You can setup as many hooks as you like; each will be invoked at the
|
36
|
+
appropriate time.
|
37
|
+
|
38
|
+
Background:
|
39
|
+
Given a previously recorded cassette file "cassettes/example.yml" with:
|
40
|
+
"""
|
41
|
+
---
|
42
|
+
- !ruby/struct:VCR::HTTPInteraction
|
43
|
+
request: !ruby/struct:VCR::Request
|
44
|
+
method: :get
|
45
|
+
uri: http://example.com:80/foo
|
46
|
+
body:
|
47
|
+
headers:
|
48
|
+
response: !ruby/struct:VCR::Response
|
49
|
+
status: !ruby/struct:VCR::ResponseStatus
|
50
|
+
code: 200
|
51
|
+
message: OK
|
52
|
+
headers:
|
53
|
+
content-type:
|
54
|
+
- text/html;charset=utf-8
|
55
|
+
content-length:
|
56
|
+
- "20"
|
57
|
+
body: example.com response
|
58
|
+
http_version: "1.1"
|
59
|
+
"""
|
60
|
+
|
61
|
+
Scenario: Replace sensitive data with before_record hook
|
62
|
+
Given a file named "before_record_example.rb" with:
|
63
|
+
"""
|
64
|
+
require 'vcr_cucumber_helpers'
|
65
|
+
|
66
|
+
start_sinatra_app(:port => 7777) do
|
67
|
+
get('/') { "Hello <secret>" }
|
68
|
+
end
|
69
|
+
|
70
|
+
require 'vcr'
|
71
|
+
|
72
|
+
VCR.config do |c|
|
73
|
+
c.stub_with :fakeweb
|
74
|
+
c.cassette_library_dir = 'cassettes'
|
75
|
+
|
76
|
+
c.before_record do |i|
|
77
|
+
i.response.body.sub!(/^Hello .*$/, 'Hello World')
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
VCR.use_cassette('recording_example', :record => :new_episodes) do
|
83
|
+
Net::HTTP.get_response('localhost', '/', 7777)
|
84
|
+
end
|
85
|
+
"""
|
86
|
+
When I run "ruby before_record_example.rb"
|
87
|
+
Then the file "cassettes/recording_example.yml" should contain "body: Hello World"
|
88
|
+
And the file "cassettes/recording_example.yml" should not contain "secret"
|
89
|
+
|
90
|
+
Scenario: Prevent recording by ignoring interaction in before_record hook
|
91
|
+
Given a file named "before_record_ignore.rb" with:
|
92
|
+
"""
|
93
|
+
require 'vcr_cucumber_helpers'
|
94
|
+
|
95
|
+
start_sinatra_app(:port => 7777) do
|
96
|
+
get('/') { "Hello World" }
|
97
|
+
end
|
98
|
+
|
99
|
+
require 'vcr'
|
100
|
+
|
101
|
+
VCR.config do |c|
|
102
|
+
c.stub_with :fakeweb
|
103
|
+
c.cassette_library_dir = 'cassettes'
|
104
|
+
c.before_record { |i| i.ignore! }
|
105
|
+
end
|
106
|
+
|
107
|
+
VCR.use_cassette('recording_example', :record => :new_episodes) do
|
108
|
+
response = Net::HTTP.get_response('localhost', '/', 7777)
|
109
|
+
puts "Response: #{response.body}"
|
110
|
+
end
|
111
|
+
"""
|
112
|
+
When I run "ruby before_record_ignore.rb"
|
113
|
+
Then it should pass with "Response: Hello World"
|
114
|
+
And the file "cassettes/recording_example.yml" should not exist
|
115
|
+
|
116
|
+
Scenario: Change playback with before_playback hook
|
117
|
+
Given a file named "before_playback_example.rb" with:
|
118
|
+
"""
|
119
|
+
require 'vcr'
|
120
|
+
|
121
|
+
VCR.config do |c|
|
122
|
+
c.stub_with :fakeweb
|
123
|
+
c.cassette_library_dir = 'cassettes'
|
124
|
+
|
125
|
+
c.before_playback do |i|
|
126
|
+
i.response.body = 'response from before_playback'
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
VCR.use_cassette('example', :record => :new_episodes) do
|
131
|
+
response = Net::HTTP.get_response('example.com', '/foo')
|
132
|
+
puts "Response: #{response.body}"
|
133
|
+
end
|
134
|
+
"""
|
135
|
+
When I run "ruby before_playback_example.rb"
|
136
|
+
Then it should pass with "Response: response from before_playback"
|
137
|
+
|
138
|
+
Scenario: Prevent playback by ignoring interaction in before_playback hook
|
139
|
+
Given a previously recorded cassette file "cassettes/localhost.yml" with:
|
140
|
+
"""
|
141
|
+
---
|
142
|
+
- !ruby/struct:VCR::HTTPInteraction
|
143
|
+
request: !ruby/struct:VCR::Request
|
144
|
+
method: :get
|
145
|
+
uri: http://localhost:7777/
|
146
|
+
body:
|
147
|
+
headers:
|
148
|
+
response: !ruby/struct:VCR::Response
|
149
|
+
status: !ruby/struct:VCR::ResponseStatus
|
150
|
+
code: 200
|
151
|
+
message: OK
|
152
|
+
headers:
|
153
|
+
content-type:
|
154
|
+
- text/html;charset=utf-8
|
155
|
+
content-length:
|
156
|
+
- "20"
|
157
|
+
body: recorded response
|
158
|
+
http_version: "1.1"
|
159
|
+
"""
|
160
|
+
And a file named "before_playback_ignore.rb" with:
|
161
|
+
"""
|
162
|
+
require 'vcr_cucumber_helpers'
|
163
|
+
|
164
|
+
start_sinatra_app(:port => 7777) do
|
165
|
+
get('/') { "sinatra response" }
|
166
|
+
end
|
167
|
+
|
168
|
+
require 'vcr'
|
169
|
+
|
170
|
+
VCR.config do |c|
|
171
|
+
c.stub_with :fakeweb
|
172
|
+
c.cassette_library_dir = 'cassettes'
|
173
|
+
c.before_playback { |i| i.ignore! }
|
174
|
+
end
|
175
|
+
|
176
|
+
VCR.use_cassette('localhost', :record => :new_episodes) do
|
177
|
+
response = Net::HTTP.get_response('localhost', '/', 7777)
|
178
|
+
puts "Response: #{response.body}"
|
179
|
+
end
|
180
|
+
"""
|
181
|
+
When I run "ruby before_playback_ignore.rb"
|
182
|
+
Then it should pass with "Response: sinatra response"
|
183
|
+
|
184
|
+
Scenario: Multiple hooks are run in order
|
185
|
+
Given a file named "multiple_hooks.rb" with:
|
186
|
+
"""
|
187
|
+
require 'vcr_cucumber_helpers'
|
188
|
+
|
189
|
+
start_sinatra_app(:port => 7777) do
|
190
|
+
get('/') { "Hello World" }
|
191
|
+
end
|
192
|
+
|
193
|
+
require 'vcr'
|
194
|
+
|
195
|
+
VCR.config do |c|
|
196
|
+
c.stub_with :fakeweb
|
197
|
+
c.cassette_library_dir = 'cassettes'
|
198
|
+
|
199
|
+
c.before_record { puts "In before_record hook 1" }
|
200
|
+
c.before_record { puts "In before_record hook 2" }
|
201
|
+
|
202
|
+
c.before_playback { puts "In before_playback hook 1" }
|
203
|
+
c.before_playback { puts "In before_playback hook 2" }
|
204
|
+
end
|
205
|
+
|
206
|
+
VCR.use_cassette('example', :record => :new_episodes) do
|
207
|
+
response = Net::HTTP.get_response('localhost', '/', 7777)
|
208
|
+
puts "Response 1: #{response.body}"
|
209
|
+
|
210
|
+
response = Net::HTTP.get_response('example.com', '/foo')
|
211
|
+
puts "Response 2: #{response.body}"
|
212
|
+
end
|
213
|
+
"""
|
214
|
+
When I run "ruby multiple_hooks.rb"
|
215
|
+
Then it should pass with:
|
216
|
+
"""
|
217
|
+
In before_playback hook 1
|
218
|
+
In before_playback hook 2
|
219
|
+
Response 1: Hello World
|
220
|
+
Response 2: example.com response
|
221
|
+
In before_record hook 1
|
222
|
+
In before_record hook 2
|
223
|
+
"""
|
224
|
+
|
225
|
+
Scenario: Use tagging to apply hooks to only certain cassettes
|
226
|
+
Given a file named "tagged_hooks.rb" with:
|
227
|
+
"""
|
228
|
+
require 'vcr_cucumber_helpers'
|
229
|
+
|
230
|
+
start_sinatra_app(:port => 7777) do
|
231
|
+
get('/') { "Hello World" }
|
232
|
+
end
|
233
|
+
|
234
|
+
require 'vcr'
|
235
|
+
|
236
|
+
VCR.config do |c|
|
237
|
+
c.stub_with :fakeweb
|
238
|
+
c.cassette_library_dir = 'cassettes'
|
239
|
+
|
240
|
+
c.before_record(:tag_1) { |i| puts "In before_record hook for tag_1 (#{i.response.body})" }
|
241
|
+
c.before_playback(:tag_2) { |i| puts "In before_playback hook for tag_2 (#{i.response.body})" }
|
242
|
+
end
|
243
|
+
|
244
|
+
[:tag_1, :tag_2, nil].each do |tag|
|
245
|
+
puts
|
246
|
+
puts "Using tag: #{tag.inspect}"
|
247
|
+
|
248
|
+
VCR.use_cassette('example', :record => :new_episodes, :tag => tag) do
|
249
|
+
response = Net::HTTP.get_response('localhost', '/', 7777)
|
250
|
+
puts "Response 1: #{response.body}"
|
251
|
+
|
252
|
+
response = Net::HTTP.get_response('example.com', '/foo')
|
253
|
+
puts "Response 2: #{response.body}"
|
254
|
+
end
|
255
|
+
end
|
256
|
+
"""
|
257
|
+
When I run "ruby tagged_hooks.rb"
|
258
|
+
Then it should pass with:
|
259
|
+
"""
|
260
|
+
Using tag: :tag_1
|
261
|
+
Response 1: Hello World
|
262
|
+
Response 2: example.com response
|
263
|
+
In before_record hook for tag_1 (example.com response)
|
264
|
+
In before_record hook for tag_1 (Hello World)
|
265
|
+
|
266
|
+
Using tag: :tag_2
|
267
|
+
In before_playback hook for tag_2 (example.com response)
|
268
|
+
In before_playback hook for tag_2 (Hello World)
|
269
|
+
Response 1: Hello World
|
270
|
+
Response 2: example.com response
|
271
|
+
|
272
|
+
Using tag: nil
|
273
|
+
Response 1: Hello World
|
274
|
+
Response 2: example.com response
|
275
|
+
"""
|
276
|
+
|