vcr 2.0.0.beta2 → 2.0.0.rc1
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 -0
- data/.travis.yml +0 -2
- data/CHANGELOG.md +22 -1
- data/CONTRIBUTING.md +46 -0
- data/Gemfile +1 -9
- data/README.md +8 -2
- data/Rakefile +12 -1
- data/cucumber.yml +8 -9
- data/features/.nav +10 -4
- data/features/cassettes/format.feature +1 -1
- data/features/cassettes/no_cassette.feature +8 -11
- data/features/configuration/allow_http_connections_when_no_cassette.feature +4 -4
- data/features/configuration/filter_sensitive_data.feature +3 -0
- data/features/configuration/hook_into.feature +4 -8
- data/features/configuration/ignore_request.feature +191 -0
- data/features/getting_started.md +38 -21
- data/features/hooks/after_http_request.feature +44 -0
- data/features/hooks/around_http_request.feature +56 -0
- data/features/hooks/before_http_request.feature +44 -0
- data/features/hooks/before_playback.feature +181 -0
- data/features/hooks/before_record.feature +172 -0
- data/features/middleware/faraday.feature +7 -3
- data/features/record_modes/none.feature +2 -1
- data/features/record_modes/once.feature +2 -1
- data/features/request_matching/body.feature +2 -2
- data/features/request_matching/custom_matcher.feature +2 -2
- data/features/request_matching/headers.feature +2 -2
- data/features/request_matching/host.feature +2 -2
- data/features/request_matching/identical_request_sequence.feature +2 -2
- data/features/request_matching/method.feature +2 -2
- data/features/request_matching/path.feature +2 -2
- data/features/request_matching/playback_repeats.feature +2 -1
- data/features/request_matching/uri.feature +2 -2
- data/features/support/env.rb +21 -12
- data/features/test_frameworks/cucumber.feature +9 -4
- data/features/test_frameworks/{rspec.feature → rspec_macro.feature} +7 -7
- data/features/test_frameworks/rspec_metadata.feature +90 -0
- data/lib/vcr.rb +1 -1
- data/lib/vcr/cassette.rb +3 -3
- data/lib/vcr/cassette/http_interaction_list.rb +13 -9
- data/lib/vcr/cassette/migrator.rb +1 -1
- data/lib/vcr/configuration.rb +37 -0
- data/lib/vcr/errors.rb +172 -6
- data/lib/vcr/library_hooks.rb +4 -6
- data/lib/vcr/library_hooks/excon.rb +23 -11
- data/lib/vcr/library_hooks/fakeweb.rb +85 -24
- data/lib/vcr/library_hooks/faraday.rb +30 -2
- data/lib/vcr/library_hooks/typhoeus.rb +25 -3
- data/lib/vcr/library_hooks/webmock.rb +25 -36
- data/lib/vcr/middleware/faraday.rb +23 -5
- data/lib/vcr/request_handler.rb +12 -1
- data/lib/vcr/request_ignorer.rb +12 -1
- data/lib/vcr/request_matcher_registry.rb +1 -9
- data/lib/vcr/structs.rb +32 -2
- data/lib/vcr/test_frameworks/rspec.rb +28 -0
- data/lib/vcr/util/hooks.rb +12 -4
- data/lib/vcr/util/version_checker.rb +2 -0
- data/lib/vcr/version.rb +1 -1
- data/spec/fixtures/cassette_spec/example.yml +1 -1
- data/spec/fixtures/{fake_example.com_responses.yml → fake_example_responses.yml} +0 -0
- data/spec/monkey_patches.rb +1 -1
- data/spec/spec_helper.rb +3 -1
- data/spec/support/http_library_adapters.rb +4 -3
- data/spec/support/shared_example_groups/hook_into_http_library.rb +194 -12
- data/spec/support/shared_example_groups/request_hooks.rb +58 -0
- data/spec/support/shared_example_groups/version_checking.rb +5 -0
- data/spec/support/sinatra_app.rb +17 -9
- data/spec/support/vcr_stub_helpers.rb +17 -0
- data/spec/vcr/cassette/http_interaction_list_spec.rb +28 -29
- data/spec/vcr/cassette/migrator_spec.rb +6 -7
- data/spec/vcr/cassette_spec.rb +5 -5
- data/spec/vcr/configuration_spec.rb +51 -32
- data/spec/vcr/deprecations_spec.rb +0 -8
- data/spec/vcr/errors_spec.rb +129 -0
- data/spec/vcr/library_hooks/excon_spec.rb +21 -4
- data/spec/vcr/library_hooks/fakeweb_spec.rb +71 -3
- data/spec/vcr/library_hooks/faraday_spec.rb +45 -0
- data/spec/vcr/library_hooks/typhoeus_spec.rb +31 -1
- data/spec/vcr/library_hooks/webmock_spec.rb +26 -3
- data/spec/vcr/middleware/faraday_spec.rb +84 -1
- data/spec/vcr/request_ignorer_spec.rb +16 -0
- data/spec/vcr/request_matcher_registry_spec.rb +0 -26
- data/spec/vcr/structs_spec.rb +61 -1
- data/spec/vcr/test_frameworks/rspec_spec.rb +32 -0
- data/spec/vcr/util/hooks_spec.rb +73 -63
- data/spec/vcr_spec.rb +2 -2
- data/vcr.gemspec +5 -5
- metadata +51 -31
- data/features/configuration/hooks.feature +0 -270
- data/features/configuration/ignore_hosts.feature +0 -61
- data/features/configuration/ignore_localhost.feature +0 -97
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,27 @@
|
|
1
1
|
## In git
|
2
2
|
|
3
|
-
[Full Changelog](http://github.com/myronmarston/vcr/compare/v2.0.0.
|
3
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v2.0.0.rc1...master)
|
4
|
+
|
5
|
+
## 2.0.0 RC 1 (December 8, 2011)
|
6
|
+
|
7
|
+
[Full Changelog](http://github.com/myronmarston/vcr/compare/v2.0.0.beta2...v2.0.0.rc1)
|
8
|
+
|
9
|
+
* Add Faraday hook that automatically inserts the VCR middleware so that
|
10
|
+
you can use VCR with Faraday without needing to insert the middleware
|
11
|
+
yourself. Use `VCR.configure { |c| c.hook_into :faraday }`.
|
12
|
+
* Add `ignore_request` config option. Pass it a block that returns
|
13
|
+
true if the given request should be ignored.
|
14
|
+
* Improve the unhandled HTTP request error message so that it lists
|
15
|
+
different options for how to get VCR to handle it.
|
16
|
+
* Add {before,after,around}_http_request hooks.
|
17
|
+
* Updated WebMock integration and bumped up required version to 1.7.8.
|
18
|
+
* Test against latest Excon (0.7.9) and confirm that VCR works fine with
|
19
|
+
it.
|
20
|
+
* Add define_cassette_placeholder as an alias for filter_sensitive_data.
|
21
|
+
* Fix Faraday middleware so that it works properly when you use parallel
|
22
|
+
requests.
|
23
|
+
* Integrate VCR with RSpec metadata. Thanks to [Ryan Bates](https://github.com/ryanb)
|
24
|
+
for the great idea.
|
4
25
|
|
5
26
|
## 2.0.0 Beta 2 (November 6, 2011)
|
6
27
|
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
## Contributing
|
2
|
+
|
3
|
+
Install [bundler](http://gembundler.com/) and use it to install all the development dependencies:
|
4
|
+
|
5
|
+
```console
|
6
|
+
gem install bundler
|
7
|
+
bundle install
|
8
|
+
```
|
9
|
+
|
10
|
+
Next setup the Git submodules:
|
11
|
+
|
12
|
+
```console
|
13
|
+
git submodule init
|
14
|
+
git submodule update
|
15
|
+
```
|
16
|
+
|
17
|
+
or using the single command form
|
18
|
+
|
19
|
+
```console
|
20
|
+
git submodule update --init
|
21
|
+
```
|
22
|
+
|
23
|
+
You should be able to run the tests now:
|
24
|
+
|
25
|
+
```console
|
26
|
+
bundle exec rake
|
27
|
+
```
|
28
|
+
|
29
|
+
VCR uses [RSpec 2](http://github.com/rspec/rspec) for unit tests. The specs are written in a very "focused" style, where each spec is concerned only with exercising the object under test, using mocks as necessary. You can run the specs using `rake spec`.
|
30
|
+
|
31
|
+
[Cucumber](http://cukes.info/) is used for end-to-end full stack integration tests that also function as VCR's documentation.
|
32
|
+
|
33
|
+
## Problems running bundle install?
|
34
|
+
|
35
|
+
If you get an error while running `bundle install`, it may be one of the "extras" gems which are not required for development. Try installing it without these gems.
|
36
|
+
|
37
|
+
```console
|
38
|
+
bundle install --without extras
|
39
|
+
```
|
40
|
+
|
41
|
+
If you are getting an error installing `rb-fsevent` gem, you may want to temporarily change the Gemfile to use the pre-release version of the gem.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
gem 'rb-fsevent', '0.9.0.pre4'
|
45
|
+
```
|
46
|
+
|
data/Gemfile
CHANGED
@@ -2,14 +2,6 @@ source :rubygems
|
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
group :development do
|
5
|
-
# patron and em-http-request can't install on JRuby, so we have to limit their platform here.
|
6
|
-
platforms :ruby do
|
7
|
-
gem 'patron', '~> 0.4.15'
|
8
|
-
gem 'em-http-request', '~> 0.3.0'
|
9
|
-
gem 'curb', '0.7.15'
|
10
|
-
gem 'typhoeus', '~> 0.3.2'
|
11
|
-
end
|
12
|
-
|
13
5
|
platforms :jruby do
|
14
6
|
gem 'jruby-openssl'
|
15
7
|
end
|
@@ -28,7 +20,7 @@ group :extras do
|
|
28
20
|
gem 'rb-fsevent'
|
29
21
|
end
|
30
22
|
|
31
|
-
platforms :mri_18 do
|
23
|
+
platforms :mri_18, :jruby do
|
32
24
|
gem 'ruby-debug'
|
33
25
|
end
|
34
26
|
|
data/README.md
CHANGED
@@ -11,9 +11,9 @@ require 'rubygems'
|
|
11
11
|
require 'test/unit'
|
12
12
|
require 'vcr'
|
13
13
|
|
14
|
-
VCR.
|
14
|
+
VCR.configure do |c|
|
15
15
|
c.cassette_library_dir = 'fixtures/vcr_cassettes'
|
16
|
-
c.
|
16
|
+
c.hook_into :webmock # or :fakeweb
|
17
17
|
end
|
18
18
|
|
19
19
|
class VCRTest < Test::Unit::TestCase
|
@@ -117,6 +117,8 @@ VCR has been tested on the following ruby interpreters:
|
|
117
117
|
* Report issues on [GitHub Issues](http://github.com/myronmarston/vcr/issues).
|
118
118
|
* Pull requests are very welcome! Please include spec and/or feature coverage for every patch,
|
119
119
|
and create a topic branch for every separate change you make.
|
120
|
+
* See the [Contributing](https://github.com/myronmarston/vcr/blob/master/CONTRIBUTING.md)
|
121
|
+
guide for instructions on running the specs and features.
|
120
122
|
|
121
123
|
If you find VCR useful, please recommend me on [working with rails](http://workingwithrails.com/person/16590-myron-marston).
|
122
124
|
|
@@ -139,11 +141,15 @@ Thanks also to the following people who have contributed patches or helpful sugg
|
|
139
141
|
* [Bartosz Blimke](http://github.com/bblimke)
|
140
142
|
* [Ben Hutton](http://github.com/benhutton)
|
141
143
|
* [Bradley Isotope](https://github.com/bradleyisotope)
|
144
|
+
* [Carlos Kirkconnell](https://github.com/kirkconnell)
|
142
145
|
* [Eric Allam](http://github.com/rubymaverick)
|
146
|
+
* [Flaviu Simihaian](https://github.com/closedbracket)
|
143
147
|
* [Justin Smestad](https://github.com/jsmestad)
|
144
148
|
* [Karl Baum](https://github.com/kbaum)
|
145
149
|
* [Nathaniel Bibler](https://github.com/nbibler)
|
146
150
|
* [Oliver Searle-Barnes](https://github.com/opsb)
|
151
|
+
* [Paco Guzmán](https://github.com/pacoguzman)
|
152
|
+
* [Ryan Bates](https://github.com/ryanb)
|
147
153
|
* [Sathya Sekaran](https://github.com/sfsekaran)
|
148
154
|
* [Wesley Beary](https://github.com/geemus)
|
149
155
|
|
data/Rakefile
CHANGED
@@ -72,7 +72,7 @@ end
|
|
72
72
|
|
73
73
|
desc "Push cukes to relishapp using the relish-client-gem"
|
74
74
|
task :relish do
|
75
|
-
%w[ README.md CHANGELOG.md Upgrade.md LICENSE ].each do |file|
|
75
|
+
%w[ README.md CHANGELOG.md Upgrade.md LICENSE CONTRIBUTING.md].each do |file|
|
76
76
|
ensure_relish_doc_symlinked(file)
|
77
77
|
end
|
78
78
|
|
@@ -136,3 +136,14 @@ task :migrate_cucumber_cassettes do
|
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
+
desc "Run the last cuke directly"
|
140
|
+
task :run_last_cuke do
|
141
|
+
command = ENV.fetch('CMD') do
|
142
|
+
raise "Must pass CMD"
|
143
|
+
end
|
144
|
+
|
145
|
+
Dir.chdir("tmp/aruba") do
|
146
|
+
sh "RUBYOPT='-I.:../../lib -r../../features/support/vcr_cucumber_helpers' ruby #{command}"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
data/cucumber.yml
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
<%
|
2
2
|
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
|
3
3
|
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'Cucumber::Formatter::Fuubar'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
|
4
|
-
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'Cucumber::Formatter::Fuubar'} --strict
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
4
|
+
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'Cucumber::Formatter::Fuubar'} --strict"
|
5
|
+
|
6
|
+
exclusions = ["--tags ~@exclude-#{RUBY_VERSION.split('.').first(2).join}"].tap do |a|
|
7
|
+
a << "--tags ~@exclude-#{RUBY_ENGINE}" if defined?(RUBY_ENGINE)
|
8
|
+
end.join(' ')
|
10
9
|
%>
|
11
|
-
default: <%= std_opts
|
12
|
-
wip: --tags @wip
|
13
|
-
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip<%=
|
10
|
+
default: <%= std_opts %> --tags ~@wip <%= exclusions %> features
|
11
|
+
wip: --tags @wip <%= exclusions %> features
|
12
|
+
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip <%= exclusions %>
|
14
13
|
|
data/features/.nav
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
- CHANGELOG.md (Changelog)
|
4
4
|
- about_these_examples.md (About These Examples)
|
5
5
|
- LICENSE.md (License)
|
6
|
+
- CONTRIBUTING.md (Contributing)
|
6
7
|
- cassettes:
|
7
8
|
- format.feature
|
8
9
|
- naming.feature
|
@@ -20,11 +21,15 @@
|
|
20
21
|
- cassette_library_dir.feature
|
21
22
|
- hook_into.feature
|
22
23
|
- default_cassette_options.feature
|
23
|
-
-
|
24
|
-
- ignore_localhost.feature
|
25
|
-
- hooks.feature
|
24
|
+
- ignore_request.feature
|
26
25
|
- filter_sensitive_data.feature
|
27
26
|
- allow_http_connections_when_no_cassette.feature
|
27
|
+
- hooks:
|
28
|
+
- before_record.feature
|
29
|
+
- before_playback.feature
|
30
|
+
- before_http_request.feature
|
31
|
+
- after_http_request.feature
|
32
|
+
- around_http_request.feature
|
28
33
|
- request_matching:
|
29
34
|
- method.feature
|
30
35
|
- uri.feature
|
@@ -39,7 +44,8 @@
|
|
39
44
|
- test_frameworks:
|
40
45
|
- test_unit.feature
|
41
46
|
- shoulda.feature
|
42
|
-
-
|
47
|
+
- rspec_metadata.feature
|
48
|
+
- rspec_macro.feature
|
43
49
|
- cucumber.feature
|
44
50
|
- middleware:
|
45
51
|
- rack.feature
|
@@ -122,7 +122,7 @@ Feature: Cassette format
|
|
122
122
|
| c.hook_into :webmock | typhoeus |
|
123
123
|
| c.hook_into :typhoeus | typhoeus |
|
124
124
|
| c.hook_into :excon | excon |
|
125
|
-
|
|
125
|
+
| c.hook_into :faraday | faraday (w/ net_http) |
|
126
126
|
|
127
127
|
Scenario: Request/Response data can be saved as JSON
|
128
128
|
Given a file named "cassette_json.rb" with:
|
@@ -7,9 +7,8 @@ Feature: Error for HTTP request made when no cassette is in use
|
|
7
7
|
made so you can use a VCR cassette at that point in your code.
|
8
8
|
|
9
9
|
If you want to allow an HTTP request to proceed as normal, you can
|
10
|
-
set the
|
11
|
-
|
12
|
-
you can temporarily turn VCR off:
|
10
|
+
set the [allow\_http\_connections\_when\_no\_cassette](../configuration/allow-http-connections-when-no-cassette)
|
11
|
+
configuration option or you can temporarily turn VCR off:
|
13
12
|
|
14
13
|
- `VCR.turn_off!` => turn VCR off so HTTP requests are allowed.
|
15
14
|
Cassette insertions will trigger an error.
|
@@ -19,6 +18,7 @@ Feature: Error for HTTP request made when no cassette is in use
|
|
19
18
|
- `VCR.turned_off { ... }` => turn VCR off for the duration of the
|
20
19
|
provided block.
|
21
20
|
|
21
|
+
@exclude-jruby
|
22
22
|
Scenario Outline: Error for request when no cassette is in use
|
23
23
|
Given a file named "no_cassette_error.rb" with:
|
24
24
|
"""ruby
|
@@ -34,10 +34,7 @@ Feature: Error for HTTP request made when no cassette is in use
|
|
34
34
|
response_body_for(:get, 'http://example.com/')
|
35
35
|
"""
|
36
36
|
When I run `ruby no_cassette_error.rb`
|
37
|
-
Then it should fail with "
|
38
|
-
And the output should contain each of the following:
|
39
|
-
| You can use VCR to automatically record this request and replay it later. |
|
40
|
-
| no_cassette_error.rb:10 |
|
37
|
+
Then it should fail with "An HTTP request has been made that VCR does not know how to handle"
|
41
38
|
|
42
39
|
Examples:
|
43
40
|
| configuration | http_lib |
|
@@ -50,7 +47,7 @@ Feature: Error for HTTP request made when no cassette is in use
|
|
50
47
|
| c.hook_into :webmock | typhoeus |
|
51
48
|
| c.hook_into :typhoeus | typhoeus |
|
52
49
|
| c.hook_into :excon | excon |
|
53
|
-
|
|
50
|
+
| c.hook_into :faraday | faraday (w/ net_http) |
|
54
51
|
|
55
52
|
Scenario: Temporarily turn VCR off to allow HTTP requests to procede as normal
|
56
53
|
Given a file named "turn_off_vcr.rb" with:
|
@@ -69,7 +66,7 @@ Feature: Error for HTTP request made when no cassette is in use
|
|
69
66
|
puts context
|
70
67
|
puts Net::HTTP.get_response('localhost', '/', 7777).body
|
71
68
|
rescue => e
|
72
|
-
puts "Error: #{e.
|
69
|
+
puts "Error: #{e.class}"
|
73
70
|
end
|
74
71
|
|
75
72
|
VCR.turned_off do
|
@@ -93,7 +90,7 @@ Feature: Error for HTTP request made when no cassette is in use
|
|
93
90
|
And the output should contain:
|
94
91
|
"""
|
95
92
|
Outside of VCR.turned_off block
|
96
|
-
Error:
|
93
|
+
Error: VCR::Errors::UnhandledHTTPRequestError
|
97
94
|
"""
|
98
95
|
And the output should contain:
|
99
96
|
"""
|
@@ -103,7 +100,7 @@ Feature: Error for HTTP request made when no cassette is in use
|
|
103
100
|
And the output should contain:
|
104
101
|
"""
|
105
102
|
After calling VCR.turn_on!
|
106
|
-
Error:
|
103
|
+
Error: VCR::Errors::UnhandledHTTPRequestError
|
107
104
|
"""
|
108
105
|
|
109
106
|
Scenario: Turning VCR off prevents cassettes from being inserted
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Feature: Allow HTTP connections when no cassette
|
2
2
|
|
3
|
-
Usually, HTTP requests made when no cassette is inserted will result
|
4
|
-
|
5
|
-
`allow_http_connections_when_no_cassette` configuration option
|
6
|
-
true to allow requests, if you do not want to use VCR for everything.
|
3
|
+
Usually, HTTP requests made when no cassette is inserted will [result in an
|
4
|
+
error](../cassettes/error-for-http-request-made-when-no-cassette-is-in-use).
|
5
|
+
You can set the `allow_http_connections_when_no_cassette` configuration option
|
6
|
+
to true to allow requests, if you do not want to use VCR for everything.
|
7
7
|
|
8
8
|
Background:
|
9
9
|
Given a file named "vcr_setup.rb" with:
|
@@ -1,5 +1,8 @@
|
|
1
1
|
Feature: Filter sensitive data
|
2
2
|
|
3
|
+
Note: this config option is also available as `define_cassette_placeholder`
|
4
|
+
to reflect the fact that it is useful for more than just sensitive data.
|
5
|
+
|
3
6
|
The `filter_sensitive_data` configuration option can be used to prevent
|
4
7
|
sensitive data from being written to your cassette files. This may be
|
5
8
|
important if you commit your cassettes files to source control and do
|
@@ -15,10 +15,7 @@ Feature: hook_into
|
|
15
15
|
- :typhoeus can be used to hook into itself (as long as you use Typhoeus::Hydra,
|
16
16
|
but not Typhoeus::Easy or Typhoeus::Multi).
|
17
17
|
- :excon can be used to hook into itself.
|
18
|
-
|
19
|
-
In addition, you can use VCR with Faraday if you use the provided
|
20
|
-
middleware in your Faraday connection stack. When you use VCR with Faraday,
|
21
|
-
you do not need to configure `hook_into` (since the middleware is sufficient).
|
18
|
+
- :faraday can be used to hook into itself.
|
22
19
|
|
23
20
|
There are some addiitonal trade offs to consider when deciding which
|
24
21
|
option to use:
|
@@ -85,8 +82,8 @@ Feature: hook_into
|
|
85
82
|
| c.hook_into :webmock | typhoeus |
|
86
83
|
| c.hook_into :typhoeus | typhoeus |
|
87
84
|
| c.hook_into :excon | excon |
|
88
|
-
|
|
89
|
-
|
|
85
|
+
| c.hook_into :faraday | faraday (w/ net_http) |
|
86
|
+
| c.hook_into :faraday | faraday (w/ typhoeus) |
|
90
87
|
|
91
88
|
@exclude-jruby
|
92
89
|
Scenario Outline: Use Typhoeus, Excon and Faraday in combination with FakeWeb or WebMock
|
@@ -117,7 +114,6 @@ Feature: hook_into
|
|
117
114
|
|
118
115
|
def faraday_response
|
119
116
|
Faraday::Connection.new(:url => 'http://localhost:7777') do |builder|
|
120
|
-
builder.use VCR::Middleware::Faraday
|
121
117
|
builder.adapter :<faraday_adapter>
|
122
118
|
end.get('/faraday').body
|
123
119
|
end
|
@@ -128,7 +124,7 @@ Feature: hook_into
|
|
128
124
|
puts "Faraday 1: #{faraday_response}"
|
129
125
|
|
130
126
|
VCR.configure do |c|
|
131
|
-
c.hook_into <hook_into>, :typhoeus, :excon
|
127
|
+
c.hook_into <hook_into>, :typhoeus, :excon, :faraday
|
132
128
|
c.cassette_library_dir = 'vcr_cassettes'
|
133
129
|
c.ignore_localhost = false
|
134
130
|
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
Feature: Ignore Request
|
2
|
+
|
3
|
+
By default, VCR hooks into every request, either allowing it and recording
|
4
|
+
it, or playing back a recorded response, or raising an error to force you
|
5
|
+
to deal with the new request. In some situations, you may prefer to have
|
6
|
+
VCR ignore some requests.
|
7
|
+
|
8
|
+
VCR provides 3 configuration options to accomplish this:
|
9
|
+
|
10
|
+
* `ignore_request { |req| ... }` will ignore any request for which the
|
11
|
+
given block returns true.
|
12
|
+
* `ignore_hosts 'foo.com', 'bar.com'` allows you to specify particular
|
13
|
+
hosts to ignore.
|
14
|
+
* `ignore_localhost = true` is equivalent to `ignore_hosts 'localhost',
|
15
|
+
'127.0.0.1', '0.0.0.0'`. It is particularly useful for when you use
|
16
|
+
VCR with a javascript-enabled capybara driver, since capybara boots
|
17
|
+
your rack app and makes localhost requests to it to check that it has
|
18
|
+
booted.
|
19
|
+
|
20
|
+
Ignored requests are not recorded and are always allowed, regardless of
|
21
|
+
the record mode, and even outside of a `VCR.use_cassette` block.
|
22
|
+
|
23
|
+
Background:
|
24
|
+
Given a file named "sinatra_app.rb" with:
|
25
|
+
"""ruby
|
26
|
+
response_count = 0
|
27
|
+
start_sinatra_app(:port => 7777) do
|
28
|
+
get('/') { "Port 7777 Response #{response_count += 1}" }
|
29
|
+
end
|
30
|
+
"""
|
31
|
+
|
32
|
+
@exclude-jruby
|
33
|
+
Scenario Outline: ignore requests to a specific port
|
34
|
+
Given a file named "ignore_request.rb" with:
|
35
|
+
"""ruby
|
36
|
+
include_http_adapter_for("<http_lib>")
|
37
|
+
require 'sinatra_app.rb'
|
38
|
+
|
39
|
+
response_count = 0
|
40
|
+
start_sinatra_app(:port => 8888) do
|
41
|
+
get('/') { "Port 8888 Response #{response_count += 1}" }
|
42
|
+
end
|
43
|
+
|
44
|
+
require 'vcr'
|
45
|
+
|
46
|
+
VCR.configure do |c|
|
47
|
+
c.ignore_request do |request|
|
48
|
+
URI(request.uri).port == 7777
|
49
|
+
end
|
50
|
+
|
51
|
+
c.cassette_library_dir = 'cassettes'
|
52
|
+
<configuration>
|
53
|
+
end
|
54
|
+
|
55
|
+
VCR.use_cassette('example') do
|
56
|
+
puts response_body_for(:get, "http://localhost:8888/")
|
57
|
+
end
|
58
|
+
|
59
|
+
VCR.use_cassette('example') do
|
60
|
+
puts response_body_for(:get, "http://localhost:7777/")
|
61
|
+
end
|
62
|
+
|
63
|
+
puts response_body_for(:get, "http://localhost:7777/")
|
64
|
+
puts response_body_for(:get, "http://localhost:8888/")
|
65
|
+
"""
|
66
|
+
When I run `ruby ignore_request.rb`
|
67
|
+
Then it should fail with:
|
68
|
+
"""
|
69
|
+
An HTTP request has been made that VCR does not know how to handle:
|
70
|
+
GET http://localhost:8888/
|
71
|
+
"""
|
72
|
+
And the output should contain:
|
73
|
+
"""
|
74
|
+
Port 8888 Response 1
|
75
|
+
Port 7777 Response 1
|
76
|
+
Port 7777 Response 2
|
77
|
+
"""
|
78
|
+
And the file "cassettes/example.yml" should contain "body: Port 8888"
|
79
|
+
And the file "cassettes/example.yml" should not contain "body: Port 7777"
|
80
|
+
|
81
|
+
Examples:
|
82
|
+
| configuration | http_lib |
|
83
|
+
| c.hook_into :fakeweb | net/http |
|
84
|
+
| c.hook_into :webmock | net/http |
|
85
|
+
| c.hook_into :typhoeus | typhoeus |
|
86
|
+
| c.hook_into :faraday | faraday (w/ net_http) |
|
87
|
+
|
88
|
+
Scenario Outline: ignored host requests are not recorded and are always allowed
|
89
|
+
Given a file named "ignore_hosts.rb" with:
|
90
|
+
"""ruby
|
91
|
+
include_http_adapter_for("<http_lib>")
|
92
|
+
require 'sinatra_app.rb'
|
93
|
+
|
94
|
+
require 'vcr'
|
95
|
+
|
96
|
+
VCR.configure do |c|
|
97
|
+
c.ignore_hosts '127.0.0.1', 'localhost'
|
98
|
+
c.cassette_library_dir = 'cassettes'
|
99
|
+
<configuration>
|
100
|
+
end
|
101
|
+
|
102
|
+
VCR.use_cassette('example') do
|
103
|
+
puts response_body_for(:get, "http://localhost:7777/")
|
104
|
+
end
|
105
|
+
|
106
|
+
puts response_body_for(:get, "http://localhost:7777/")
|
107
|
+
"""
|
108
|
+
When I run `ruby ignore_hosts.rb`
|
109
|
+
Then it should pass with:
|
110
|
+
"""
|
111
|
+
Port 7777 Response 1
|
112
|
+
Port 7777 Response 2
|
113
|
+
"""
|
114
|
+
And the file "cassettes/example.yml" should not exist
|
115
|
+
|
116
|
+
Examples:
|
117
|
+
| configuration | http_lib |
|
118
|
+
| c.hook_into :fakeweb | net/http |
|
119
|
+
| c.hook_into :webmock | net/http |
|
120
|
+
| c.hook_into :typhoeus | typhoeus |
|
121
|
+
| c.hook_into :excon | excon |
|
122
|
+
| c.hook_into :faraday | faraday (w/ net_http) |
|
123
|
+
|
124
|
+
@exclude-jruby
|
125
|
+
Scenario Outline: localhost requests are not treated differently by default
|
126
|
+
Given a file named "localhost_not_ignored.rb" with:
|
127
|
+
"""ruby
|
128
|
+
include_http_adapter_for("<http_lib>")
|
129
|
+
require 'sinatra_app.rb'
|
130
|
+
|
131
|
+
require 'vcr'
|
132
|
+
|
133
|
+
VCR.configure do |c|
|
134
|
+
c.cassette_library_dir = 'cassettes'
|
135
|
+
<configuration>
|
136
|
+
end
|
137
|
+
|
138
|
+
VCR.use_cassette('localhost') do
|
139
|
+
response_body_for(:get, "http://localhost:7777/")
|
140
|
+
end
|
141
|
+
|
142
|
+
response_body_for(:get, "http://localhost:7777/")
|
143
|
+
"""
|
144
|
+
When I run `ruby localhost_not_ignored.rb`
|
145
|
+
Then it should fail with "An HTTP request has been made that VCR does not know how to handle"
|
146
|
+
And the file "cassettes/localhost.yml" should contain "body: Port 7777 Response 1"
|
147
|
+
|
148
|
+
Examples:
|
149
|
+
| configuration | http_lib |
|
150
|
+
| c.hook_into :fakeweb | net/http |
|
151
|
+
| c.hook_into :webmock | net/http |
|
152
|
+
| c.hook_into :typhoeus | typhoeus |
|
153
|
+
| c.hook_into :excon | excon |
|
154
|
+
| c.hook_into :faraday | faraday (w/ net_http) |
|
155
|
+
|
156
|
+
Scenario Outline: localhost requests are allowed and not recorded when ignore_localhost = true
|
157
|
+
Given a file named "ignore_localhost_true.rb" with:
|
158
|
+
"""ruby
|
159
|
+
include_http_adapter_for("<http_lib>")
|
160
|
+
require 'sinatra_app.rb'
|
161
|
+
|
162
|
+
require 'vcr'
|
163
|
+
|
164
|
+
VCR.configure do |c|
|
165
|
+
c.ignore_localhost = true
|
166
|
+
c.cassette_library_dir = 'cassettes'
|
167
|
+
<configuration>
|
168
|
+
end
|
169
|
+
|
170
|
+
VCR.use_cassette('localhost') do
|
171
|
+
puts response_body_for(:get, "http://localhost:7777/")
|
172
|
+
end
|
173
|
+
|
174
|
+
puts response_body_for(:get, "http://localhost:7777/")
|
175
|
+
"""
|
176
|
+
When I run `ruby ignore_localhost_true.rb`
|
177
|
+
Then it should pass with:
|
178
|
+
"""
|
179
|
+
Port 7777 Response 1
|
180
|
+
Port 7777 Response 2
|
181
|
+
"""
|
182
|
+
And the file "cassettes/localhost.yml" should not exist
|
183
|
+
|
184
|
+
Examples:
|
185
|
+
| configuration | http_lib |
|
186
|
+
| c.hook_into :fakeweb | net/http |
|
187
|
+
| c.hook_into :webmock | net/http |
|
188
|
+
| c.hook_into :typhoeus | typhoeus |
|
189
|
+
| c.hook_into :excon | excon |
|
190
|
+
| c.hook_into :faraday | faraday (w/ net_http) |
|
191
|
+
|