vcr 1.11.3 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,84 @@
|
|
1
|
+
Feature: Matching on URI
|
2
|
+
|
3
|
+
Use the `:uri` request matcher to match requests on the request URI.
|
4
|
+
|
5
|
+
The `:uri` matcher is used (along with the `:method` matcher) by default
|
6
|
+
if you do not specify how requests should match.
|
7
|
+
|
8
|
+
Background:
|
9
|
+
Given a previously recorded cassette file "cassettes/example.yml" with:
|
10
|
+
"""
|
11
|
+
---
|
12
|
+
- !ruby/struct:VCR::HTTPInteraction
|
13
|
+
request: !ruby/struct:VCR::Request
|
14
|
+
method: :post
|
15
|
+
uri: http://example.com:80/foo
|
16
|
+
body:
|
17
|
+
headers:
|
18
|
+
response: !ruby/struct:VCR::Response
|
19
|
+
status: !ruby/struct:VCR::ResponseStatus
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
content-length:
|
24
|
+
- "12"
|
25
|
+
body: foo response
|
26
|
+
http_version: "1.1"
|
27
|
+
- !ruby/struct:VCR::HTTPInteraction
|
28
|
+
request: !ruby/struct:VCR::Request
|
29
|
+
method: :post
|
30
|
+
uri: http://example.com:80/bar
|
31
|
+
body:
|
32
|
+
headers:
|
33
|
+
response: !ruby/struct:VCR::Response
|
34
|
+
status: !ruby/struct:VCR::ResponseStatus
|
35
|
+
code: 200
|
36
|
+
message: OK
|
37
|
+
headers:
|
38
|
+
content-length:
|
39
|
+
- "12"
|
40
|
+
body: bar response
|
41
|
+
http_version: "1.1"
|
42
|
+
"""
|
43
|
+
|
44
|
+
Scenario Outline: Replay interaction that matches the request URI
|
45
|
+
And a file named "uri_matching.rb" with:
|
46
|
+
"""ruby
|
47
|
+
include_http_adapter_for("<http_lib>")
|
48
|
+
|
49
|
+
require 'vcr'
|
50
|
+
|
51
|
+
VCR.configure do |c|
|
52
|
+
<configuration>
|
53
|
+
c.cassette_library_dir = 'cassettes'
|
54
|
+
end
|
55
|
+
|
56
|
+
VCR.use_cassette('example', :match_requests_on => [:uri]) do
|
57
|
+
puts "Response for /bar: " + response_body_for(:get, "http://example.com/bar")
|
58
|
+
end
|
59
|
+
|
60
|
+
VCR.use_cassette('example', :match_requests_on => [:uri]) do
|
61
|
+
puts "Response for /foo: " + response_body_for(:get, "http://example.com/foo")
|
62
|
+
end
|
63
|
+
"""
|
64
|
+
When I run `ruby uri_matching.rb`
|
65
|
+
Then it should pass with:
|
66
|
+
"""
|
67
|
+
Response for /bar: bar response
|
68
|
+
Response for /foo: foo response
|
69
|
+
"""
|
70
|
+
|
71
|
+
Examples:
|
72
|
+
| configuration | http_lib |
|
73
|
+
| c.hook_into :fakeweb | net/http |
|
74
|
+
| c.hook_into :webmock | net/http |
|
75
|
+
| c.hook_into :webmock | httpclient |
|
76
|
+
| c.hook_into :webmock | curb |
|
77
|
+
| c.hook_into :webmock | patron |
|
78
|
+
| c.hook_into :webmock | em-http-request |
|
79
|
+
| c.hook_into :webmock | typhoeus |
|
80
|
+
| c.hook_into :typhoeus | typhoeus |
|
81
|
+
| c.hook_into :excon | excon |
|
82
|
+
| | faraday (w/ net_http) |
|
83
|
+
| | faraday (w/ typhoeus) |
|
84
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
Feature: URI without param(s)
|
2
|
+
|
3
|
+
A common source of difficulty when using VCR with the default matchers
|
4
|
+
are non-deterministic URIs. If the URI changes on every test run (because
|
5
|
+
it includes a timestamp parameter, or whatever), the default URI matcher
|
6
|
+
will not work well for you.
|
7
|
+
|
8
|
+
You can write a custom matcher to match URIs however you want, but for the
|
9
|
+
common need to match on a URI and ignore particular query parameters, VCR
|
10
|
+
provides an easier way:
|
11
|
+
|
12
|
+
:match_requests_on => [:method, VCR.request_matchers.uri_without_param(:timestamp)]
|
13
|
+
|
14
|
+
`uri_without_param` also has a plural alias (i.e. `uri_without_params(:timestamp, :session)`)
|
15
|
+
|
16
|
+
Background:
|
17
|
+
Given a previously recorded cassette file "cassettes/example.yml" with:
|
18
|
+
"""
|
19
|
+
---
|
20
|
+
- !ruby/struct:VCR::HTTPInteraction
|
21
|
+
request: !ruby/struct:VCR::Request
|
22
|
+
method: :get
|
23
|
+
uri: http://example.com:80/search?q=foo×tamp=1316920490
|
24
|
+
body:
|
25
|
+
headers:
|
26
|
+
response: !ruby/struct:VCR::Response
|
27
|
+
status: !ruby/struct:VCR::ResponseStatus
|
28
|
+
code: 200
|
29
|
+
message: OK
|
30
|
+
headers:
|
31
|
+
content-length:
|
32
|
+
- "12"
|
33
|
+
body: foo response
|
34
|
+
http_version: "1.1"
|
35
|
+
- !ruby/struct:VCR::HTTPInteraction
|
36
|
+
request: !ruby/struct:VCR::Request
|
37
|
+
method: :get
|
38
|
+
uri: http://example.com:80/search?q=bar×tamp=1296723437
|
39
|
+
body:
|
40
|
+
headers:
|
41
|
+
response: !ruby/struct:VCR::Response
|
42
|
+
status: !ruby/struct:VCR::ResponseStatus
|
43
|
+
code: 200
|
44
|
+
message: OK
|
45
|
+
headers:
|
46
|
+
content-length:
|
47
|
+
- "12"
|
48
|
+
body: bar response
|
49
|
+
http_version: "1.1"
|
50
|
+
"""
|
51
|
+
|
52
|
+
Scenario: Match the URI on all but the timestamp query parameter
|
53
|
+
And a file named "uri_without_param_matcher.rb" with:
|
54
|
+
"""ruby
|
55
|
+
include_http_adapter_for("net/http")
|
56
|
+
|
57
|
+
require 'vcr'
|
58
|
+
|
59
|
+
VCR.configure do |c|
|
60
|
+
c.hook_into :fakeweb
|
61
|
+
c.cassette_library_dir = 'cassettes'
|
62
|
+
c.default_cassette_options = {
|
63
|
+
:match_requests_on => [:method, VCR.request_matchers.uri_without_param(:timestamp)]
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def search_uri(q)
|
68
|
+
"http://example.com:80/search?q=#{q}×tamp=#{Time.now.to_i}"
|
69
|
+
end
|
70
|
+
|
71
|
+
VCR.use_cassette('example') do
|
72
|
+
puts "Response for bar: " + response_body_for(:get, search_uri("bar"))
|
73
|
+
end
|
74
|
+
|
75
|
+
VCR.use_cassette('example') do
|
76
|
+
puts "Response for foo: " + response_body_for(:get, search_uri("foo"))
|
77
|
+
end
|
78
|
+
"""
|
79
|
+
When I run `ruby uri_without_param_matcher.rb`
|
80
|
+
Then it should pass with:
|
81
|
+
"""
|
82
|
+
Response for bar: bar response
|
83
|
+
Response for foo: foo response
|
84
|
+
"""
|
85
|
+
|
@@ -1,32 +1,8 @@
|
|
1
1
|
require 'vcr'
|
2
2
|
|
3
3
|
module VCRHelpers
|
4
|
-
YAML_REGEX_FOR_1_9_1 = Regexp.union(*[
|
5
|
-
' request',
|
6
|
-
' method',
|
7
|
-
' uri',
|
8
|
-
' body',
|
9
|
-
' headers',
|
10
|
-
' response',
|
11
|
-
' status',
|
12
|
-
' code',
|
13
|
-
' message',
|
14
|
-
' body',
|
15
|
-
' http_version'
|
16
|
-
].uniq)
|
17
|
-
|
18
|
-
def normalize_cassette_yaml(content)
|
19
|
-
return content unless RUBY_VERSION == '1.9.1'
|
20
|
-
|
21
|
-
# Ruby 1.9.1 serializes YAML a bit different, so
|
22
|
-
# we deal with that difference and add leading colons here.
|
23
|
-
content = content.gsub(YAML_REGEX_FOR_1_9_1) do |match|
|
24
|
-
match.sub(/^ +/, '\0:')
|
25
|
-
end
|
26
|
-
end
|
27
4
|
|
28
5
|
def normalize_cassette_structs(content)
|
29
|
-
content = normalize_cassette_yaml(content)
|
30
6
|
structs = YAML.load(content)
|
31
7
|
|
32
8
|
# Remove non-deterministic headers
|
@@ -34,9 +10,9 @@ module VCRHelpers
|
|
34
10
|
s.response.headers.reject! { |k, v| %w[ server date ].include?(k) }
|
35
11
|
end
|
36
12
|
|
37
|
-
case
|
38
|
-
when
|
39
|
-
# Excon
|
13
|
+
case @stubbing_lib_for_current_scenario
|
14
|
+
when /excon|faraday/
|
15
|
+
# Excon/Faraday do not expose the status message or http version,
|
40
16
|
# so we have no way to record these attributes.
|
41
17
|
structs.each do |s|
|
42
18
|
s.response.status.message = nil
|
@@ -69,7 +45,7 @@ Given /^the directory "([^"]*)" does not exist$/ do |dir|
|
|
69
45
|
end
|
70
46
|
|
71
47
|
Given /^a previously recorded cassette file "([^"]*)" with:$/ do |file_name, content|
|
72
|
-
write_file(file_name,
|
48
|
+
write_file(file_name, content)
|
73
49
|
end
|
74
50
|
|
75
51
|
Given /^(\d+) days have passed since the cassette was recorded$/ do |day_count|
|
data/features/support/env.rb
CHANGED
@@ -4,20 +4,22 @@ Bundler.setup
|
|
4
4
|
|
5
5
|
require 'aruba/cucumber'
|
6
6
|
|
7
|
-
|
8
|
-
this_dir = File.dirname(__FILE__)
|
9
|
-
in_current_dir do
|
10
|
-
FileUtils.ln_s File.join(this_dir, 'vcr_cucumber_helpers.rb'), 'vcr_cucumber_helpers.rb'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
7
|
+
cucumer_helpers_file = '../../features/support/vcr_cucumber_helpers'
|
14
8
|
if RUBY_VERSION > '1.9.1'
|
15
9
|
Before do
|
16
|
-
set_env('RUBYOPT',
|
10
|
+
set_env('RUBYOPT', "-I.:../../lib -r#{cucumer_helpers_file}")
|
17
11
|
end
|
18
12
|
elsif RUBY_PLATFORM == 'java'
|
19
13
|
Before do
|
20
|
-
set_env('RUBYOPT',
|
14
|
+
set_env('RUBYOPT', "-I../../lib -rubygems -r#{cucumer_helpers_file}")
|
15
|
+
|
16
|
+
# ideas taken from: http://blog.headius.com/2010/03/jruby-startup-time-tips.html
|
17
|
+
set_env('JRUBY_OPTS', '-X-C') # disable JIT since these processes are so short lived
|
18
|
+
set_env('JAVA_OPTS', '-d32') # force jRuby to use client JVM for faster startup times
|
19
|
+
end
|
20
|
+
else
|
21
|
+
Before do
|
22
|
+
set_env('RUBYOPT', "-rubygems -r#{cucumer_helpers_file}")
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
@@ -27,8 +27,6 @@ elsif RUBY_PLATFORM == 'java'
|
|
27
27
|
# on JRuby. I'm not sure why, and there's little benefit to running
|
28
28
|
# them on JRuby...so we just skip them. Excon seems to have the same issue :(.
|
29
29
|
UNSUPPORTED_HTTP_LIBS = c_dependent_libs + %w[ httpclient excon ]
|
30
|
-
elsif RUBY_VERSION == '1.8.6' && ENV['TRAVIS']
|
31
|
-
UNSUPPORTED_HTTP_LIBS = %w[ em-http-request ]
|
32
30
|
end
|
33
31
|
|
34
32
|
if defined?(UNSUPPORTED_HTTP_LIBS)
|
@@ -42,19 +40,12 @@ if defined?(UNSUPPORTED_HTTP_LIBS)
|
|
42
40
|
end
|
43
41
|
end
|
44
42
|
|
45
|
-
stubbing_libs = %w[ :fakeweb :webmock :typhoeus :faraday :excon ]
|
46
|
-
|
47
43
|
# Set a global based on the current stubbing lib so we can put special-case
|
48
44
|
# logic in our step definitions based on the http stubbing library.
|
49
45
|
Before do |scenario|
|
50
46
|
if scenario.respond_to?(:cell_values)
|
51
|
-
|
52
|
-
if stub_with.size == 1
|
53
|
-
$stubbing_lib_for_current_scenario = stub_with.first
|
54
|
-
else
|
55
|
-
$stubbing_lib_for_current_scenario = nil
|
56
|
-
end
|
47
|
+
@stubbing_lib_for_current_scenario = scenario.cell_values.find { |v| v =~ /fakeweb|webmock|typhoeus|faraday|excon/ }
|
57
48
|
else
|
58
|
-
|
49
|
+
@stubbing_lib_for_current_scenario = nil
|
59
50
|
end
|
60
51
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
# This file gets symlinked into the tmp/aruba directory before
|
2
2
|
# each scenario so that it is available to be required in them.
|
3
|
-
$LOAD_PATH
|
3
|
+
$LOAD_PATH << '../../spec' unless $LOAD_PATH.include?('../../spec')
|
4
4
|
$LOAD_PATH.unshift '../../lib' unless $LOAD_PATH.include?('../../lib')
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
if RUNNING_UNDER_ARUBA
|
6
|
+
running_under_aruba = File.expand_path('.').include?('aruba')
|
7
|
+
if running_under_aruba
|
9
8
|
require 'support/fixnum_extension'
|
10
9
|
require 'vcr/util/internet_connection'
|
11
10
|
|
@@ -23,7 +22,7 @@ end
|
|
23
22
|
|
24
23
|
def include_http_adapter_for(lib)
|
25
24
|
require 'support/http_library_adapters'
|
26
|
-
require lib
|
25
|
+
require (lib =~ /faraday/ ? 'faraday' : lib)
|
27
26
|
include HTTP_LIBRARY_ADAPTERS[lib]
|
28
27
|
end
|
29
28
|
|
@@ -8,13 +8,15 @@ Feature: Usage with Cucumber
|
|
8
8
|
|
9
9
|
In a cucumber support file (e.g. features/support/vcr.rb), put code like this:
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
``` ruby
|
12
|
+
VCR.cucumber_tags do |t|
|
13
|
+
t.tag '@tag1'
|
14
|
+
t.tags '@tag2', '@tag3'
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
t.tag '@tag3', :cassette => :options
|
17
|
+
t.tags '@tag4, '@tag5', :cassette => :options
|
18
|
+
end
|
19
|
+
```
|
18
20
|
|
19
21
|
VCR will use a cassette named "cucumber_tags/<tag_name>" for scenarios
|
20
22
|
with each of these tags. The configured `default_cassette_options` will
|
@@ -23,9 +25,7 @@ Feature: Usage with Cucumber
|
|
23
25
|
|
24
26
|
Scenario: Record HTTP interactions in a scenario by tagging it
|
25
27
|
Given a file named "lib/server.rb" with:
|
26
|
-
"""
|
27
|
-
require 'vcr_cucumber_helpers'
|
28
|
-
|
28
|
+
"""ruby
|
29
29
|
if ENV['WITH_SERVER'] == 'true'
|
30
30
|
start_sinatra_app(:port => 7777) do
|
31
31
|
get('/:path') { "Hello #{params[:path]}" }
|
@@ -34,14 +34,13 @@ Feature: Usage with Cucumber
|
|
34
34
|
"""
|
35
35
|
|
36
36
|
Given a file named "features/support/vcr.rb" with:
|
37
|
-
"""
|
37
|
+
"""ruby
|
38
38
|
require "lib/server"
|
39
39
|
require 'vcr'
|
40
40
|
|
41
|
-
VCR.
|
42
|
-
c.
|
41
|
+
VCR.configure do |c|
|
42
|
+
c.hook_into :fakeweb
|
43
43
|
c.cassette_library_dir = 'features/cassettes'
|
44
|
-
c.default_cassette_options = { :record => :new_episodes }
|
45
44
|
end
|
46
45
|
|
47
46
|
VCR.cucumber_tags do |t|
|
@@ -50,7 +49,7 @@ Feature: Usage with Cucumber
|
|
50
49
|
end
|
51
50
|
"""
|
52
51
|
And a file named "features/step_definitions/steps.rb" with:
|
53
|
-
"""
|
52
|
+
"""ruby
|
54
53
|
require 'net/http'
|
55
54
|
|
56
55
|
When /^a request is made to "([^"]*)"$/ do |url|
|
@@ -92,8 +91,8 @@ Feature: Usage with Cucumber
|
|
92
91
|
When I run `cucumber WITH_SERVER=true features/vcr_example.feature`
|
93
92
|
Then it should fail with "3 scenarios (2 failed, 1 passed)"
|
94
93
|
And the output should contain each of the following:
|
95
|
-
| Real HTTP connections are disabled.
|
96
|
-
| Real HTTP connections are disabled.
|
94
|
+
| Real HTTP connections are disabled. Request: GET http://localhost:7777/disallowed_1 |
|
95
|
+
| Real HTTP connections are disabled. Request: GET http://localhost:7777/disallowed_2 |
|
97
96
|
And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "body: Hello localhost_request_1"
|
98
97
|
And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "body: Hello localhost_request_2"
|
99
98
|
And the file "features/cassettes/nested_cassette.yml" should contain "body: Hello nested_cassette"
|
@@ -104,8 +103,8 @@ Feature: Usage with Cucumber
|
|
104
103
|
When I run `cucumber features/vcr_example.feature`
|
105
104
|
Then it should fail with "3 scenarios (2 failed, 1 passed)"
|
106
105
|
And the output should contain each of the following:
|
107
|
-
| Real HTTP connections are disabled.
|
108
|
-
| Real HTTP connections are disabled.
|
106
|
+
| Real HTTP connections are disabled. Request: GET http://localhost:7777/disallowed_1 |
|
107
|
+
| Real HTTP connections are disabled. Request: GET http://localhost:7777/disallowed_2 |
|
109
108
|
And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "body: Hello localhost_request_1"
|
110
109
|
And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "body: Hello localhost_request_2"
|
111
110
|
And the file "features/cassettes/nested_cassette.yml" should contain "body: Hello nested_cassette"
|
@@ -27,15 +27,13 @@ Feature: Usage with RSpec
|
|
27
27
|
| spec/cassettes/VCR-RSpec_integration/without_an_explicit_cassette_name.yml |
|
28
28
|
| spec/cassettes/net_http_example.yml |
|
29
29
|
And a file named "spec/sinatra_app.rb" with:
|
30
|
-
"""
|
31
|
-
require 'vcr_cucumber_helpers'
|
32
|
-
|
30
|
+
"""ruby
|
33
31
|
start_sinatra_app(:port => 7777) do
|
34
32
|
get('/') { "Hello" }
|
35
33
|
end
|
36
34
|
"""
|
37
35
|
And a file named "spec/vcr_example_spec.rb" with:
|
38
|
-
"""
|
36
|
+
"""ruby
|
39
37
|
require 'spec_helper'
|
40
38
|
|
41
39
|
describe "VCR-RSpec integration" do
|
@@ -63,14 +61,13 @@ Feature: Usage with RSpec
|
|
63
61
|
|
64
62
|
Scenario: Use `use_vcr_cassette` macro with RSpec 2
|
65
63
|
Given a file named "spec/spec_helper.rb" with:
|
66
|
-
"""
|
64
|
+
"""ruby
|
67
65
|
require 'sinatra_app'
|
68
66
|
require 'vcr'
|
69
67
|
|
70
|
-
VCR.
|
68
|
+
VCR.configure do |c|
|
71
69
|
c.cassette_library_dir = 'spec/cassettes'
|
72
|
-
c.
|
73
|
-
c.default_cassette_options = { :record => :new_episodes }
|
70
|
+
c.hook_into :fakeweb
|
74
71
|
end
|
75
72
|
|
76
73
|
RSpec.configure do |c|
|
@@ -84,7 +81,7 @@ Feature: Usage with RSpec
|
|
84
81
|
|
85
82
|
Scenario: Use `use_vcr_cassette` macro with RSpec 1
|
86
83
|
Given a file named "spec/spec_helper.rb" with:
|
87
|
-
"""
|
84
|
+
"""ruby
|
88
85
|
require 'sinatra_app'
|
89
86
|
$LOAD_PATH.unshift(File.join(%w[ .. .. vendor rspec-1 lib ]))
|
90
87
|
|
@@ -93,10 +90,9 @@ Feature: Usage with RSpec
|
|
93
90
|
|
94
91
|
require 'vcr'
|
95
92
|
|
96
|
-
VCR.
|
93
|
+
VCR.configure do |c|
|
97
94
|
c.cassette_library_dir = 'spec/cassettes'
|
98
|
-
c.
|
99
|
-
c.default_cassette_options = { :record => :new_episodes }
|
95
|
+
c.hook_into :fakeweb
|
100
96
|
end
|
101
97
|
|
102
98
|
Spec::Runner.configure do |c|
|