vcr 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +23 -0
- data/Gemfile +0 -2
- data/Gemfile.lock +15 -14
- data/Guardfile +2 -3
- data/LICENSE +1 -1
- data/README.md +5 -1
- data/features/.nav +28 -0
- data/features/README.md +1 -1
- data/features/cassettes/automatic_re_recording.feature +2 -2
- data/features/cassettes/format.feature +2 -2
- data/features/cassettes/no_cassette.feature +3 -3
- data/features/cassettes/request_matching.feature +8 -8
- data/features/configuration/allow_http_connections_when_no_cassette.feature +1 -1
- data/features/configuration/cassette_library_dir.feature +1 -1
- data/features/configuration/default_cassette_options.feature +2 -2
- data/features/configuration/hooks.feature +276 -0
- data/features/configuration/ignore_localhost.feature +1 -1
- data/features/configuration/stub_with.feature +19 -20
- data/features/middleware/rack.feature +6 -6
- data/features/{cassettes/record_modes → record_modes}/all.feature +2 -2
- data/features/{cassettes/record_modes → record_modes}/new_episodes.feature +3 -3
- data/features/{cassettes/record_modes → record_modes}/none.feature +4 -4
- data/features/support/vcr_cucumber_helpers.rb +1 -1
- data/features/test_frameworks/cucumber.feature +11 -11
- data/features/test_frameworks/rspec.feature +12 -12
- data/features/test_frameworks/shoulda.feature +1 -1
- data/lib/vcr.rb +8 -4
- data/lib/vcr/cassette.rb +28 -39
- data/lib/vcr/cassette/reader.rb +58 -0
- data/lib/vcr/config.rb +45 -40
- data/lib/vcr/deprecations.rb +1 -1
- data/lib/vcr/extensions/net_http.rb +6 -1
- data/lib/vcr/hooks.rb +45 -0
- data/lib/vcr/http_stubbing_adapters/common.rb +16 -13
- data/lib/vcr/http_stubbing_adapters/fakeweb.rb +4 -4
- data/lib/vcr/http_stubbing_adapters/faraday.rb +4 -4
- data/lib/vcr/http_stubbing_adapters/typhoeus.rb +4 -4
- data/lib/vcr/http_stubbing_adapters/webmock.rb +4 -4
- data/lib/vcr/structs.rb +8 -0
- data/lib/vcr/{basic_object.rb → util/basic_object.rb} +0 -0
- data/lib/vcr/{internet_connection.rb → util/internet_connection.rb} +1 -1
- data/lib/vcr/{ping.rb → util/ping.rb} +0 -0
- data/lib/vcr/version.rb +1 -1
- data/script/FullBuildRakeFile +6 -0
- data/script/full_build +1 -1
- data/script/spec +1 -0
- data/spec/fixtures/1.9.1/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/not_1.9.1/cassette_spec/empty.yml +0 -0
- data/spec/spec_helper.rb +7 -4
- data/spec/support/http_library_adapters.rb +8 -0
- data/spec/support/http_stubbing_adapter.rb +2 -2
- data/spec/vcr/cassette/reader_spec.rb +59 -0
- data/spec/{cassette_spec.rb → vcr/cassette_spec.rb} +115 -54
- data/spec/{config_spec.rb → vcr/config_spec.rb} +0 -0
- data/spec/{cucumber_tags_spec.rb → vcr/cucumber_tags_spec.rb} +0 -0
- data/spec/{deprecations_spec.rb → vcr/deprecations_spec.rb} +0 -0
- data/spec/{extensions → vcr/extensions}/net_http_response_spec.rb +0 -0
- data/spec/{extensions → vcr/extensions}/net_http_spec.rb +0 -0
- data/spec/vcr/hooks_spec.rb +95 -0
- data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/fakeweb_spec.rb +0 -0
- data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/faraday_spec.rb +5 -3
- data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/multi_object_proxy_spec.rb +0 -0
- data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/typhoeus_spec.rb +0 -0
- data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/webmock_spec.rb +0 -0
- data/spec/{middleware → vcr/middleware}/cassette_arguments_spec.rb +0 -0
- data/spec/{middleware → vcr/middleware}/faraday_spec.rb +0 -0
- data/spec/{middleware → vcr/middleware}/rack_spec.rb +0 -0
- data/spec/{request_matcher_spec.rb → vcr/request_matcher_spec.rb} +0 -0
- data/spec/{rspec_spec.rb → vcr/rspec_spec.rb} +0 -0
- data/spec/{structs_spec.rb → vcr/structs_spec.rb} +15 -4
- data/spec/{internet_connection_spec.rb → vcr/util/internet_connection_spec.rb} +0 -0
- data/spec/{version_spec.rb → vcr/version_spec.rb} +0 -0
- data/spec/vcr_spec.rb +10 -3
- data/vcr.gemspec +3 -3
- metadata +123 -101
- data/spec/fixtures/1.9.1/cassette_spec/erb_with_no_vars.yml +0 -32
- data/spec/fixtures/1.9.1/cassette_spec/erb_with_vars.yml +0 -32
- data/spec/fixtures/not_1.9.1/cassette_spec/erb_with_no_vars.yml +0 -32
- data/spec/fixtures/not_1.9.1/cassette_spec/erb_with_vars.yml +0 -32
@@ -1,37 +1,36 @@
|
|
1
|
-
Feature: stub_with
|
1
|
+
Feature: stub_with
|
2
2
|
|
3
3
|
The `stub_with` configuration option determines which HTTP stubbing library
|
4
4
|
VCR will use. There are currently 4 supported stubbing libraries which
|
5
5
|
support many different HTTP libraries:
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
- FakeWeb can be used to stub Net::HTTP.
|
8
|
+
- WebMock can be used to stub:
|
9
|
+
- Net::HTTP
|
10
|
+
- HTTPClient
|
11
|
+
- Patron
|
12
|
+
- Curb (Curb::Easy, but not Curb::Multi)
|
13
|
+
- EM HTTP Request
|
14
|
+
- Typhoeus can be used to stub itself (as long as you use Typhoeus::Hydra,
|
15
15
|
but not Typhoeus::Easy or Typhoeus::Multi).
|
16
|
-
|
16
|
+
- Faraday can be used (in combination with the provided Faraday middleware)
|
17
17
|
to stub requests made through Faraday (regardless of which Faraday HTTP
|
18
18
|
adapter is used).
|
19
19
|
|
20
20
|
There are some addiitonal trade offs to consider when deciding which
|
21
21
|
stubbing library to use:
|
22
22
|
|
23
|
-
|
23
|
+
- FakeWeb does not allow you to stub a request based on the headers or body.
|
24
24
|
Therefore, the `:match_requests_on` option does not support `:body` or
|
25
|
-
`:headers` when you use FakeWeb. Typhoeus and
|
26
|
-
matching on `:body` and `:headers`.
|
27
|
-
|
25
|
+
`:headers` when you use FakeWeb. Typhoeus, WebMock and Faraday both
|
26
|
+
support matching on `:body` and `:headers`.
|
27
|
+
- FakeWeb is currently about 4 times faster than WebMock for stubbing
|
28
28
|
Net::HTTP (see benchmarks/http_stubbing_libraries.rb for details).
|
29
|
-
|
30
|
-
supported HTTP libraries.
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
* Typhoeus and Faraday can be used together, and with either
|
29
|
+
- FakeWeb and WebMock both use extensive monkey patching to stub their
|
30
|
+
supported HTTP libraries. No monkey patching is used for Typhoeus or
|
31
|
+
Faraday.
|
32
|
+
- FakeWeb and WebMock cannot both be used at the same time.
|
33
|
+
- Typhoeus and Faraday can be used together, and with either
|
35
34
|
FakeWeb or WebMock.
|
36
35
|
|
37
36
|
Regardless of which library you use, VCR takes care of all of the configuration
|
@@ -1,17 +1,17 @@
|
|
1
|
-
Feature:
|
1
|
+
Feature: Rack
|
2
2
|
|
3
3
|
VCR provides a rack middleware that uses a cassette for the duration of
|
4
|
-
a request. Simply provide VCR::Middleware::Rack with a block that sets
|
4
|
+
a request. Simply provide `VCR::Middleware::Rack` with a block that sets
|
5
5
|
the cassette name and options. You can set these based on the rack env
|
6
6
|
if your block accepts two arguments.
|
7
7
|
|
8
|
-
|
8
|
+
This is useful in a couple different ways:
|
9
9
|
|
10
|
-
|
11
|
-
the rails app (using the
|
10
|
+
- In a rails app, you could use this to log all HTTP API calls made by
|
11
|
+
the rails app (using the `:all` record mode). Of course, this will only
|
12
12
|
record HTTP API calls made in the request-response cycle--API calls that
|
13
13
|
are offloaded to a background job will not be logged.
|
14
|
-
|
14
|
+
- This can be used as middleware in a simple rack HTTP proxy, to record
|
15
15
|
and replay the proxied requests.
|
16
16
|
|
17
17
|
Background:
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Feature: :new_episodes
|
1
|
+
Feature: :new_episodes
|
2
2
|
|
3
|
-
The
|
3
|
+
The `:new_episodes` record mode replays previously recorded
|
4
4
|
requests and records new ones.
|
5
5
|
|
6
6
|
Background:
|
@@ -46,7 +46,7 @@ Feature: :new_episodes record mode
|
|
46
46
|
"""
|
47
47
|
require 'setup'
|
48
48
|
|
49
|
-
VCR.use_cassette('example', :record => :
|
49
|
+
VCR.use_cassette('example', :record => :new_episodes) do
|
50
50
|
response = Net::HTTP.get_response('example.com', '/foo')
|
51
51
|
puts "Response: #{response.body}"
|
52
52
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
Feature: :none
|
1
|
+
Feature: :none
|
2
2
|
|
3
|
-
The
|
3
|
+
The `:none` record mode allows previously recorded responses
|
4
4
|
to be replayed, but raises an error for any new requests.
|
5
5
|
|
6
|
-
This is useful when
|
7
|
-
HTTP requests. The
|
6
|
+
This is useful when your code makes potentially dangerous
|
7
|
+
HTTP requests. The `:none` record mode guarantees that no
|
8
8
|
new HTTP requests will be made.
|
9
9
|
|
10
10
|
Background:
|
@@ -7,7 +7,7 @@ RUNNING_UNDER_ARUBA = File.dirname(__FILE__) == '.' || File.dirname(__FILE__) =~
|
|
7
7
|
|
8
8
|
if RUNNING_UNDER_ARUBA
|
9
9
|
require 'support/fixnum_extension'
|
10
|
-
require 'vcr/internet_connection'
|
10
|
+
require 'vcr/util/internet_connection'
|
11
11
|
|
12
12
|
# pretend we're always on the internet (so that we don't have an
|
13
13
|
# internet connection dependency for our cukes)
|
@@ -1,25 +1,25 @@
|
|
1
|
-
Feature: Usage with
|
1
|
+
Feature: Usage with Cucumber
|
2
2
|
|
3
3
|
VCR can be used with cucumber in two basic ways:
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
- Use `VCR.use_cassette` in a step definition.
|
6
|
+
- Use a `VCR.cucumber_tags` block to tell VCR to use a
|
7
7
|
cassette for a tagged scenario.
|
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
|
+
VCR.cucumber_tags do |t|
|
12
|
+
t.tag '@tag1'
|
13
|
+
t.tags '@tag2', '@tag3'
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
t.tag '@tag3', :cassette => :options
|
16
|
+
t.tags '@tag4, '@tag5', :cassette => :options
|
17
|
+
end
|
18
18
|
|
19
19
|
VCR will use a cassette named "cucumber_tags/<tag_name>" for scenarios
|
20
|
-
with each of these tags. The configured default_cassette_options will
|
20
|
+
with each of these tags. The configured `default_cassette_options` will
|
21
21
|
be used, or you can override specific options by passing a hash as the
|
22
|
-
last argument to
|
22
|
+
last argument to `#tag` or `#tags`.
|
23
23
|
|
24
24
|
Scenario: Record HTTP interactions in a scenario by tagging it
|
25
25
|
Given a file named "features/support/vcr.rb" with:
|
@@ -7,20 +7,20 @@ Feature: Usage with RSpec
|
|
7
7
|
In any example group, add a `use_vcr_cassette` declaration to use a cassette
|
8
8
|
for that example group. You can use this in a few different ways:
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
- `use_vcr_cassette`
|
11
|
+
- Infers a cassette name from the example group description (and parent
|
12
12
|
example group descriptions).
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
- Uses the `default_cassette_options` you have configured.
|
14
|
+
- `use_vcr_cassette "Cassette Name"`
|
15
|
+
- Uses the given cassette name.
|
16
|
+
- Uses the `default_cassette_options` you have configured.
|
17
|
+
- `use_vcr_cassette :cassette => :options`
|
18
|
+
- Infers a cassette name from the example group description (and parent
|
19
19
|
example group descriptions).
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
- Uses the provided cassette options (merged with the defaults).
|
21
|
+
- `use_vcr_cassette "Cassette Name", :cassette => :options`
|
22
|
+
- Uses the given cassette name.
|
23
|
+
- Uses the provided cassette options (merged with the defaults).
|
24
24
|
|
25
25
|
Background:
|
26
26
|
Given the following files do not exist:
|
data/lib/vcr.rb
CHANGED
@@ -9,9 +9,9 @@ require 'vcr/http_stubbing_adapters/common'
|
|
9
9
|
module VCR
|
10
10
|
extend self
|
11
11
|
|
12
|
-
autoload :BasicObject, 'vcr/basic_object'
|
12
|
+
autoload :BasicObject, 'vcr/util/basic_object'
|
13
13
|
autoload :CucumberTags, 'vcr/cucumber_tags'
|
14
|
-
autoload :InternetConnection, 'vcr/internet_connection'
|
14
|
+
autoload :InternetConnection, 'vcr/util/internet_connection'
|
15
15
|
autoload :RSpec, 'vcr/rspec'
|
16
16
|
|
17
17
|
LOCALHOST_ALIASES = %w( localhost 127.0.0.1 0.0.0.0 )
|
@@ -30,12 +30,16 @@ module VCR
|
|
30
30
|
cassettes.last
|
31
31
|
end
|
32
32
|
|
33
|
-
def insert_cassette(
|
33
|
+
def insert_cassette(name, options = {})
|
34
34
|
unless turned_on?
|
35
35
|
raise TurnedOffError.new("VCR is turned off. You must turn it on before you can insert a cassette.")
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
if cassettes.any? { |c| c.name == name }
|
39
|
+
raise ArgumentError.new("There is already a cassette with the same name (#{name}). You cannot nest multiple cassettes with the same name.")
|
40
|
+
end
|
41
|
+
|
42
|
+
cassette = Cassette.new(name, options)
|
39
43
|
cassettes.push(cassette)
|
40
44
|
cassette
|
41
45
|
end
|
data/lib/vcr/cassette.rb
CHANGED
@@ -3,17 +3,17 @@ require 'yaml'
|
|
3
3
|
require 'erb'
|
4
4
|
require 'set'
|
5
5
|
|
6
|
+
require 'vcr/cassette/reader'
|
7
|
+
|
6
8
|
module VCR
|
7
9
|
class Cassette
|
8
|
-
class MissingERBVariableError < NameError; end
|
9
|
-
|
10
10
|
VALID_RECORD_MODES = [:all, :none, :new_episodes]
|
11
11
|
|
12
|
-
attr_reader :name, :record_mode, :match_requests_on, :erb, :re_record_interval
|
12
|
+
attr_reader :name, :record_mode, :match_requests_on, :erb, :re_record_interval, :tag
|
13
13
|
|
14
14
|
def initialize(name, options = {})
|
15
15
|
options = VCR::Config.default_cassette_options.merge(options)
|
16
|
-
invalid_options = options.keys - [:record, :erb, :allow_real_http, :match_requests_on, :re_record_interval]
|
16
|
+
invalid_options = options.keys - [:record, :erb, :allow_real_http, :match_requests_on, :re_record_interval, :tag]
|
17
17
|
|
18
18
|
if invalid_options.size > 0
|
19
19
|
raise ArgumentError.new("You passed the following invalid options to VCR::Cassette.new: #{invalid_options.inspect}.")
|
@@ -24,10 +24,11 @@ module VCR
|
|
24
24
|
@erb = options[:erb]
|
25
25
|
@match_requests_on = options[:match_requests_on]
|
26
26
|
@re_record_interval = options[:re_record_interval]
|
27
|
+
@tag = options[:tag]
|
27
28
|
@record_mode = :all if should_re_record?
|
28
29
|
|
29
30
|
deprecate_old_cassette_options(options)
|
30
|
-
raise_error_unless_valid_record_mode
|
31
|
+
raise_error_unless_valid_record_mode
|
31
32
|
|
32
33
|
set_http_connections_allowed
|
33
34
|
load_recorded_interactions
|
@@ -35,7 +36,7 @@ module VCR
|
|
35
36
|
|
36
37
|
def eject
|
37
38
|
write_recorded_interactions_to_disk
|
38
|
-
VCR.http_stubbing_adapter.restore_stubs_checkpoint(
|
39
|
+
VCR.http_stubbing_adapter.restore_stubs_checkpoint(self)
|
39
40
|
restore_http_connections_allowed
|
40
41
|
restore_ignore_localhost_for_deprecation
|
41
42
|
end
|
@@ -62,7 +63,7 @@ module VCR
|
|
62
63
|
name.to_s.gsub(/[^\w\-\/]+/, '_')
|
63
64
|
end
|
64
65
|
|
65
|
-
def raise_error_unless_valid_record_mode
|
66
|
+
def raise_error_unless_valid_record_mode
|
66
67
|
unless VALID_RECORD_MODES.include?(record_mode)
|
67
68
|
raise ArgumentError.new("#{record_mode} is not a valid cassette record mode. Valid options are: #{VALID_RECORD_MODES.inspect}")
|
68
69
|
end
|
@@ -97,11 +98,11 @@ module VCR
|
|
97
98
|
end
|
98
99
|
|
99
100
|
def load_recorded_interactions
|
100
|
-
VCR.http_stubbing_adapter.create_stubs_checkpoint(
|
101
|
-
|
102
|
-
if file && File.exist?(file)
|
101
|
+
VCR.http_stubbing_adapter.create_stubs_checkpoint(self)
|
102
|
+
if file && File.size?(file)
|
103
103
|
begin
|
104
104
|
interactions = YAML.load(raw_yaml_content)
|
105
|
+
invoke_hook(:before_playback, interactions)
|
105
106
|
|
106
107
|
if VCR.http_stubbing_adapter.ignore_localhost?
|
107
108
|
interactions.reject! do |i|
|
@@ -121,32 +122,8 @@ module VCR
|
|
121
122
|
end
|
122
123
|
end
|
123
124
|
|
124
|
-
@@struct_cache = Hash.new do |hash, attributes|
|
125
|
-
hash[attributes] = Struct.new(*attributes)
|
126
|
-
end
|
127
|
-
|
128
125
|
def raw_yaml_content
|
129
|
-
|
130
|
-
return content unless @erb
|
131
|
-
|
132
|
-
template = ERB.new(content)
|
133
|
-
|
134
|
-
begin
|
135
|
-
return template.result unless @erb.is_a?(Hash)
|
136
|
-
|
137
|
-
# create an object with methods for each desired local variable...
|
138
|
-
local_variables = @@struct_cache[@erb.keys].new(*@erb.values)
|
139
|
-
|
140
|
-
# instance_eval seems to be the only way to get the binding for ruby 1.9: http://redmine.ruby-lang.org/issues/show/2161
|
141
|
-
template.result(local_variables.instance_eval { binding })
|
142
|
-
rescue NameError => e
|
143
|
-
example_hash = (@erb.is_a?(Hash) ? @erb : {}).merge(e.name => 'some value')
|
144
|
-
|
145
|
-
raise MissingERBVariableError.new(
|
146
|
-
"The ERB in the #{sanitized_name}.yml cassette file references undefined variable #{e.name}. " +
|
147
|
-
"Pass it to the cassette using :erb => #{ example_hash.inspect }."
|
148
|
-
)
|
149
|
-
end
|
126
|
+
VCR::Cassette::Reader.new(file, erb).read
|
150
127
|
end
|
151
128
|
|
152
129
|
def merged_interactions
|
@@ -168,10 +145,22 @@ module VCR
|
|
168
145
|
end
|
169
146
|
|
170
147
|
def write_recorded_interactions_to_disk
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
148
|
+
return unless VCR::Config.cassette_library_dir
|
149
|
+
return if new_recorded_interactions.empty?
|
150
|
+
|
151
|
+
interactions = merged_interactions
|
152
|
+
invoke_hook(:before_record, interactions)
|
153
|
+
return if interactions.empty?
|
154
|
+
|
155
|
+
directory = File.dirname(file)
|
156
|
+
FileUtils.mkdir_p directory unless File.exist?(directory)
|
157
|
+
File.open(file, 'w') { |f| f.write interactions.to_yaml }
|
158
|
+
end
|
159
|
+
|
160
|
+
def invoke_hook(type, interactions)
|
161
|
+
interactions.delete_if do |i|
|
162
|
+
VCR::Config.invoke_hook(type, tag, i, self)
|
163
|
+
i.ignored?
|
175
164
|
end
|
176
165
|
end
|
177
166
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module VCR
|
2
|
+
class Cassette
|
3
|
+
class MissingERBVariableError < NameError; end
|
4
|
+
|
5
|
+
class Reader
|
6
|
+
def initialize(file_name, erb)
|
7
|
+
@file_name, @erb = file_name, erb
|
8
|
+
end
|
9
|
+
|
10
|
+
def read
|
11
|
+
return file_content unless use_erb?
|
12
|
+
binding = binding_for_variables if erb_variables
|
13
|
+
template.result(binding)
|
14
|
+
rescue NameError => e
|
15
|
+
handle_name_error(e)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def handle_name_error(e)
|
21
|
+
example_hash = (erb_variables || {}).merge(e.name => 'some value')
|
22
|
+
|
23
|
+
raise MissingERBVariableError.new(
|
24
|
+
"The ERB in the #{@file_name} cassette file references undefined variable #{e.name}. " +
|
25
|
+
"Pass it to the cassette using :erb => #{ example_hash.inspect }."
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def use_erb?
|
30
|
+
!!@erb
|
31
|
+
end
|
32
|
+
|
33
|
+
def erb_variables
|
34
|
+
@erb if @erb.is_a?(Hash)
|
35
|
+
end
|
36
|
+
|
37
|
+
def file_content
|
38
|
+
@file_content ||= File.read(@file_name)
|
39
|
+
end
|
40
|
+
|
41
|
+
def template
|
42
|
+
@template ||= ERB.new(file_content)
|
43
|
+
end
|
44
|
+
|
45
|
+
@@struct_cache = Hash.new do |hash, attributes|
|
46
|
+
hash[attributes] = Struct.new(*attributes)
|
47
|
+
end
|
48
|
+
|
49
|
+
def variables_object
|
50
|
+
@variables_object ||= @@struct_cache[erb_variables.keys].new(*erb_variables.values)
|
51
|
+
end
|
52
|
+
|
53
|
+
def binding_for_variables
|
54
|
+
@binding_for_variables ||= variables_object.instance_eval { binding }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/vcr/config.rb
CHANGED
@@ -1,46 +1,51 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'vcr/hooks'
|
2
3
|
|
3
4
|
module VCR
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
5
|
+
module Config
|
6
|
+
include VCR::Hooks
|
7
|
+
extend self
|
8
|
+
|
9
|
+
define_hook :before_record
|
10
|
+
define_hook :before_playback
|
11
|
+
|
12
|
+
attr_reader :cassette_library_dir
|
13
|
+
def cassette_library_dir=(cassette_library_dir)
|
14
|
+
@cassette_library_dir = cassette_library_dir
|
15
|
+
FileUtils.mkdir_p(cassette_library_dir) if cassette_library_dir
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_writer :default_cassette_options
|
19
|
+
def default_cassette_options
|
20
|
+
@default_cassette_options ||= {}
|
21
|
+
@default_cassette_options.merge!(:match_requests_on => RequestMatcher::DEFAULT_MATCH_ATTRIBUTES) unless @default_cassette_options.has_key?(:match_requests_on)
|
22
|
+
@default_cassette_options
|
23
|
+
end
|
24
|
+
|
25
|
+
def stub_with(*http_stubbing_libraries)
|
26
|
+
@http_stubbing_libraries = http_stubbing_libraries
|
27
|
+
end
|
28
|
+
|
29
|
+
def http_stubbing_libraries
|
30
|
+
@http_stubbing_libraries ||= []
|
31
|
+
end
|
32
|
+
|
33
|
+
def ignore_localhost=(value)
|
34
|
+
@ignore_localhost = value
|
35
|
+
VCR.http_stubbing_adapter.ignore_localhost = value if http_stubbing_libraries.any?
|
36
|
+
end
|
37
|
+
|
38
|
+
def ignore_localhost?
|
39
|
+
@ignore_localhost
|
40
|
+
end
|
41
|
+
|
42
|
+
def allow_http_connections_when_no_cassette=(value)
|
43
|
+
@allow_http_connections_when_no_cassette = value
|
44
|
+
VCR.http_stubbing_adapter.set_http_connections_allowed_to_default if http_stubbing_libraries.any?
|
45
|
+
end
|
46
|
+
|
47
|
+
def allow_http_connections_when_no_cassette?
|
48
|
+
!!@allow_http_connections_when_no_cassette
|
44
49
|
end
|
45
50
|
end
|
46
51
|
end
|