vcr 1.3.1 → 1.3.2
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 +14 -2
- data/Gemfile +3 -0
- data/Gemfile.lock +20 -2
- data/README.md +6 -1
- data/Rakefile +6 -44
- data/benchmarks/http_stubbing_libraries.rb +4 -4
- data/cucumber.yml +14 -0
- data/features/README.md +21 -0
- data/features/cassettes/automatic_re_recording.feature +68 -0
- data/features/cassettes/dynamic_erb.feature +90 -0
- data/features/cassettes/format.feature +81 -0
- data/features/cassettes/no_cassette.feature +38 -0
- data/features/cassettes/record_modes/all.feature +78 -0
- data/features/cassettes/record_modes/new_episodes.feature +71 -0
- data/features/cassettes/record_modes/none.feature +65 -0
- data/features/cassettes/request_matching.feature +379 -0
- data/features/configuration/cassette_library_dir.feature +28 -0
- data/features/configuration/default_cassette_options.feature +80 -0
- data/features/configuration/ignore_localhost.feature +103 -0
- data/features/configuration/stub_with.feature +164 -0
- data/features/http_libraries/net_http.feature +137 -0
- data/features/step_definitions/cli_steps.rb +82 -0
- data/features/support/aruba_workaround/aruba_patches.rb +36 -0
- data/features/support/aruba_workaround/background_process.rb +4 -0
- data/features/support/env.rb +16 -102
- data/features/support/http_lib_filters.rb +37 -0
- data/features/support/vcr_cucumber_helpers.rb +34 -0
- data/features/test_frameworks/cucumber.feature +109 -0
- data/features/test_frameworks/rspec.feature +110 -0
- data/features/test_frameworks/shoulda.feature +64 -0
- data/features/test_frameworks/test_unit.feature +46 -0
- data/lib/vcr/cassette.rb +1 -1
- data/lib/vcr/structs.rb +64 -13
- data/lib/vcr/version.rb +1 -1
- data/{FullBuildRakeFile → script/FullBuildRakeFile} +0 -0
- data/script/full_build +1 -0
- data/spec/extensions/net_http_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/structs_spec.rb +47 -16
- data/spec/support/vcr_localhost_server.rb +11 -5
- data/vcr.gemspec +2 -1
- metadata +82 -77
- data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/regex_cassette.yml +0 -43
- data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette1.yml +0 -43
- data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette2.yml +0 -63
- data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette3.yml +0 -85
- data/features/fixtures/vcr_cassettes/1.9.1/erb_cassette.yml +0 -36
- data/features/fixtures/vcr_cassettes/1.9.1/match_requests_on.yml +0 -35
- data/features/fixtures/vcr_cassettes/1.9.1/nested_replay_cassette.yml +0 -32
- data/features/fixtures/vcr_cassettes/1.9.1/not_the_real_response.yml +0 -43
- data/features/fixtures/vcr_cassettes/1.9.1/record_all.yml +0 -62
- data/features/fixtures/vcr_cassettes/1.9.1/replay_localhost_cassette.yml +0 -32
- data/features/fixtures/vcr_cassettes/not_1.9.1/cucumber_tags/regex_cassette.yml +0 -43
- data/features/fixtures/vcr_cassettes/not_1.9.1/cucumber_tags/replay_cassette1.yml +0 -43
- data/features/fixtures/vcr_cassettes/not_1.9.1/cucumber_tags/replay_cassette2.yml +0 -47
- data/features/fixtures/vcr_cassettes/not_1.9.1/cucumber_tags/replay_cassette3.yml +0 -85
- data/features/fixtures/vcr_cassettes/not_1.9.1/erb_cassette.yml +0 -36
- data/features/fixtures/vcr_cassettes/not_1.9.1/match_requests_on.yml +0 -35
- data/features/fixtures/vcr_cassettes/not_1.9.1/nested_replay_cassette.yml +0 -24
- data/features/fixtures/vcr_cassettes/not_1.9.1/not_the_real_response.yml +0 -43
- data/features/fixtures/vcr_cassettes/not_1.9.1/record_all.yml +0 -61
- data/features/fixtures/vcr_cassettes/not_1.9.1/replay_localhost_cassette.yml +0 -32
- data/features/http_client.feature +0 -16
- data/features/net_http.feature +0 -38
- data/features/record_response.feature +0 -95
- data/features/replay_recorded_response.feature +0 -96
- data/features/rspec.feature +0 -100
- data/features/step_definitions/http_client_steps.rb +0 -7
- data/features/step_definitions/net_http_steps.rb +0 -49
- data/features/step_definitions/vcr_steps.rb +0 -252
- data/features/webmock.feature +0 -26
- data/full_build +0 -1
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,26 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.3.2 (November 16, 2010)
|
4
|
+
|
5
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.3.1...v1.3.2)
|
6
|
+
|
7
|
+
* Fix serialized structs so that they are normalized andthey will be the same
|
8
|
+
regardless of which HTTP library made the request.
|
9
|
+
* Status "OK " => "OK"
|
10
|
+
* Body '' => nil
|
11
|
+
* Headers {} => nil
|
12
|
+
* Remove extraneous headers added by the HTTP lib (i.e. Typhoeus user agent)
|
13
|
+
* Rewrite cucumber features in a more documentation-oriented style.
|
14
|
+
|
3
15
|
## 1.3.1 (November 11, 2010)
|
4
16
|
|
5
|
-
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.3.0...
|
17
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.3.0...v1.3.1)
|
6
18
|
|
7
19
|
* Update WebMock adapter to work with (and require) newly released WebMock 1.6.0.
|
8
20
|
|
9
21
|
## 1.3.0 (November 11, 2010)
|
10
22
|
|
11
|
-
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.2.0...
|
23
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.2.0...v1.3.0)
|
12
24
|
|
13
25
|
* Moved documentation from README to [Wiki](http://github.com/myronmarston/vcr/wiki).
|
14
26
|
* Refactoring and code cleanup.
|
data/Gemfile
CHANGED
@@ -13,11 +13,14 @@ group :development do
|
|
13
13
|
platforms :jruby do
|
14
14
|
gem 'jruby-openssl'
|
15
15
|
end
|
16
|
+
|
17
|
+
gem 'shoulda'
|
16
18
|
end
|
17
19
|
|
18
20
|
# Additional gems that are useful, but not required for development.
|
19
21
|
group :extras do
|
20
22
|
gem 'guard-rspec'
|
23
|
+
gem 'relish'
|
21
24
|
|
22
25
|
platforms :mri do
|
23
26
|
gem 'rcov'
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vcr (1.3.
|
4
|
+
vcr (1.3.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
9
|
addressable (2.2.2)
|
10
10
|
archive-tar-minitar (0.5.2)
|
11
|
-
aruba (0.2.
|
11
|
+
aruba (0.2.4)
|
12
|
+
background_process
|
13
|
+
cucumber (~> 0.9.3)
|
14
|
+
background_process (1.2)
|
12
15
|
bouncy-castle-java (1.5.0145.2)
|
13
16
|
builder (2.1.2)
|
14
17
|
columnize (0.3.1)
|
@@ -49,6 +52,7 @@ GEM
|
|
49
52
|
linecache (0.43)
|
50
53
|
linecache19 (0.5.11)
|
51
54
|
ruby_core_source (>= 0.1.4)
|
55
|
+
mime-types (1.16)
|
52
56
|
open_gem (1.4.2)
|
53
57
|
launchy (~> 0.3.5)
|
54
58
|
patron (0.4.9)
|
@@ -56,6 +60,12 @@ GEM
|
|
56
60
|
rake (0.8.7)
|
57
61
|
rb-fsevent (0.3.6)
|
58
62
|
rcov (0.9.9)
|
63
|
+
relish (0.1.1)
|
64
|
+
archive-tar-minitar (~> 0.5.2)
|
65
|
+
json (~> 1.4.6)
|
66
|
+
rest-client (~> 1.6.1)
|
67
|
+
rest-client (1.6.1)
|
68
|
+
mime-types (>= 1.16)
|
59
69
|
rspec (2.1.0)
|
60
70
|
rspec-core (~> 2.1.0)
|
61
71
|
rspec-expectations (~> 2.1.0)
|
@@ -79,8 +89,13 @@ GEM
|
|
79
89
|
ruby-debug-base19 (>= 0.11.19)
|
80
90
|
ruby_core_source (0.1.4)
|
81
91
|
archive-tar-minitar (>= 0.5.2)
|
92
|
+
shoulda (2.9.2)
|
93
|
+
sinatra (1.1.0)
|
94
|
+
rack (~> 1.1)
|
95
|
+
tilt (~> 1.1)
|
82
96
|
term-ansicolor (1.0.5)
|
83
97
|
thor (0.14.4)
|
98
|
+
tilt (1.1)
|
84
99
|
timecop (0.3.5)
|
85
100
|
typhoeus (0.2.0)
|
86
101
|
webmock (1.6.0)
|
@@ -106,10 +121,13 @@ DEPENDENCIES
|
|
106
121
|
rake (~> 0.8.7)
|
107
122
|
rb-fsevent
|
108
123
|
rcov
|
124
|
+
relish
|
109
125
|
rspec (~> 2.1.0)
|
110
126
|
ruby-debug
|
111
127
|
ruby-debug-base19 (= 0.11.23)
|
112
128
|
ruby-debug19
|
129
|
+
shoulda
|
130
|
+
sinatra (~> 1.1.0)
|
113
131
|
timecop (~> 0.3.5)
|
114
132
|
typhoeus (~> 0.2.0)
|
115
133
|
vcr!
|
data/README.md
CHANGED
@@ -53,7 +53,12 @@ maintenance) and accurate (the response from example.com will contain the same h
|
|
53
53
|
|
54
54
|
## Usage
|
55
55
|
|
56
|
-
|
56
|
+
Browse the [cucumber features](http://relishapp.com/myronmarston/vcr) or visit
|
57
|
+
the [wiki](http://github.com/myronmarston/vcr/wiki) for usage info and
|
58
|
+
documentation.
|
59
|
+
|
60
|
+
The [VCR talk given at Philly.rb](http://philly-rb-vcr-talk.heroku.com/) also
|
61
|
+
contains good usage info.
|
57
62
|
|
58
63
|
## Development
|
59
64
|
|
data/Rakefile
CHANGED
@@ -4,9 +4,6 @@ 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'
|
10
7
|
|
11
8
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
12
9
|
#t.rspec_opts = %w[--format documentation]
|
@@ -22,50 +19,15 @@ task :cleanup_rcov_files do
|
|
22
19
|
rm_rf 'coverage.data'
|
23
20
|
end
|
24
21
|
|
25
|
-
permutations = {
|
26
|
-
'fakeweb' => %w( net/http typhoeus ),
|
27
|
-
'typhoeus' => %w( typhoeus ),
|
28
|
-
'webmock' => %w( net/http typhoeus httpclient patron em-http-request curb )
|
29
|
-
}
|
30
|
-
|
31
|
-
permutations.delete('typhoeus') if RUBY_INTERPRETER == :jruby
|
32
|
-
|
33
22
|
require 'cucumber/rake/task'
|
34
|
-
|
35
|
-
permutations.each do |http_stubbing_adapter, http_libraries|
|
36
|
-
features_subtasks = []
|
37
|
-
|
38
|
-
namespace http_stubbing_adapter do
|
39
|
-
http_libraries.each do |http_lib|
|
40
|
-
next if RUBY_INTERPRETER != :mri && %w( patron em-http-request curb ).include?(http_lib)
|
41
|
-
next if RUBY_INTERPRETER == :jruby && http_lib == 'typhoeus'
|
23
|
+
Cucumber::Rake::Task.new
|
42
24
|
|
43
|
-
|
44
|
-
features_subtasks << "features:#{http_stubbing_adapter}:#{sanitized_http_lib}"
|
25
|
+
task :default => [:spec, :cucumber]
|
45
26
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
Cucumber::Rake::Task.new(
|
52
|
-
{ sanitized_http_lib => "#{features_subtasks.last}_prep" },
|
53
|
-
"Run the features using #{http_stubbing_adapter} and #{http_lib}") do |t|
|
54
|
-
t.cucumber_opts = ['--format', 'progress', '--tags', "@#{http_stubbing_adapter},@all_http_libs,@#{sanitized_http_lib}"]
|
55
|
-
|
56
|
-
# disable scenarios on heroku that can't pass due to heroku's restrictions
|
57
|
-
t.cucumber_opts += ['--tags', '~@spawns_localhost_server'] if ENV.keys.include?('HEROKU_SLUG')
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
desc "Run the features using #{http_stubbing_adapter} and each of #{http_stubbing_adapter}'s supported http libraries"
|
63
|
-
task http_stubbing_adapter => features_subtasks
|
64
|
-
end
|
27
|
+
desc "Push cukes to relishapp using the relish-client-gem"
|
28
|
+
task :relish do
|
29
|
+
sh "relish push vcr"
|
65
30
|
end
|
66
31
|
|
67
|
-
|
68
|
-
task :features => permutations.keys.map { |a| "features:#{a}" }
|
69
|
-
|
70
|
-
task :default => [:spec, :features]
|
32
|
+
task :release => :relish
|
71
33
|
|
@@ -50,10 +50,10 @@ end
|
|
50
50
|
# Output on my machine:
|
51
51
|
#
|
52
52
|
# Benchmarking Single setup/teardown:
|
53
|
-
# webmock 0.000000 0.000000
|
54
|
-
# fakeweb 0.000000 0.000000 1.
|
53
|
+
# webmock 0.000000 0.000000 8.500000 ( 8.559143)
|
54
|
+
# fakeweb 0.000000 0.000000 1.900000 ( 1.967160)
|
55
55
|
#
|
56
56
|
#
|
57
57
|
# Benchmarking Setup/teardown for each http request:
|
58
|
-
# webmock 0.000000 0.000000
|
59
|
-
# fakeweb 0.000000 0.000000 2.
|
58
|
+
# webmock 0.000000 0.000000 9.710000 ( 9.764760)
|
59
|
+
# fakeweb 0.000000 0.000000 2.470000 ( 2.479292)
|
data/cucumber.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
<%
|
2
|
+
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
|
3
|
+
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
|
4
|
+
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
|
5
|
+
interp_opts = if RUBY_PLATFORM == 'java'
|
6
|
+
' --tags ~@exclude-jruby'
|
7
|
+
else
|
8
|
+
''
|
9
|
+
end
|
10
|
+
%>
|
11
|
+
default: <%= std_opts %><%= interp_opts %> features
|
12
|
+
wip: --tags @wip:30 --wip features
|
13
|
+
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip<%= interp_opts %>
|
14
|
+
|
data/features/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
## VCR
|
2
|
+
|
3
|
+
The cucumber features provided here demonstrate all of the major features of
|
4
|
+
VCR. These features are executable documentation for VCR.
|
5
|
+
|
6
|
+
Many of the examples use one (or both) of these helper functions
|
7
|
+
provided by `vcr_cucumber_helpers.rb`:
|
8
|
+
|
9
|
+
* `start_sinatra_app`: starts a sinatra application on the given port.
|
10
|
+
The server automatically shuts down when the ruby script ends. Many
|
11
|
+
examples re-run the script without the sinatra server to demonstrate
|
12
|
+
the replaying of a recorded HTTP response.
|
13
|
+
* `include_http_adapter_for`: includes a module that implements a common
|
14
|
+
HTTP interface for the given HTTP library. The `response_body_for`
|
15
|
+
method will make an HTTP request using the given this library. This
|
16
|
+
allows scenarios to be run against each different supported HTTP
|
17
|
+
library.
|
18
|
+
|
19
|
+
If you have ideas to clarify or improve any of these cucumber features,
|
20
|
+
please submit an [issue](https://github.com/myronmarston/vcr/issues) or
|
21
|
+
pull request.
|
@@ -0,0 +1,68 @@
|
|
1
|
+
Feature: Automatic Re-recording
|
2
|
+
|
3
|
+
Over time, your cassettes may get out-of-date. APIs change and sites you
|
4
|
+
scrape get updated. VCR provides a facility to automatically re-record your
|
5
|
+
cassettes. Enable re-recording using the :re_record_interval option.
|
6
|
+
|
7
|
+
The value provided should be an interval (expressed in seconds) that
|
8
|
+
determines how often VCR will re-record the cassette. When a cassette
|
9
|
+
is used, VCR checks the file modification time; if more time than the
|
10
|
+
interval has passed, VCR will use the :all record mode to cause it be
|
11
|
+
re-recorded.
|
12
|
+
|
13
|
+
Background:
|
14
|
+
Given a previously recorded cassette file "cassettes/example.yml" with:
|
15
|
+
"""
|
16
|
+
---
|
17
|
+
- !ruby/struct:VCR::HTTPInteraction
|
18
|
+
request: !ruby/struct:VCR::Request
|
19
|
+
method: :get
|
20
|
+
uri: http://localhost:7777/
|
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
|
+
content-length:
|
29
|
+
- "12"
|
30
|
+
body: Old Response
|
31
|
+
http_version: "1.1"
|
32
|
+
"""
|
33
|
+
And a file named "re_record.rb" with:
|
34
|
+
"""
|
35
|
+
require 'vcr_cucumber_helpers'
|
36
|
+
|
37
|
+
start_sinatra_app(:port => 7777) do
|
38
|
+
get('/') { 'New Response' }
|
39
|
+
end
|
40
|
+
|
41
|
+
require 'vcr'
|
42
|
+
|
43
|
+
VCR.config do |c|
|
44
|
+
c.stub_with :fakeweb
|
45
|
+
c.cassette_library_dir = 'cassettes'
|
46
|
+
end
|
47
|
+
|
48
|
+
VCR.use_cassette('example', :record => :new_episodes, :re_record_interval => 7.days) do
|
49
|
+
puts Net::HTTP.get_response('localhost', '/', 7777).body
|
50
|
+
end
|
51
|
+
"""
|
52
|
+
|
53
|
+
Scenario: Cassette is not re-recorded when not enough time has passed
|
54
|
+
Given 6 days have passed since the cassette was recorded
|
55
|
+
When I run "ruby re_record.rb"
|
56
|
+
Then the output should contain "Old Response"
|
57
|
+
But the output should not contain "New Response"
|
58
|
+
And the file "cassettes/example.yml" should contain "body: Old Response"
|
59
|
+
But the file "cassettes/example.yml" should not contain "body: New Response"
|
60
|
+
|
61
|
+
Scenario: Cassette is re-recorded when enough time has passed
|
62
|
+
Given 8 days have passed since the cassette was recorded
|
63
|
+
When I run "ruby re_record.rb"
|
64
|
+
Then the output should contain "New Response"
|
65
|
+
But the output should not contain "Old Response"
|
66
|
+
And the file "cassettes/example.yml" should contain "body: New Response"
|
67
|
+
But the file "cassettes/example.yml" should not contain "body: Old Response"
|
68
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
Feature: Dynamic ERB cassettes
|
2
|
+
|
3
|
+
By default, cassettes are static: the exact response that was received
|
4
|
+
when the cassette was recorded will be replayed for all future requests.
|
5
|
+
Usually, this is fine, but in some cases you need something more dynamic.
|
6
|
+
You can use ERB for this.
|
7
|
+
|
8
|
+
To enable ERB evaluation of a cassette, pass the `:erb => true` option
|
9
|
+
to a cassette. If you want to pass variables to the cassette, you can
|
10
|
+
pass the names and values of the variables in a hash (`:erb => { ... }`).
|
11
|
+
|
12
|
+
Scenario: Enable dynamic ERB cassette evalutation using :erb => true
|
13
|
+
Given a previously recorded cassette file "cassettes/dynamic.yml" with:
|
14
|
+
"""
|
15
|
+
---
|
16
|
+
- !ruby/struct:VCR::HTTPInteraction
|
17
|
+
request: !ruby/struct:VCR::Request
|
18
|
+
method: :get
|
19
|
+
uri: http://example.com:80/foo?a=<%= 'b' * 3 %>
|
20
|
+
body:
|
21
|
+
headers:
|
22
|
+
response: !ruby/struct:VCR::Response
|
23
|
+
status: !ruby/struct:VCR::ResponseStatus
|
24
|
+
code: 200
|
25
|
+
message: OK
|
26
|
+
headers:
|
27
|
+
content-type:
|
28
|
+
- text/html;charset=utf-8
|
29
|
+
content-length:
|
30
|
+
- "9"
|
31
|
+
body: Hello <%= 'bar'.next %>
|
32
|
+
http_version: "1.1"
|
33
|
+
"""
|
34
|
+
And a file named "dynamic_erb_example.rb" with:
|
35
|
+
"""
|
36
|
+
require 'vcr'
|
37
|
+
|
38
|
+
VCR.config do |c|
|
39
|
+
c.stub_with :fakeweb
|
40
|
+
c.cassette_library_dir = 'cassettes'
|
41
|
+
c.default_cassette_options = { :record => :none }
|
42
|
+
end
|
43
|
+
|
44
|
+
VCR.use_cassette('dynamic', :erb => true) do
|
45
|
+
response = Net::HTTP.get_response('example.com', '/foo?a=bbb')
|
46
|
+
puts "Response: #{response.body}"
|
47
|
+
end
|
48
|
+
"""
|
49
|
+
When I run "ruby dynamic_erb_example.rb"
|
50
|
+
Then it should pass with "Response: Hello bas"
|
51
|
+
|
52
|
+
Scenario: Pass arguments to the ERB using :erb => { ... }
|
53
|
+
Given a previously recorded cassette file "cassettes/dynamic.yml" with:
|
54
|
+
"""
|
55
|
+
---
|
56
|
+
- !ruby/struct:VCR::HTTPInteraction
|
57
|
+
request: !ruby/struct:VCR::Request
|
58
|
+
method: :get
|
59
|
+
uri: http://example.com:80/foo?a=<%= arg1 %>
|
60
|
+
body:
|
61
|
+
headers:
|
62
|
+
response: !ruby/struct:VCR::Response
|
63
|
+
status: !ruby/struct:VCR::ResponseStatus
|
64
|
+
code: 200
|
65
|
+
message: OK
|
66
|
+
headers:
|
67
|
+
content-type:
|
68
|
+
- text/html;charset=utf-8
|
69
|
+
content-length:
|
70
|
+
- "9"
|
71
|
+
body: Hello <%= arg2 %>
|
72
|
+
http_version: "1.1"
|
73
|
+
"""
|
74
|
+
And a file named "dynamic_erb_example.rb" with:
|
75
|
+
"""
|
76
|
+
require 'vcr'
|
77
|
+
|
78
|
+
VCR.config do |c|
|
79
|
+
c.stub_with :fakeweb
|
80
|
+
c.cassette_library_dir = 'cassettes'
|
81
|
+
c.default_cassette_options = { :record => :none }
|
82
|
+
end
|
83
|
+
|
84
|
+
VCR.use_cassette('dynamic', :erb => { :arg1 => 7, :arg2 => 'baz' }) do
|
85
|
+
response = Net::HTTP.get_response('example.com', '/foo?a=7')
|
86
|
+
puts "Response: #{response.body}"
|
87
|
+
end
|
88
|
+
"""
|
89
|
+
When I run "ruby dynamic_erb_example.rb"
|
90
|
+
Then it should pass with "Response: Hello baz"
|
@@ -0,0 +1,81 @@
|
|
1
|
+
Feature: Cassette format
|
2
|
+
|
3
|
+
VCR Cassettes are YAML files that contain all of the information
|
4
|
+
about the requests and corresponding responses in a
|
5
|
+
human-readable/editable format. A cassette contains an array
|
6
|
+
of HTTP interactions, each of which has the following:
|
7
|
+
|
8
|
+
* Request method, uri, body, headers
|
9
|
+
* Response status (code & message), headers, body, http version
|
10
|
+
|
11
|
+
Scenario Outline: Request/Response data is saved to disk as YAML
|
12
|
+
Given a file named "cassette_format.rb" with:
|
13
|
+
"""
|
14
|
+
require 'vcr_cucumber_helpers'
|
15
|
+
include_http_adapter_for("<http_lib>")
|
16
|
+
|
17
|
+
start_sinatra_app(:port => 7777) do
|
18
|
+
get('/:path') { ARGV[0] + ' ' + params[:path] }
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'vcr'
|
22
|
+
|
23
|
+
VCR.config do |c|
|
24
|
+
c.stub_with <stub_with>
|
25
|
+
c.cassette_library_dir = 'cassettes'
|
26
|
+
end
|
27
|
+
|
28
|
+
VCR.use_cassette('example', :record => :new_episodes) do
|
29
|
+
make_http_request(:get, "http://localhost:7777/foo")
|
30
|
+
make_http_request(:get, "http://localhost:7777/bar")
|
31
|
+
end
|
32
|
+
"""
|
33
|
+
When I run "ruby cassette_format.rb 'Hello'"
|
34
|
+
Then the file "cassettes/example.yml" should contain YAML like:
|
35
|
+
"""
|
36
|
+
---
|
37
|
+
- !ruby/struct:VCR::HTTPInteraction
|
38
|
+
request: !ruby/struct:VCR::Request
|
39
|
+
method: :get
|
40
|
+
uri: http://localhost:7777/foo
|
41
|
+
body:
|
42
|
+
headers:
|
43
|
+
response: !ruby/struct:VCR::Response
|
44
|
+
status: !ruby/struct:VCR::ResponseStatus
|
45
|
+
code: 200
|
46
|
+
message: OK
|
47
|
+
headers:
|
48
|
+
content-type:
|
49
|
+
- text/html;charset=utf-8
|
50
|
+
content-length:
|
51
|
+
- "9"
|
52
|
+
body: Hello foo
|
53
|
+
http_version: "1.1"
|
54
|
+
- !ruby/struct:VCR::HTTPInteraction
|
55
|
+
request: !ruby/struct:VCR::Request
|
56
|
+
method: :get
|
57
|
+
uri: http://localhost:7777/bar
|
58
|
+
body:
|
59
|
+
headers:
|
60
|
+
response: !ruby/struct:VCR::Response
|
61
|
+
status: !ruby/struct:VCR::ResponseStatus
|
62
|
+
code: 200
|
63
|
+
message: OK
|
64
|
+
headers:
|
65
|
+
content-type:
|
66
|
+
- text/html;charset=utf-8
|
67
|
+
content-length:
|
68
|
+
- "9"
|
69
|
+
body: Hello bar
|
70
|
+
http_version: "1.1"
|
71
|
+
"""
|
72
|
+
|
73
|
+
Examples:
|
74
|
+
| stub_with | http_lib |
|
75
|
+
| :fakeweb | net/http |
|
76
|
+
| :webmock | net/http |
|
77
|
+
| :webmock | httpclient |
|
78
|
+
| :webmock | patron |
|
79
|
+
| :webmock | curb |
|
80
|
+
| :webmock | em-http-request |
|
81
|
+
| :typhoeus | typhoeus |
|