vcr 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/CHANGELOG.md +23 -0
  2. data/Gemfile +0 -2
  3. data/Gemfile.lock +15 -14
  4. data/Guardfile +2 -3
  5. data/LICENSE +1 -1
  6. data/README.md +5 -1
  7. data/features/.nav +28 -0
  8. data/features/README.md +1 -1
  9. data/features/cassettes/automatic_re_recording.feature +2 -2
  10. data/features/cassettes/format.feature +2 -2
  11. data/features/cassettes/no_cassette.feature +3 -3
  12. data/features/cassettes/request_matching.feature +8 -8
  13. data/features/configuration/allow_http_connections_when_no_cassette.feature +1 -1
  14. data/features/configuration/cassette_library_dir.feature +1 -1
  15. data/features/configuration/default_cassette_options.feature +2 -2
  16. data/features/configuration/hooks.feature +276 -0
  17. data/features/configuration/ignore_localhost.feature +1 -1
  18. data/features/configuration/stub_with.feature +19 -20
  19. data/features/middleware/rack.feature +6 -6
  20. data/features/{cassettes/record_modes → record_modes}/all.feature +2 -2
  21. data/features/{cassettes/record_modes → record_modes}/new_episodes.feature +3 -3
  22. data/features/{cassettes/record_modes → record_modes}/none.feature +4 -4
  23. data/features/support/vcr_cucumber_helpers.rb +1 -1
  24. data/features/test_frameworks/cucumber.feature +11 -11
  25. data/features/test_frameworks/rspec.feature +12 -12
  26. data/features/test_frameworks/shoulda.feature +1 -1
  27. data/lib/vcr.rb +8 -4
  28. data/lib/vcr/cassette.rb +28 -39
  29. data/lib/vcr/cassette/reader.rb +58 -0
  30. data/lib/vcr/config.rb +45 -40
  31. data/lib/vcr/deprecations.rb +1 -1
  32. data/lib/vcr/extensions/net_http.rb +6 -1
  33. data/lib/vcr/hooks.rb +45 -0
  34. data/lib/vcr/http_stubbing_adapters/common.rb +16 -13
  35. data/lib/vcr/http_stubbing_adapters/fakeweb.rb +4 -4
  36. data/lib/vcr/http_stubbing_adapters/faraday.rb +4 -4
  37. data/lib/vcr/http_stubbing_adapters/typhoeus.rb +4 -4
  38. data/lib/vcr/http_stubbing_adapters/webmock.rb +4 -4
  39. data/lib/vcr/structs.rb +8 -0
  40. data/lib/vcr/{basic_object.rb → util/basic_object.rb} +0 -0
  41. data/lib/vcr/{internet_connection.rb → util/internet_connection.rb} +1 -1
  42. data/lib/vcr/{ping.rb → util/ping.rb} +0 -0
  43. data/lib/vcr/version.rb +1 -1
  44. data/script/FullBuildRakeFile +6 -0
  45. data/script/full_build +1 -1
  46. data/script/spec +1 -0
  47. data/spec/fixtures/1.9.1/cassette_spec/empty.yml +0 -0
  48. data/spec/fixtures/not_1.9.1/cassette_spec/empty.yml +0 -0
  49. data/spec/spec_helper.rb +7 -4
  50. data/spec/support/http_library_adapters.rb +8 -0
  51. data/spec/support/http_stubbing_adapter.rb +2 -2
  52. data/spec/vcr/cassette/reader_spec.rb +59 -0
  53. data/spec/{cassette_spec.rb → vcr/cassette_spec.rb} +115 -54
  54. data/spec/{config_spec.rb → vcr/config_spec.rb} +0 -0
  55. data/spec/{cucumber_tags_spec.rb → vcr/cucumber_tags_spec.rb} +0 -0
  56. data/spec/{deprecations_spec.rb → vcr/deprecations_spec.rb} +0 -0
  57. data/spec/{extensions → vcr/extensions}/net_http_response_spec.rb +0 -0
  58. data/spec/{extensions → vcr/extensions}/net_http_spec.rb +0 -0
  59. data/spec/vcr/hooks_spec.rb +95 -0
  60. data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/fakeweb_spec.rb +0 -0
  61. data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/faraday_spec.rb +5 -3
  62. data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/multi_object_proxy_spec.rb +0 -0
  63. data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/typhoeus_spec.rb +0 -0
  64. data/spec/{http_stubbing_adapters → vcr/http_stubbing_adapters}/webmock_spec.rb +0 -0
  65. data/spec/{middleware → vcr/middleware}/cassette_arguments_spec.rb +0 -0
  66. data/spec/{middleware → vcr/middleware}/faraday_spec.rb +0 -0
  67. data/spec/{middleware → vcr/middleware}/rack_spec.rb +0 -0
  68. data/spec/{request_matcher_spec.rb → vcr/request_matcher_spec.rb} +0 -0
  69. data/spec/{rspec_spec.rb → vcr/rspec_spec.rb} +0 -0
  70. data/spec/{structs_spec.rb → vcr/structs_spec.rb} +15 -4
  71. data/spec/{internet_connection_spec.rb → vcr/util/internet_connection_spec.rb} +0 -0
  72. data/spec/{version_spec.rb → vcr/version_spec.rb} +0 -0
  73. data/spec/vcr_spec.rb +10 -3
  74. data/vcr.gemspec +3 -3
  75. metadata +123 -101
  76. data/spec/fixtures/1.9.1/cassette_spec/erb_with_no_vars.yml +0 -32
  77. data/spec/fixtures/1.9.1/cassette_spec/erb_with_vars.yml +0 -32
  78. data/spec/fixtures/not_1.9.1/cassette_spec/erb_with_no_vars.yml +0 -32
  79. data/spec/fixtures/not_1.9.1/cassette_spec/erb_with_vars.yml +0 -32
