vcr 1.11.3 → 2.0.0.beta1
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 +2 -0
- data/.travis.yml +6 -2
- data/CHANGELOG.md +49 -1
- data/Gemfile +1 -5
- data/Guardfile +0 -5
- data/README.md +3 -2
- data/Rakefile +11 -16
- data/cucumber.yml +0 -4
- data/features/.nav +14 -2
- data/features/cassettes/automatic_re_recording.feature +4 -6
- data/features/cassettes/dynamic_erb.feature +6 -8
- data/features/cassettes/exclusive.feature +111 -0
- data/features/cassettes/format.feature +16 -14
- data/features/cassettes/naming.feature +4 -6
- data/features/cassettes/no_cassette.feature +25 -28
- data/features/cassettes/update_content_length_header.feature +9 -9
- data/features/configuration/allow_http_connections_when_no_cassette.feature +6 -8
- data/features/configuration/cassette_library_dir.feature +4 -6
- data/features/configuration/default_cassette_options.feature +12 -10
- data/features/configuration/filter_sensitive_data.feature +12 -17
- data/features/configuration/{stub_with.feature → hook_into.feature} +63 -62
- data/features/configuration/hooks.feature +23 -33
- data/features/configuration/ignore_hosts.feature +16 -17
- data/features/configuration/ignore_localhost.feature +33 -42
- data/features/http_libraries/em_http_request.feature +7 -8
- data/features/http_libraries/net_http.feature +26 -28
- data/features/middleware/faraday.feature +17 -56
- data/features/middleware/rack.feature +8 -11
- data/features/record_modes/all.feature +5 -7
- data/features/record_modes/new_episodes.feature +5 -7
- data/features/record_modes/none.feature +6 -6
- data/features/record_modes/once.feature +6 -8
- data/features/request_matching/README.md +28 -0
- data/features/request_matching/body.feature +81 -0
- data/features/request_matching/custom_matcher.feature +125 -0
- data/features/request_matching/headers.feature +85 -0
- data/features/request_matching/host.feature +85 -0
- data/features/request_matching/identical_request_sequence.feature +79 -0
- data/features/request_matching/method.feature +86 -0
- data/features/request_matching/path.feature +86 -0
- data/features/request_matching/playback_repeats.feature +87 -0
- data/features/request_matching/uri.feature +84 -0
- data/features/request_matching/uri_without_param.feature +85 -0
- data/features/step_definitions/cli_steps.rb +4 -28
- data/features/support/env.rb +11 -9
- data/features/support/http_lib_filters.rb +2 -11
- data/features/support/vcr_cucumber_helpers.rb +4 -5
- data/features/test_frameworks/cucumber.feature +17 -18
- data/features/test_frameworks/rspec.feature +8 -12
- data/features/test_frameworks/shoulda.feature +5 -8
- data/features/test_frameworks/test_unit.feature +5 -8
- data/lib/vcr.rb +38 -58
- data/lib/vcr/cassette.rb +41 -60
- data/lib/vcr/cassette/http_interaction_list.rb +56 -0
- data/lib/vcr/cassette/reader.rb +29 -31
- data/lib/vcr/configuration.rb +76 -0
- data/lib/vcr/deprecations.rb +39 -0
- data/lib/vcr/errors.rb +22 -0
- data/lib/vcr/library_hooks.rb +19 -0
- data/lib/vcr/library_hooks/excon.rb +136 -0
- data/lib/vcr/library_hooks/fakeweb.rb +110 -0
- data/lib/vcr/library_hooks/faraday.rb +3 -0
- data/lib/vcr/library_hooks/typhoeus.rb +98 -0
- data/lib/vcr/library_hooks/webmock.rb +100 -0
- data/lib/vcr/middleware/faraday.rb +43 -36
- data/lib/vcr/middleware/rack.rb +28 -4
- data/lib/vcr/request_handler.rb +43 -0
- data/lib/vcr/request_ignorer.rb +31 -0
- data/lib/vcr/request_matcher_registry.rb +86 -0
- data/lib/vcr/structs/http_interaction.rb +24 -18
- data/lib/vcr/structs/normalizers/body.rb +1 -1
- data/lib/vcr/structs/normalizers/header.rb +1 -1
- data/lib/vcr/structs/normalizers/status_message.rb +1 -1
- data/lib/vcr/structs/normalizers/uri.rb +1 -1
- data/lib/vcr/structs/request.rb +0 -13
- data/lib/vcr/structs/response.rb +2 -9
- data/lib/vcr/structs/response_status.rb +0 -4
- data/lib/vcr/test_frameworks/cucumber.rb +1 -1
- data/lib/vcr/test_frameworks/rspec.rb +1 -1
- data/lib/vcr/util/hooks.rb +28 -19
- data/lib/vcr/util/internet_connection.rb +29 -2
- data/lib/vcr/util/version_checker.rb +60 -0
- data/lib/vcr/version.rb +1 -1
- data/script/FullBuildRakeFile +0 -7
- data/script/full_build +1 -1
- data/spec/capture_warnings.rb +36 -31
- data/spec/fixtures/{1.9.1/cassette_spec → cassette_spec}/empty.yml +0 -0
- data/spec/fixtures/{not_1.9.1/cassette_spec → cassette_spec}/example.yml +0 -0
- data/spec/fixtures/{not_1.9.1/cassette_spec → cassette_spec}/with_localhost_requests.yml +0 -0
- data/spec/fixtures/{not_1.9.1/fake_example.com_responses.yml → fake_example.com_responses.yml} +0 -0
- data/spec/fixtures/{not_1.9.1/match_requests_on.yml → match_requests_on.yml} +0 -0
- data/spec/monkey_patches.rb +40 -11
- data/spec/spec_helper.rb +7 -43
- data/spec/support/http_library_adapters.rb +3 -13
- data/spec/support/shared_example_groups/{http_library.rb → hook_into_http_library.rb} +39 -111
- data/spec/support/shared_example_groups/version_checking.rb +9 -9
- data/spec/vcr/cassette/http_interaction_list_spec.rb +178 -0
- data/spec/vcr/cassette/reader_spec.rb +2 -2
- data/spec/vcr/cassette_spec.rb +121 -156
- data/spec/vcr/configuration_spec.rb +143 -0
- data/spec/vcr/deprecations_spec.rb +91 -0
- data/spec/vcr/{http_stubbing_adapters → library_hooks}/excon_spec.rb +6 -9
- data/spec/vcr/library_hooks/fakeweb_spec.rb +83 -0
- data/spec/vcr/{http_stubbing_adapters → library_hooks}/typhoeus_spec.rb +7 -11
- data/spec/vcr/library_hooks/webmock_spec.rb +17 -0
- data/spec/vcr/library_hooks_spec.rb +51 -0
- data/spec/vcr/middleware/faraday_spec.rb +17 -44
- data/spec/vcr/middleware/rack_spec.rb +94 -58
- data/spec/vcr/request_ignorer_spec.rb +54 -0
- data/spec/vcr/request_matcher_registry_spec.rb +223 -0
- data/spec/vcr/structs/request_spec.rb +0 -33
- data/spec/vcr/structs/response_spec.rb +0 -24
- data/spec/vcr/structs/response_status_spec.rb +0 -9
- data/spec/vcr/util/hooks_spec.rb +3 -5
- data/spec/vcr/version_spec.rb +1 -1
- data/spec/vcr_spec.rb +79 -91
- data/vcr.gemspec +1 -1
- metadata +83 -103
- data/features/cassettes/request_matching.feature +0 -383
- data/lib/vcr/config.rb +0 -84
- data/lib/vcr/deprecations/cassette.rb +0 -29
- data/lib/vcr/deprecations/config.rb +0 -18
- data/lib/vcr/deprecations/http_stubbing_adapters/common.rb +0 -9
- data/lib/vcr/deprecations/http_stubbing_adapters/fakeweb.rb +0 -11
- data/lib/vcr/extensions/net_http.rb +0 -32
- data/lib/vcr/http_stubbing_adapters/common.rb +0 -202
- data/lib/vcr/http_stubbing_adapters/excon.rb +0 -178
- data/lib/vcr/http_stubbing_adapters/fakeweb.rb +0 -107
- data/lib/vcr/http_stubbing_adapters/faraday.rb +0 -26
- data/lib/vcr/http_stubbing_adapters/multi_object_proxy.rb +0 -43
- data/lib/vcr/http_stubbing_adapters/typhoeus.rb +0 -115
- data/lib/vcr/http_stubbing_adapters/webmock.rb +0 -120
- data/lib/vcr/middleware/cassette_arguments.rb +0 -19
- data/lib/vcr/middleware/common.rb +0 -20
- data/lib/vcr/request_matcher.rb +0 -94
- data/lib/vcr/rspec.rb +0 -2
- data/lib/vcr/util/basic_object.rb +0 -43
- data/lib/vcr/util/ping.rb +0 -30
- data/lib/vcr/util/regexes.rb +0 -37
- data/spec/fixtures/1.9.1/0_3_1_cassette.yml +0 -29
- data/spec/fixtures/1.9.1/cassette_spec/example.yml +0 -110
- data/spec/fixtures/1.9.1/cassette_spec/with_localhost_requests.yml +0 -109
- data/spec/fixtures/1.9.1/example_net_http.yml +0 -14
- data/spec/fixtures/1.9.1/example_net_http_request.yml +0 -12
- data/spec/fixtures/1.9.1/example_net_http_response.yml +0 -25
- data/spec/fixtures/1.9.1/fake_example.com_responses.yml +0 -108
- data/spec/fixtures/1.9.1/match_requests_on.yml +0 -185
- data/spec/fixtures/not_1.9.1/0_3_1_cassette.yml +0 -29
- data/spec/fixtures/not_1.9.1/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/not_1.9.1/example_net_http.yml +0 -14
- data/spec/fixtures/not_1.9.1/example_net_http_request.yml +0 -12
- data/spec/fixtures/not_1.9.1/example_net_http_response.yml +0 -25
- data/spec/support/shared_example_groups/http_stubbing_adapter.rb +0 -133
- data/spec/support/shared_example_groups/ignore_localhost_deprecation.rb +0 -28
- data/spec/vcr/config_spec.rb +0 -181
- data/spec/vcr/deprecations/cassette_spec.rb +0 -57
- data/spec/vcr/deprecations/config_spec.rb +0 -30
- data/spec/vcr/deprecations/http_stubbing_adapters/common_spec.rb +0 -7
- data/spec/vcr/deprecations/http_stubbing_adapters/fakeweb_spec.rb +0 -16
- data/spec/vcr/extensions/net_http_spec.rb +0 -80
- data/spec/vcr/http_stubbing_adapters/fakeweb_spec.rb +0 -19
- data/spec/vcr/http_stubbing_adapters/faraday_spec.rb +0 -76
- data/spec/vcr/http_stubbing_adapters/multi_object_proxy_spec.rb +0 -101
- data/spec/vcr/http_stubbing_adapters/webmock_spec.rb +0 -17
- data/spec/vcr/middleware/cassette_arguments_spec.rb +0 -32
- data/spec/vcr/request_matcher_spec.rb +0 -230
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
env: CUCUMBER_FORMAT=progress
|
|
2
2
|
bundler_args: --without extras
|
|
3
|
-
script: "bundle exec rake ci:build"
|
|
3
|
+
script: "bundle exec rake ci:build --trace"
|
|
4
4
|
rvm:
|
|
5
|
-
- 1.8.6
|
|
6
5
|
- 1.8.7
|
|
7
6
|
- 1.9.2
|
|
8
7
|
- 1.9.3
|
|
9
8
|
- ree
|
|
10
9
|
- jruby
|
|
10
|
+
branches:
|
|
11
|
+
only:
|
|
12
|
+
- master
|
|
13
|
+
- 1-x-stable
|
|
14
|
+
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
## In git
|
|
2
2
|
|
|
3
|
-
[Full Changelog](http://github.com/myronmarston/vcr/compare/
|
|
3
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v2.0.0.beta1...master)
|
|
4
|
+
|
|
5
|
+
## 2.0.0 Beta 1 (October 8, 2011)
|
|
6
|
+
|
|
7
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.11.3...v2.0.0.beta1)
|
|
8
|
+
|
|
9
|
+
### Changes
|
|
10
|
+
|
|
11
|
+
* Previously, the last matching response in a cassette would
|
|
12
|
+
repeatedly playback if the same request kept being made. This is
|
|
13
|
+
no longer the case.
|
|
14
|
+
* The Faraday middleware has been rewritten.
|
|
15
|
+
* You no longer need to configure `stub_with :faraday` to use it.
|
|
16
|
+
* It has been updated to work in parallel mode.
|
|
17
|
+
* It no longer accepts a block and uses that to determine the
|
|
18
|
+
cassette. Instead, use `VCR.use_cassette` just like you would
|
|
19
|
+
with FakeWeb or WebMock.
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
* Allow any callable (an object that responds to #call, such as a
|
|
24
|
+
lambda) to be used as a request matcher. Thanks to [Avdi Grimm](https://github.com/avdi)
|
|
25
|
+
for the idea.
|
|
26
|
+
* Add ability to register custom request matchers.
|
|
27
|
+
* Add `VCR.request_matchers.uri_without_param(:some_param)` to generate
|
|
28
|
+
a request matcher that matches on URI but ignores the named parameter.
|
|
29
|
+
* New `:allow_playback_repeats` cassette option preserves the old
|
|
30
|
+
playback repeat behavior. Thanks to [Avdi Grimm](https://github.com/avdi)
|
|
31
|
+
for the idea.
|
|
32
|
+
* New `:exclusive` cassette option allows a cassette to be exclusively
|
|
33
|
+
used rather than keeping the existing one active as a fallback. Thanks
|
|
34
|
+
to [Avdi Grimm](https://github.com/avdi) for the idea.
|
|
35
|
+
|
|
36
|
+
### Removed
|
|
37
|
+
|
|
38
|
+
* Removed support for Ruby 1.8.6 and 1.9.1.
|
|
39
|
+
* Removed lots of old deprecated APIs.
|
|
40
|
+
* Removed support for manually changing the URI in a cassette to a regex.
|
|
41
|
+
|
|
42
|
+
### Deprecated
|
|
43
|
+
|
|
44
|
+
* Deprecated `VCR.config` in favor of `VCR.configure`.
|
|
45
|
+
* Deprecated `VCR::Config` singleton module in favor of
|
|
46
|
+
`VCR::Configuration` class. The current configuration instance
|
|
47
|
+
can be accessed via `VCR.configuration`.
|
|
48
|
+
* Deprecated `stub_with` in favor of `hook_into`. The stubbing
|
|
49
|
+
adapters have been completely rewritten and are no longer an
|
|
50
|
+
implementation of the adapter design pattern. Instead they simply
|
|
51
|
+
use the named library to globally hook into every HTTP request.
|
|
4
52
|
|
|
5
53
|
## 1.11.3 (August 31, 2011)
|
|
6
54
|
|
data/Gemfile
CHANGED
|
@@ -18,9 +18,8 @@ end
|
|
|
18
18
|
# Additional gems that are useful, but not required for development.
|
|
19
19
|
group :extras do
|
|
20
20
|
gem 'guard-rspec'
|
|
21
|
-
gem 'guard-cucumber'
|
|
22
21
|
gem 'growl'
|
|
23
|
-
gem 'relish'
|
|
22
|
+
gem 'relish', '~> 0.5.0'
|
|
24
23
|
gem 'fuubar'
|
|
25
24
|
gem 'fuubar-cucumber'
|
|
26
25
|
|
|
@@ -31,13 +30,10 @@ group :extras do
|
|
|
31
30
|
|
|
32
31
|
platforms :mri_18 do
|
|
33
32
|
gem 'ruby-debug'
|
|
34
|
-
gem 'linecache', '0.43' # later versions do not work on 1.8.6
|
|
35
33
|
end
|
|
36
34
|
|
|
37
35
|
platforms :mri_19 do
|
|
38
|
-
gem 'linecache19', '0.5.11' # 0.5.12 cannot install on 1.9.1, and 0.5.11 appears to work with both 1.9.1 & 1.9.2
|
|
39
36
|
gem 'ruby-debug19'
|
|
40
|
-
gem 'ruby-debug-base19', RUBY_VERSION == '1.9.1' ? '0.11.23' : '~> 0.11.24'
|
|
41
37
|
end unless RUBY_VERSION == '1.9.3'
|
|
42
38
|
end
|
|
43
39
|
|
data/Guardfile
CHANGED
data/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
|
|
4
4
|
|
|
5
|
+
[](http://travis-ci.org/myronmarston/vcr)
|
|
6
|
+
|
|
5
7
|
## Synopsis
|
|
6
8
|
|
|
7
9
|
``` ruby
|
|
@@ -82,9 +84,7 @@ contain backwards-incompatible changes to the public API.
|
|
|
82
84
|
|
|
83
85
|
VCR has been tested on the following ruby interpreters:
|
|
84
86
|
|
|
85
|
-
* MRI 1.8.6
|
|
86
87
|
* MRI 1.8.7
|
|
87
|
-
* MRI 1.9.1
|
|
88
88
|
* MRI 1.9.2
|
|
89
89
|
* REE 1.8.7
|
|
90
90
|
* JRuby 1.5.6
|
|
@@ -144,6 +144,7 @@ Thanks also to the following people who have contributed patches or helpful sugg
|
|
|
144
144
|
* [Nathaniel Bibler](https://github.com/nbibler)
|
|
145
145
|
* [Oliver Searle-Barnes](https://github.com/opsb)
|
|
146
146
|
* [Wesley Beary](https://github.com/geemus)
|
|
147
|
+
* [Avdi Grimm](https://github.com/avdi)
|
|
147
148
|
|
|
148
149
|
## Copyright
|
|
149
150
|
|
data/Rakefile
CHANGED
|
@@ -11,7 +11,10 @@ require "rspec/core/rake_task"
|
|
|
11
11
|
|
|
12
12
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
13
13
|
t.verbose = false
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
# we require spec_helper so we don't get an RSpec warning about
|
|
16
|
+
# examples being defined before configuration.
|
|
17
|
+
t.ruby_opts = "-w -I./spec -r./spec/capture_warnings -rspec_helper"
|
|
15
18
|
|
|
16
19
|
# I'm not sure why, but bundler seems to silence warnings...
|
|
17
20
|
t.skip_bundler = true
|
|
@@ -29,10 +32,8 @@ task :cleanup_rcov_files do
|
|
|
29
32
|
rm_rf 'coverage.data'
|
|
30
33
|
end
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Cucumber::Rake::Task.new
|
|
35
|
-
end
|
|
35
|
+
require 'cucumber/rake/task'
|
|
36
|
+
Cucumber::Rake::Task.new
|
|
36
37
|
|
|
37
38
|
task :default => [:spec, :cucumber]
|
|
38
39
|
|
|
@@ -46,16 +47,17 @@ namespace :ci do
|
|
|
46
47
|
|
|
47
48
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
48
49
|
t.verbose = true
|
|
49
|
-
|
|
50
|
+
|
|
51
|
+
# we require spec_helper so we don't get an RSpec warning about
|
|
52
|
+
# examples being defined before configuration.
|
|
53
|
+
t.ruby_opts = "-w -I./spec -r./spec/capture_warnings -rspec_helper"
|
|
50
54
|
# I'm not sure why, but bundler seems to silence warnings...
|
|
51
55
|
t.skip_bundler = true
|
|
52
56
|
t.rspec_opts = %w[--format progress --backtrace]
|
|
53
57
|
end
|
|
54
58
|
|
|
55
|
-
ci_tasks = [:setup, :spec]
|
|
56
|
-
ci_tasks << :cucumber if %w[ 1.8.7 1.9.2 1.9.3 ].include?(RUBY_VERSION) && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby')
|
|
57
59
|
desc "Run a ci build"
|
|
58
|
-
task :build =>
|
|
60
|
+
task :build => [:setup, :spec, :cucumber]
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
def ensure_relish_doc_symlinked(filename)
|
|
@@ -98,10 +100,3 @@ task :release => [:require_ruby_18, :prep_relish_release, :relish]
|
|
|
98
100
|
# For gem-test: http://gem-testers.org/
|
|
99
101
|
task :test => :spec
|
|
100
102
|
|
|
101
|
-
task :fix_should_eq do
|
|
102
|
-
Dir["spec/**/*.rb"].each do |spec_file|
|
|
103
|
-
contents = File.read(spec_file)
|
|
104
|
-
contents.gsub!(/should == (.*)$/, 'should eq(\1)')
|
|
105
|
-
File.open(spec_file, 'w') { |f| f.write(contents) }
|
|
106
|
-
end
|
|
107
|
-
end
|
data/cucumber.yml
CHANGED
|
@@ -7,10 +7,6 @@ interp_opts = if defined?(RUBY_ENGINE)
|
|
|
7
7
|
else
|
|
8
8
|
''
|
|
9
9
|
end
|
|
10
|
-
|
|
11
|
-
if ENV['TRAVIS'] && RUBY_VERSION == '1.8.6'
|
|
12
|
-
interp_opts << ' --tags ~@exclude-travis-186'
|
|
13
|
-
end
|
|
14
10
|
%>
|
|
15
11
|
default: <%= std_opts %><%= interp_opts %> features
|
|
16
12
|
wip: --tags @wip:30 --wip features<%= interp_opts %>
|
data/features/.nav
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
- format.feature
|
|
7
7
|
- naming.feature
|
|
8
8
|
- no_cassette.feature
|
|
9
|
-
- request_matching.feature
|
|
10
9
|
- dynamic_erb.feature
|
|
11
10
|
- automatic_re_recording.feature
|
|
11
|
+
- exclusive.feature
|
|
12
12
|
- update_content_length_header.feature
|
|
13
13
|
- record_modes:
|
|
14
14
|
- once.feature
|
|
@@ -17,12 +17,24 @@
|
|
|
17
17
|
- all.feature
|
|
18
18
|
- configuration:
|
|
19
19
|
- cassette_library_dir.feature
|
|
20
|
-
-
|
|
20
|
+
- hook_into.feature
|
|
21
21
|
- default_cassette_options.feature
|
|
22
22
|
- ignore_hosts.feature
|
|
23
23
|
- ignore_localhost.feature
|
|
24
24
|
- hooks.feature
|
|
25
|
+
- filter_sensitive_data.feature
|
|
25
26
|
- allow_http_connections_when_no_cassette.feature
|
|
27
|
+
- request_matching:
|
|
28
|
+
- method.feature
|
|
29
|
+
- uri.feature
|
|
30
|
+
- host.feature
|
|
31
|
+
- path.feature
|
|
32
|
+
- body.feature
|
|
33
|
+
- headers.feature
|
|
34
|
+
- identical_request_sequence.feature
|
|
35
|
+
- custom_matcher.feature
|
|
36
|
+
- uri_without_param.feature
|
|
37
|
+
- playback_repeats.feature
|
|
26
38
|
- test_frameworks:
|
|
27
39
|
- test_unit.feature
|
|
28
40
|
- shoulda.feature
|
|
@@ -31,21 +31,19 @@ Feature: Automatic Re-recording
|
|
|
31
31
|
http_version: "1.1"
|
|
32
32
|
"""
|
|
33
33
|
And a file named "re_record.rb" with:
|
|
34
|
-
"""
|
|
35
|
-
require 'vcr_cucumber_helpers'
|
|
36
|
-
|
|
34
|
+
"""ruby
|
|
37
35
|
start_sinatra_app(:port => 7777) do
|
|
38
36
|
get('/') { 'New Response' }
|
|
39
37
|
end
|
|
40
38
|
|
|
41
39
|
require 'vcr'
|
|
42
40
|
|
|
43
|
-
VCR.
|
|
44
|
-
c.
|
|
41
|
+
VCR.configure do |c|
|
|
42
|
+
c.hook_into :fakeweb
|
|
45
43
|
c.cassette_library_dir = 'cassettes'
|
|
46
44
|
end
|
|
47
45
|
|
|
48
|
-
VCR.use_cassette('example', :
|
|
46
|
+
VCR.use_cassette('example', :re_record_interval => 7.days) do
|
|
49
47
|
puts Net::HTTP.get_response('localhost', '/', 7777).body
|
|
50
48
|
end
|
|
51
49
|
"""
|
|
@@ -32,13 +32,12 @@ Feature: Dynamic ERB cassettes
|
|
|
32
32
|
http_version: "1.1"
|
|
33
33
|
"""
|
|
34
34
|
And a file named "dynamic_erb_example.rb" with:
|
|
35
|
-
"""
|
|
35
|
+
"""ruby
|
|
36
36
|
require 'vcr'
|
|
37
37
|
|
|
38
|
-
VCR.
|
|
39
|
-
c.
|
|
38
|
+
VCR.configure do |c|
|
|
39
|
+
c.hook_into :fakeweb
|
|
40
40
|
c.cassette_library_dir = 'cassettes'
|
|
41
|
-
c.default_cassette_options = { :record => :none }
|
|
42
41
|
end
|
|
43
42
|
|
|
44
43
|
VCR.use_cassette('dynamic', :erb => true) do
|
|
@@ -72,13 +71,12 @@ Feature: Dynamic ERB cassettes
|
|
|
72
71
|
http_version: "1.1"
|
|
73
72
|
"""
|
|
74
73
|
And a file named "dynamic_erb_example.rb" with:
|
|
75
|
-
"""
|
|
74
|
+
"""ruby
|
|
76
75
|
require 'vcr'
|
|
77
76
|
|
|
78
|
-
VCR.
|
|
79
|
-
c.
|
|
77
|
+
VCR.configure do |c|
|
|
78
|
+
c.hook_into :fakeweb
|
|
80
79
|
c.cassette_library_dir = 'cassettes'
|
|
81
|
-
c.default_cassette_options = { :record => :none }
|
|
82
80
|
end
|
|
83
81
|
|
|
84
82
|
VCR.use_cassette('dynamic', :erb => { :arg1 => 7, :arg2 => 'baz' }) do
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Feature: exclusive cassette
|
|
2
|
+
|
|
3
|
+
VCR allows cassettes to be nested. This is particularly useful in
|
|
4
|
+
a context like cucumber, where you may be using a cassette for an
|
|
5
|
+
entire scenario, and also using a cassette within a particular step
|
|
6
|
+
definition.
|
|
7
|
+
|
|
8
|
+
By default, both the inner and outer cassettes are active. On each
|
|
9
|
+
request, VCR will look for a matching HTTP interaction in the inner
|
|
10
|
+
cassette, and it will use the outer cassette as a fall back if none
|
|
11
|
+
can be found.
|
|
12
|
+
|
|
13
|
+
If you do not want the HTTP interactions of the outer cassette considered,
|
|
14
|
+
you can pass the `:exclusive` option, so that the inner cassette is
|
|
15
|
+
used exclusively.
|
|
16
|
+
|
|
17
|
+
Background:
|
|
18
|
+
Given a previously recorded cassette file "cassettes/outer.yml" with:
|
|
19
|
+
"""
|
|
20
|
+
---
|
|
21
|
+
- !ruby/struct:VCR::HTTPInteraction
|
|
22
|
+
request: !ruby/struct:VCR::Request
|
|
23
|
+
method: :get
|
|
24
|
+
uri: http://localhost:7777/outer
|
|
25
|
+
body:
|
|
26
|
+
headers:
|
|
27
|
+
response: !ruby/struct:VCR::Response
|
|
28
|
+
status: !ruby/struct:VCR::ResponseStatus
|
|
29
|
+
code: 200
|
|
30
|
+
message: OK
|
|
31
|
+
headers:
|
|
32
|
+
content-length:
|
|
33
|
+
- "18"
|
|
34
|
+
body: Old outer response
|
|
35
|
+
http_version: "1.1"
|
|
36
|
+
"""
|
|
37
|
+
And a previously recorded cassette file "cassettes/inner.yml" with:
|
|
38
|
+
"""
|
|
39
|
+
---
|
|
40
|
+
- !ruby/struct:VCR::HTTPInteraction
|
|
41
|
+
request: !ruby/struct:VCR::Request
|
|
42
|
+
method: :get
|
|
43
|
+
uri: http://localhost:7777/inner
|
|
44
|
+
body:
|
|
45
|
+
headers:
|
|
46
|
+
response: !ruby/struct:VCR::Response
|
|
47
|
+
status: !ruby/struct:VCR::ResponseStatus
|
|
48
|
+
code: 200
|
|
49
|
+
message: OK
|
|
50
|
+
headers:
|
|
51
|
+
content-length:
|
|
52
|
+
- "18"
|
|
53
|
+
body: Old inner response
|
|
54
|
+
http_version: "1.1"
|
|
55
|
+
"""
|
|
56
|
+
And a file named "setup.rb" with:
|
|
57
|
+
"""ruby
|
|
58
|
+
include_http_adapter_for("net/http")
|
|
59
|
+
|
|
60
|
+
start_sinatra_app(:port => 7777) do
|
|
61
|
+
get('/:path') { "New #{params[:path]} response" }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
require 'vcr'
|
|
65
|
+
|
|
66
|
+
VCR.configure do |c|
|
|
67
|
+
c.hook_into :fakeweb
|
|
68
|
+
c.cassette_library_dir = 'cassettes'
|
|
69
|
+
c.default_cassette_options = { :record => :new_episodes }
|
|
70
|
+
end
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
Scenario: Cassettes are not exclusive by default
|
|
74
|
+
Given a file named "not_exclusive.rb" with:
|
|
75
|
+
"""ruby
|
|
76
|
+
require 'setup'
|
|
77
|
+
|
|
78
|
+
VCR.use_cassette('outer') do
|
|
79
|
+
VCR.use_cassette('inner') do
|
|
80
|
+
puts response_body_for(:get, "http://localhost:7777/outer")
|
|
81
|
+
puts response_body_for(:get, "http://localhost:7777/inner")
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
"""
|
|
85
|
+
When I run `ruby not_exclusive.rb`
|
|
86
|
+
Then it should pass with:
|
|
87
|
+
"""
|
|
88
|
+
Old outer response
|
|
89
|
+
Old inner response
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
Scenario: Use an exclusive cassette
|
|
93
|
+
Given a file named "exclusive.rb" with:
|
|
94
|
+
"""ruby
|
|
95
|
+
require 'setup'
|
|
96
|
+
|
|
97
|
+
VCR.use_cassette('outer') do
|
|
98
|
+
VCR.use_cassette('inner', :exclusive => true) do
|
|
99
|
+
puts response_body_for(:get, "http://localhost:7777/outer")
|
|
100
|
+
puts response_body_for(:get, "http://localhost:7777/inner")
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
"""
|
|
104
|
+
When I run `ruby exclusive.rb`
|
|
105
|
+
Then it should pass with:
|
|
106
|
+
"""
|
|
107
|
+
New outer response
|
|
108
|
+
Old inner response
|
|
109
|
+
"""
|
|
110
|
+
And the file "cassettes/inner.yml" should contain "body: New outer response"
|
|
111
|
+
|
|
@@ -20,8 +20,7 @@ Feature: Cassette format
|
|
|
20
20
|
|
|
21
21
|
Scenario Outline: Request/Response data is saved to disk as YAML
|
|
22
22
|
Given a file named "cassette_format.rb" with:
|
|
23
|
-
"""
|
|
24
|
-
require 'vcr_cucumber_helpers'
|
|
23
|
+
"""ruby
|
|
25
24
|
include_http_adapter_for("<http_lib>")
|
|
26
25
|
|
|
27
26
|
start_sinatra_app(:port => 7777) do
|
|
@@ -30,12 +29,12 @@ Feature: Cassette format
|
|
|
30
29
|
|
|
31
30
|
require 'vcr'
|
|
32
31
|
|
|
33
|
-
VCR.
|
|
34
|
-
|
|
32
|
+
VCR.configure do |c|
|
|
33
|
+
<configuration>
|
|
35
34
|
c.cassette_library_dir = 'cassettes'
|
|
36
35
|
end
|
|
37
36
|
|
|
38
|
-
VCR.use_cassette('example'
|
|
37
|
+
VCR.use_cassette('example') do
|
|
39
38
|
make_http_request(:get, "http://localhost:7777/foo")
|
|
40
39
|
make_http_request(:get, "http://localhost:7777/bar")
|
|
41
40
|
end
|
|
@@ -81,12 +80,15 @@ Feature: Cassette format
|
|
|
81
80
|
"""
|
|
82
81
|
|
|
83
82
|
Examples:
|
|
84
|
-
|
|
|
85
|
-
| :fakeweb
|
|
86
|
-
| :webmock
|
|
87
|
-
| :webmock
|
|
88
|
-
| :webmock
|
|
89
|
-
| :webmock
|
|
90
|
-
| :webmock
|
|
91
|
-
| :
|
|
92
|
-
| :
|
|
83
|
+
| configuration | http_lib |
|
|
84
|
+
| c.hook_into :fakeweb | net/http |
|
|
85
|
+
| c.hook_into :webmock | net/http |
|
|
86
|
+
| c.hook_into :webmock | httpclient |
|
|
87
|
+
| c.hook_into :webmock | patron |
|
|
88
|
+
| c.hook_into :webmock | curb |
|
|
89
|
+
| c.hook_into :webmock | em-http-request |
|
|
90
|
+
| c.hook_into :webmock | typhoeus |
|
|
91
|
+
| c.hook_into :typhoeus | typhoeus |
|
|
92
|
+
| c.hook_into :excon | excon |
|
|
93
|
+
| | faraday (w/ net_http) |
|
|
94
|
+
|