@@ -1,4 +1,4 @@
1
- Feature: ignore_localhost configuration option
1
+ Feature: ignore_localhost
2
2
 
3
3
  The `ignore_localhost` configuration option can be used to prevent VCR
4
4
  from having any affect on localhost requests. If set to true, it will
@@ -1,37 +1,36 @@
1
- Feature: stub_with configuration option
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
- * 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,
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
- * Faraday can be used (in combination with the provided Faraday middleware)
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
- * FakeWeb does not allow you to stub a request based on the headers or body.
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 WebMock both support
26
- matching on `:body` and `:headers`.
27
- * FakeWeb is currently about 4 times faster than WebMock for stubbing
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
- * FakeWeb and WebMock both use extensive monkey patching to stub their
30
- supported HTTP libraries. Typhoeus provides all the necessary
31
- stubbing and recording integration points, and no monkey patching
32
- is required at all.
33
- * FakeWeb and WebMock cannot both be used at the same time.
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: rack middleware
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
- There useful in a couple different ways:
8
+ This is useful in a couple different ways:
9
9
 
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
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
- * This can be used as middleware in a simple rack HTTP proxy, to record the
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: :all record mode
1
+ Feature: :all
2
2
 
3
- The :all record mode records all requests and does not
3
+ The `:all` record mode records all requests and does not
4
4
  replay any previously recorded responds.
5
5
 
6
6
  This can be temporarily used to force VCR to re-record
@@ -1,6 +1,6 @@
1
- Feature: :new_episodes record mode
1
+ Feature: :new_episodes
2
2
 
3
- The :new_episodes record mode replays previously recorded
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 => :none) do
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 record mode
1
+ Feature: :none
2
2
 
3
- The :none record mode allows previously recorded responses
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 you code makes potentially dangerous
7
- HTTP requests. The :none record mode guarantees that no
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 cucumber
1
+ Feature: Usage with Cucumber
2
2
 
3
3
  VCR can be used with cucumber in two basic ways:
4
4
 
5
- * Use `VCR.use_cassette` in a step definition.
6
- * Use a `VCR.cucumber_tags` block to tell VCR to use a
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
- VCR.cucumber_tags do |t|
12
- t.tag '@tag1'
13
- t.tags '@tag2', '@tag3'
11
+ VCR.cucumber_tags do |t|
12
+ t.tag '@tag1'
13
+ t.tags '@tag2', '@tag3'
14
14
 
15
- t.tag '@tag3', :cassette => :options
16
- t.tags '@tag4, '@tag5', :cassette => :options
17
- end
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 #tag or #tags.
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
- * use_vcr_cassette
11
- * Infers a cassette name from the example group description (and parent
10
+ - `use_vcr_cassette`
11
+ - Infers a cassette name from the example group description (and parent
12
12
  example group descriptions).
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
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
- * 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).
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:
@@ -1,4 +1,4 @@
1
- Feature: Usage with shoulda
1
+ Feature: Usage with Shoulda
2
2
 
3
3
  When using a test framework that provides setup and teardown hooks
4
4
  (such as shoulda), you can use `VCR.insert_cassette` and
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(*args)
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
- cassette = Cassette.new(*args)
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(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(name)
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(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(name)
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
- content = File.read(file)
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
- if VCR::Config.cassette_library_dir && new_recorded_interactions.size > 0
172
- directory = File.dirname(file)
173
- FileUtils.mkdir_p directory unless File.exist?(directory)
174
- File.open(file, 'w') { |f| f.write merged_interactions.to_yaml }
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
- class Config
5
- class << self
6
- attr_reader :cassette_library_dir
7
- def cassette_library_dir=(cassette_library_dir)
8
- @cassette_library_dir = cassette_library_dir
9
- FileUtils.mkdir_p(cassette_library_dir) if cassette_library_dir
10
- end
11
-
12
- attr_writer :default_cassette_options
13
- def default_cassette_options
14
- @default_cassette_options ||= {}
15
- @default_cassette_options.merge!(:match_requests_on => RequestMatcher::DEFAULT_MATCH_ATTRIBUTES) unless @default_cassette_options.has_key?(:match_requests_on)
16
- @default_cassette_options
17
- end
18
-
19
- def stub_with(*http_stubbing_libraries)
20
- @http_stubbing_libraries = http_stubbing_libraries
21
- end
22
-
23
- def http_stubbing_libraries
24
- @http_stubbing_libraries ||= []
25
- end
26
-
27
- def ignore_localhost=(value)
28
- @ignore_localhost = value
29
- VCR.http_stubbing_adapter.ignore_localhost = value if http_stubbing_libraries.any?
30
- end
31
-
32
- def ignore_localhost?
33
- @ignore_localhost
34
- end
35
-
36
- def allow_http_connections_when_no_cassette=(value)
37
- @allow_http_connections_when_no_cassette = value
38
- VCR.http_stubbing_adapter.set_http_connections_allowed_to_default if http_stubbing_libraries.any?
39
- end
40
-
41
- def allow_http_connections_when_no_cassette?
42
- !!@allow_http_connections_when_no_cassette
43
- end
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