Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deprecate `VCR::Config` in favor of `VCR.configuration` and `VCR.conf…

…ig` in favor of `VCR.configure`.

- "config" is ambiguous--is it short for "configure" (the verb) or "configuration" (the noun)?
- I like this new way since it's more inline with other ruby libraries like RSpec.
- The old singleton module made isolated tests hard as there was a lot of global state to cleanup between tests.  Now there is just one piece of state: the VCR::Configuration instance held by VCR.configuration.  This makes it far easier to keep my tests isolated.
  • Loading branch information...
commit e36ed0e812b3a1650090d011d1bf972ae503ad79 1 parent 5905942
@myronmarston authored
Showing with 260 additions and 197 deletions.
  1. +4 −0 CHANGELOG.md
  2. +1 −1  features/cassettes/automatic_re_recording.feature
  3. +2 −2 features/cassettes/dynamic_erb.feature
  4. +1 −1  features/cassettes/format.feature
  5. +1 −1  features/cassettes/naming.feature
  6. +4 −4 features/cassettes/no_cassette.feature
  7. +5 −5 features/cassettes/request_matching.feature
  8. +1 −1  features/cassettes/update_content_length_header.feature
  9. +1 −1  features/configuration/allow_http_connections_when_no_cassette.feature
  10. +1 −1  features/configuration/cassette_library_dir.feature
  11. +2 −2 features/configuration/default_cassette_options.feature
  12. +3 −3 features/configuration/filter_sensitive_data.feature
  13. +8 −8 features/configuration/hooks.feature
  14. +1 −1  features/configuration/ignore_hosts.feature
  15. +2 −2 features/configuration/ignore_localhost.feature
  16. +2 −2 features/configuration/stub_with.feature
  17. +1 −1  features/http_libraries/em_http_request.feature
  18. +5 −5 features/http_libraries/net_http.feature
  19. +1 −1  features/middleware/faraday.feature
  20. +2 −2 features/middleware/rack.feature
  21. +1 −1  features/record_modes/all.feature
  22. +1 −1  features/record_modes/new_episodes.feature
  23. +1 −1  features/record_modes/none.feature
  24. +1 −1  features/record_modes/once.feature
  25. +1 −1  features/test_frameworks/cucumber.feature
  26. +2 −2 features/test_frameworks/rspec.feature
  27. +1 −1  features/test_frameworks/shoulda.feature
  28. +1 −1  features/test_frameworks/test_unit.feature
  29. +13 −7 lib/vcr.rb
  30. +6 −6 lib/vcr/cassette.rb
  31. +5 −8 lib/vcr/{config.rb → configuration.rb}
  32. +12 −0 lib/vcr/deprecations/vcr.rb
  33. +1 −1  lib/vcr/http_stubbing_adapters/common.rb
  34. +19 −13 lib/vcr/util/hooks.rb
  35. +5 −21 spec/spec_helper.rb
  36. +2 −2 spec/support/shared_example_groups/http_stubbing_adapter.rb
  37. +6 −6 spec/support/shared_example_groups/ignore_localhost_deprecation.rb
  38. +32 −30 spec/vcr/cassette_spec.rb
  39. +34 −34 spec/vcr/{config_spec.rb → configuration_spec.rb}
  40. +42 −0 spec/vcr/deprecations/vcr_spec.rb
  41. +26 −16 spec/vcr_spec.rb
View
4 CHANGELOG.md
@@ -4,6 +4,10 @@
* Removed support for Ruby 1.8.6 and 1.9.1.
* Removed lots of old deprecated APIs.
+* Deprecated `VCR.config` in favor of `VCR.configure`.
+* Deprecated `VCR::Config` singleton module in favor of
+ `VCR::Configuration` class. The current configuration instance
+ can be accessed via `VCR.configuration`.
## 1.11.3 (August 31, 2011)
View
2  features/cassettes/automatic_re_recording.feature
@@ -40,7 +40,7 @@ Feature: Automatic Re-recording
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
end
View
4 features/cassettes/dynamic_erb.feature
@@ -35,7 +35,7 @@ Feature: Dynamic ERB cassettes
"""ruby
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
end
@@ -74,7 +74,7 @@ Feature: Dynamic ERB cassettes
"""ruby
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
end
View
2  features/cassettes/format.feature
@@ -30,7 +30,7 @@ Feature: Cassette format
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with <stub_with>
c.cassette_library_dir = 'cassettes'
end
View
2  features/cassettes/naming.feature
@@ -15,7 +15,7 @@ Feature: Naming
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.cassette_library_dir = 'cassettes'
c.stub_with :fakeweb
end
View
8 features/cassettes/no_cassette.feature
@@ -27,7 +27,7 @@ Feature: Error for HTTP request made when no cassette is in use
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with <stub_with>
c.cassette_library_dir = 'cassettes'
end
@@ -62,7 +62,7 @@ Feature: Error for HTTP request made when no cassette is in use
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
end
@@ -112,7 +112,7 @@ Feature: Error for HTTP request made when no cassette is in use
"""ruby
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
end
@@ -133,7 +133,7 @@ Feature: Error for HTTP request made when no cassette is in use
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.cassette_library_dir = 'cassettes'
c.stub_with :fakeweb
end
View
10 features/cassettes/request_matching.feature
@@ -69,7 +69,7 @@ Feature: Request matching
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with <stub_with>
c.cassette_library_dir = 'cassettes'
end
@@ -139,7 +139,7 @@ Feature: Request matching
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with <stub_with>
c.cassette_library_dir = 'cassettes'
end
@@ -213,7 +213,7 @@ Feature: Request matching
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with <stub_with>
c.cassette_library_dir = 'cassettes'
end
@@ -286,7 +286,7 @@ Feature: Request matching
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with <stub_with>
c.cassette_library_dir = 'cassettes'
end
@@ -355,7 +355,7 @@ Feature: Request matching
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with <stub_with>
c.cassette_library_dir = 'cassettes'
end
View
2  features/cassettes/update_content_length_header.feature
@@ -44,7 +44,7 @@ Feature: Update content_length header
"""ruby
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.cassette_library_dir = 'cassettes'
c.stub_with :fakeweb
end
View
2  features/configuration/allow_http_connections_when_no_cassette.feature
@@ -18,7 +18,7 @@ Feature: Allow HTTP connections when no cassette
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.allow_http_connections_when_no_cassette = true
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
View
2  features/configuration/cassette_library_dir.feature
@@ -14,7 +14,7 @@ Feature: cassette_library_dir
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.cassette_library_dir = 'vcr/cassettes'
c.stub_with :fakeweb
end
View
4 features/configuration/default_cassette_options.feature
@@ -14,7 +14,7 @@ Feature: default_cassette_options
"""ruby
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.default_cassette_options = { :record => :new_episodes, :erb => true }
# not important for this example, but must be set to something
@@ -57,7 +57,7 @@ Feature: default_cassette_options
"""ruby
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
# not important for this example, but must be set to something
c.stub_with :webmock
c.cassette_library_dir = 'cassettes'
View
6 features/configuration/filter_sensitive_data.feature
@@ -36,7 +36,7 @@ Feature: Filter sensitive data
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
c.filter_sensitive_data('<GREETING>') { 'Hello' }
@@ -71,7 +71,7 @@ Feature: Filter sensitive data
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
c.filter_sensitive_data('<LOCATION>', :my_tag) { 'World' }
@@ -125,7 +125,7 @@ Feature: Filter sensitive data
'jane.doe' => 'cheetah'
}
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :webmock
c.cassette_library_dir = 'cassettes'
c.filter_sensitive_data('<PASSWORD>') do |interaction|
View
16 features/configuration/hooks.feature
@@ -7,7 +7,7 @@ Feature: Hooks
- `before_playback`: Called before a cassette sets up its stubs for playback.
To use these, call `config.before_record` or `config.before_playback` in
- your `VCR.config` block. Provide a block that accepts 0, 1 or 2 arguments.
+ your `VCR.configure` block. Provide a block that accepts 0, 1 or 2 arguments.
The first argument, if the block accepts it, will be an HTTP interaction.
Changes you make to the interaction will be reflected in the recording or
@@ -22,7 +22,7 @@ Feature: Hooks
You can also use tagging to apply hooks to particular cassettes. Consider
this code:
- VCR.config do |c|
+ VCR.configure do |c|
c.before_record(:twitter) { ... } # modify the interactions somehow
end
@@ -69,7 +69,7 @@ Feature: Hooks
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
@@ -98,7 +98,7 @@ Feature: Hooks
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
c.before_record { |i| i.ignore! }
@@ -118,7 +118,7 @@ Feature: Hooks
"""ruby
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
@@ -167,7 +167,7 @@ Feature: Hooks
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
c.before_playback { |i| i.ignore! }
@@ -192,7 +192,7 @@ Feature: Hooks
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
@@ -233,7 +233,7 @@ Feature: Hooks
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
View
2  features/configuration/ignore_hosts.feature
@@ -29,7 +29,7 @@ Feature: ignore_hosts
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.ignore_hosts '127.0.0.1', 'localhost'
c.cassette_library_dir = 'cassettes'
c.stub_with <stub_with>
View
4 features/configuration/ignore_localhost.feature
@@ -29,7 +29,7 @@ Feature: ignore_localhost
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
<additional_config>
c.cassette_library_dir = 'cassettes'
c.stub_with <stub_with>
@@ -73,7 +73,7 @@ Feature: ignore_localhost
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.ignore_localhost = true
c.cassette_library_dir = 'cassettes'
c.stub_with <stub_with>
View
4 features/configuration/stub_with.feature
@@ -55,7 +55,7 @@ Feature: stub_with
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with <stub_with>
c.cassette_library_dir = 'vcr_cassettes'
end
@@ -128,7 +128,7 @@ Feature: stub_with
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with <stub_with>, :typhoeus, :excon, :faraday
c.cassette_library_dir = 'vcr_cassettes'
end
View
2  features/http_libraries/em_http_request.feature
@@ -22,7 +22,7 @@ Feature: EM HTTP Request
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :webmock
c.cassette_library_dir = 'cassettes'
end
View
10 features/http_libraries/net_http.feature
@@ -24,7 +24,7 @@ Feature: Net::HTTP
"""ruby
require 'vcr_setup.rb'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with <stub_with>
c.cassette_library_dir = 'cassettes'
end
@@ -50,7 +50,7 @@ Feature: Net::HTTP
"""ruby
require 'vcr_setup.rb'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with <stub_with>
c.cassette_library_dir = 'cassettes'
end
@@ -82,7 +82,7 @@ Feature: Net::HTTP
"""ruby
require 'vcr_setup.rb'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with <stub_with>
c.cassette_library_dir = 'cassettes'
end
@@ -115,7 +115,7 @@ Feature: Net::HTTP
require 'open-uri'
require 'vcr_setup.rb'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with <stub_with>
c.cassette_library_dir = 'cassettes'
end
@@ -141,7 +141,7 @@ Feature: Net::HTTP
"""ruby
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with <stub_with>
c.cassette_library_dir = 'cassettes'
end
View
2  features/middleware/faraday.feature
@@ -22,7 +22,7 @@ Feature: Faraday middleware
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.cassette_library_dir = 'cassettes'
c.stub_with :faraday
end
View
4 features/middleware/rack.feature
@@ -51,7 +51,7 @@ Feature: Rack
get('/') { Net::HTTP.get_response(URI.parse(params[:url])).body }
end
- VCR.config do |c|
+ VCR.configure do |c|
c.cassette_library_dir = 'cassettes'
c.stub_with :fakeweb
c.allow_http_connections_when_no_cassette = true
@@ -78,7 +78,7 @@ Feature: Rack
get('/') { Net::HTTP.get_response(URI.parse(params[:url])).body }
end
- VCR.config do |c|
+ VCR.configure do |c|
c.cassette_library_dir = 'cassettes'
c.stub_with :fakeweb
c.allow_http_connections_when_no_cassette = true
View
2  features/record_modes/all.feature
@@ -21,7 +21,7 @@ Feature: :all
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
end
View
2  features/record_modes/new_episodes.feature
@@ -20,7 +20,7 @@ Feature: :new_episodes
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
end
View
2  features/record_modes/none.feature
@@ -14,7 +14,7 @@ Feature: :none
"""ruby
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
end
View
2  features/record_modes/once.feature
@@ -23,7 +23,7 @@ Feature: :once
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.cassette_library_dir = 'cassettes'
end
View
2  features/test_frameworks/cucumber.feature
@@ -40,7 +40,7 @@ Feature: Usage with Cucumber
require "lib/server"
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :webmock
c.cassette_library_dir = 'features/cassettes'
end
View
4 features/test_frameworks/rspec.feature
@@ -67,7 +67,7 @@ Feature: Usage with RSpec
require 'sinatra_app'
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.cassette_library_dir = 'spec/cassettes'
c.stub_with :fakeweb
end
@@ -92,7 +92,7 @@ Feature: Usage with RSpec
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.cassette_library_dir = 'spec/cassettes'
c.stub_with :fakeweb
end
View
2  features/test_frameworks/shoulda.feature
@@ -28,7 +28,7 @@ Feature: Usage with Shoulda
require 'shoulda'
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :webmock
c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
end
View
2  features/test_frameworks/test_unit.feature
@@ -18,7 +18,7 @@ Feature: Usage with Test::Unit
require 'test/unit'
require 'vcr'
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :webmock
c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
end
View
20 lib/vcr.rb
@@ -3,10 +3,12 @@
require 'vcr/util/yaml'
require 'vcr/cassette'
-require 'vcr/config'
+require 'vcr/configuration'
require 'vcr/request_matcher'
require 'vcr/version'
+require 'vcr/deprecations/vcr'
+
require 'vcr/http_stubbing_adapters/common'
require 'vcr/structs/normalizers/body'
@@ -75,11 +77,15 @@ def use_cassette(*args, &block)
end
end
- def config
- yield VCR::Config
+ def configuration
+ @configuration ||= Configuration.new
+ end
+
+ def configure
+ yield configuration
http_stubbing_adapter.check_version!
http_stubbing_adapter.set_http_connections_allowed_to_default
- http_stubbing_adapter.ignored_hosts = VCR::Config.ignored_hosts
+ http_stubbing_adapter.ignored_hosts = VCR.configuration.ignored_hosts
end
def cucumber_tags(&block)
@@ -89,11 +95,11 @@ def cucumber_tags(&block)
def http_stubbing_adapter
@http_stubbing_adapter ||= begin
- if [:fakeweb, :webmock].all? { |l| VCR::Config.http_stubbing_libraries.include?(l) }
+ if [:fakeweb, :webmock].all? { |l| VCR.configuration.http_stubbing_libraries.include?(l) }
raise ArgumentError.new("You have configured VCR to use both :fakeweb and :webmock. You cannot use both.")
end
- adapters = VCR::Config.http_stubbing_libraries.map { |l| adapter_for(l) }
+ adapters = VCR.configuration.http_stubbing_libraries.map { |l| adapter_for(l) }
raise ArgumentError.new("The http stubbing library is not configured.") if adapters.empty?
adapter = HttpStubbingAdapters::MultiObjectProxy.for(*adapters)
adapter.after_adapters_loaded
@@ -103,7 +109,7 @@ def http_stubbing_adapter
def record_http_interaction(interaction)
return unless cassette = current_cassette
- return if VCR::Config.uri_should_be_ignored?(interaction.uri)
+ return if VCR.configuration.uri_should_be_ignored?(interaction.uri)
cassette.record_http_interaction(interaction)
end
View
12 lib/vcr/cassette.rb
@@ -11,7 +11,7 @@ class Cassette
attr_reader :name, :record_mode, :match_requests_on, :erb, :re_record_interval, :tag
def initialize(name, options = {})
- options = VCR::Config.default_cassette_options.merge(options)
+ options = VCR.configuration.default_cassette_options.merge(options)
invalid_options = options.keys - [
:record,
:erb,
@@ -59,7 +59,7 @@ def new_recorded_interactions
end
def file
- File.join(VCR::Config.cassette_library_dir, "#{sanitized_name}.yml") if VCR::Config.cassette_library_dir
+ File.join(VCR.configuration.cassette_library_dir, "#{sanitized_name}.yml") if VCR.configuration.cassette_library_dir
end
def update_content_length_header?
@@ -88,7 +88,7 @@ def should_re_record?
def should_allow_http_connections?
case record_mode
when :none; false
- when :once; !File.size?(file)
+ when :once; file.nil? || !File.size?(file)
else true
end
end
@@ -123,7 +123,7 @@ def load_recorded_interactions
invoke_hook(:before_playback, interactions)
interactions.reject! do |i|
- i.request.uri.is_a?(String) && VCR::Config.uri_should_be_ignored?(i.request.uri)
+ i.request.uri.is_a?(String) && VCR.configuration.uri_should_be_ignored?(i.request.uri)
end
if update_content_length_header?
@@ -161,7 +161,7 @@ def merged_interactions
end
def write_recorded_interactions_to_disk
- return unless VCR::Config.cassette_library_dir
+ return unless VCR.configuration.cassette_library_dir
return if new_recorded_interactions.empty?
interactions = merged_interactions
@@ -175,7 +175,7 @@ def write_recorded_interactions_to_disk
def invoke_hook(type, interactions)
interactions.delete_if do |i|
- VCR::Config.invoke_hook(type, tag, i, self)
+ VCR.configuration.invoke_hook(type, tag, i, self)
i.ignored?
end
end
View
13 lib/vcr/config.rb → lib/vcr/configuration.rb
@@ -2,14 +2,17 @@
require 'vcr/util/hooks'
module VCR
- module Config
+ class Configuration
include VCR::Hooks
include VCR::VariableArgsBlockCaller
- extend self
define_hook :before_record
define_hook :before_playback
+ def initialize
+ @allow_http_connections_when_no_cassette = nil
+ end
+
attr_reader :cassette_library_dir
def cassette_library_dir=(cassette_library_dir)
@cassette_library_dir = cassette_library_dir
@@ -73,12 +76,6 @@ def uri_should_be_ignored?(uri)
uri = URI.parse(uri) unless uri.respond_to?(:host)
ignored_hosts.include?(uri.host)
end
-
- def initialize_ivars
- @allow_http_connections_when_no_cassette = nil
- end
-
- initialize_ivars # to avoid warnings
end
end
View
12 lib/vcr/deprecations/vcr.rb
@@ -0,0 +1,12 @@
+module VCR
+ def config
+ warn "WARNING: `VCR.config` is deprecated. Use VCR.configure instead."
+ configure { |c| yield c }
+ end
+
+ def self.const_missing(const)
+ return super unless const == :Config
+ warn "WARNING: `VCR::Config` is deprecated. Use VCR.configuration instead."
+ configuration
+ end
+end
View
2  lib/vcr/http_stubbing_adapters/common.rb
@@ -65,7 +65,7 @@ def library_name
end
def set_http_connections_allowed_to_default
- self.http_connections_allowed = VCR::Config.allow_http_connections_when_no_cassette?
+ self.http_connections_allowed = VCR.configuration.allow_http_connections_when_no_cassette?
end
def raise_no_checkpoint_error(cassette)
View
32 lib/vcr/util/hooks.rb
@@ -2,6 +2,10 @@ module VCR
module Hooks
include VariableArgsBlockCaller
+ def self.included(klass)
+ klass.extend(ClassMethods)
+ end
+
def invoke_hook(hook, tag, *args)
hooks_for(hook, tag).each do |callback|
call_block(callback, *args)
@@ -12,16 +16,24 @@ def clear_hooks
hooks.clear
end
- private
+ private
- def hooks
- @hooks ||= Hash.new do |hook_type_hash, hook_type|
- hook_type_hash[hook_type] = Hash.new do |tag_hash, tag|
- tag_hash[tag] = []
- end
+ def hooks
+ @hooks ||= Hash.new do |hook_type_hash, hook_type|
+ hook_type_hash[hook_type] = Hash.new do |tag_hash, tag|
+ tag_hash[tag] = []
end
end
+ end
+ def hooks_for(hook, tag)
+ for_hook = hooks[hook]
+ hooks = for_hook[tag] # matching tagged hooks
+ hooks += for_hook[nil] unless tag.nil? # untagged hooks
+ hooks
+ end
+
+ module ClassMethods
def define_hook(hook)
# We use splat args here because 1.8.7 doesn't allow default
# values for block arguments, so we have to fake it.
@@ -34,12 +46,6 @@ def define_hook(hook)
hooks[hook][tag] << block
end
end
-
- def hooks_for(hook, tag)
- for_hook = hooks[hook]
- hooks = for_hook[tag] # matching tagged hooks
- hooks += for_hook[nil] unless tag.nil? # untagged hooks
- hooks
- end
+ end
end
end
View
26 spec/spec_helper.rb
@@ -16,24 +16,9 @@
module VCR
SPEC_ROOT = File.dirname(__FILE__)
- module Config
- def reset!(stubbing_lib = :fakeweb)
- self.default_cassette_options = { :record => :new_episodes }
-
- if stubbing_lib
- stub_with stubbing_lib
- else
- http_stubbing_libraries.clear
- end
-
- clear_hooks
- @ignored_hosts = []
-
- VCR.instance_eval do
- instance_variables.each { |ivar| remove_instance_variable(ivar) }
- end
- VCR.send(:initialize_ivars)
- end
+ def reset!(stubbing_lib = :fakeweb)
+ @configuration = nil
+ configuration.stub_with stubbing_lib if stubbing_lib
end
end
@@ -44,12 +29,11 @@ def reset!(stubbing_lib = :fakeweb)
tmp_dir = File.expand_path('../../tmp/cassette_library_dir', __FILE__)
config.before(:each) do
- VCR::Config.cassette_library_dir = tmp_dir
+ VCR.reset!
+ VCR.configuration.cassette_library_dir = tmp_dir
VCR.turn_on! unless VCR.turned_on?
VCR.eject_cassette while VCR.current_cassette
- VCR::Config.reset!
-
WebMock.allow_net_connect!
WebMock.reset!
View
4 spec/support/shared_example_groups/http_stubbing_adapter.rb
@@ -4,8 +4,8 @@
describe '.set_http_connections_allowed_to_default' do
[true, false].each do |default|
- context "when VCR::Config.allow_http_connections_when_no_cassette is #{default}" do
- before(:each) { VCR::Config.allow_http_connections_when_no_cassette = default }
+ context "when VCR.configuration.allow_http_connections_when_no_cassette is #{default}" do
+ before(:each) { VCR.configuration.allow_http_connections_when_no_cassette = default }
it "sets http_connections_allowed to #{default}" do
subject.http_connections_allowed = !default
View
12 spec/support/shared_example_groups/ignore_localhost_deprecation.rb
@@ -1,28 +1,28 @@
shared_examples_for '.ignore_localhost? deprecation' do
it 'returns false when no hosts are ignored' do
- VCR::Config.ignored_hosts.should be_empty
+ VCR.configuration.ignored_hosts.should be_empty
described_class.ignore_localhost?.should be_false
end
it 'returns false when only non-local hosts are ignored' do
- VCR::Config.ignore_hosts 'example.com'
+ VCR.configuration.ignore_hosts 'example.com'
described_class.ignore_localhost?.should be_false
end
it 'returns false when only some localhost aliases are ignored' do
aliases = VCR::LOCALHOST_ALIASES.dup
aliases.pop
- VCR::Config.ignore_hosts(*aliases)
+ VCR.configuration.ignore_hosts(*aliases)
described_class.ignore_localhost?.should be_false
end
it 'returns true when all localhost aliases are ignored, even if some other hosts are ignored, too' do
- VCR::Config.ignore_hosts 'example.com', *VCR::LOCALHOST_ALIASES
+ VCR.configuration.ignore_hosts 'example.com', *VCR::LOCALHOST_ALIASES
described_class.ignore_localhost?.should be_true
end
- it 'prints a warning: WARNING: `VCR::Config.ignore_localhost?` is deprecated. Check the list of ignored hosts using `VCR::Config.ignored_hosts` instead.' do
- VCR::Config.should_receive(:warn).with(/Check the list of ignored hosts using `VCR::Config.ignored_hosts` instead/)
+ it 'prints a warning: WARNING: `VCR.configuration.ignore_localhost?` is deprecated. Check the list of ignored hosts using `VCR.configuration.ignored_hosts` instead.' do
+ VCR.configuration.should_receive(:warn).with(/Check the list of ignored hosts using `VCR.configuration.ignored_hosts` instead/)
described_class.ignore_localhost?
end
end
View
62 spec/vcr/cassette_spec.rb
@@ -4,7 +4,7 @@
describe '#file' do
it 'combines the cassette_library_dir with the cassette name' do
cassette = VCR::Cassette.new('the_file')
- cassette.file.should eq(File.join(VCR::Config.cassette_library_dir, 'the_file.yml'))
+ cassette.file.should eq(File.join(VCR.configuration.cassette_library_dir, 'the_file.yml'))
end
it 'strips out disallowed characters so that it is a valid file name with no spaces' do
@@ -17,10 +17,12 @@
cassette.file.should =~ /#{Regexp.escape('dir/file_name.yml')}$/
end
- it 'returns nil if the cassette_library_dir is not set' do
- VCR::Config.cassette_library_dir = nil
- cassette = VCR::Cassette.new('the_file')
- cassette.file.should be_nil
+ VCR::Cassette::VALID_RECORD_MODES.each do |mode|
+ it "returns nil if the cassette_library_dir is not set (when the record mode is :#{mode})" do
+ VCR.configuration.cassette_library_dir = nil
+ cassette = VCR::Cassette.new('the_file', :record => mode)
+ cassette.file.should be_nil
+ end
end
end
@@ -34,7 +36,7 @@
end
describe '#match_requests_on' do
- before(:each) { VCR::Config.default_cassette_options.merge!(:match_requests_on => [:uri, :method]) }
+ before(:each) { VCR.configuration.default_cassette_options.merge!(:match_requests_on => [:uri, :method]) }
it "returns the provided options" do
c = VCR::Cassette.new('example', :match_requests_on => [:uri])
@@ -49,7 +51,7 @@
describe '.new' do
it 'raises an error with a helpful message when loading an old unsupported cassette' do
- VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures"
+ VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures"
expect { VCR::Cassette.new('0_3_1_cassette') }.to raise_error(/The VCR cassette 0_3_1_cassette.yml uses an old format that is now deprecated/)
end
@@ -64,7 +66,7 @@
end
it 'does not raise an error in the case of an empty file' do
- VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
+ VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
VCR::Cassette.new('empty', :record => :none).recorded_interactions.should eq([])
end
@@ -85,7 +87,7 @@
it 'reads the appropriate file from disk using a VCR::Cassette::Reader' do
VCR::Cassette::Reader.should_receive(:new).with(
- "#{VCR::Config.cassette_library_dir}/foo.yml", anything
+ "#{VCR.configuration.cassette_library_dir}/foo.yml", anything
).and_return(mock('reader', :read => VCR::YAML.dump([])))
VCR::Cassette.new('foo', :record => :new_episodes)
@@ -94,7 +96,7 @@
[true, false, nil, { }].each do |erb|
it "passes #{erb.inspect} to the VCR::Cassette::Reader when given as the :erb option" do
# test that it overrides the default
- VCR::Config.default_cassette_options = { :erb => true }
+ VCR.configuration.default_cassette_options = { :erb => true }
VCR::Cassette::Reader.should_receive(:new).with(
anything, erb
@@ -104,7 +106,7 @@
end
it "passes #{erb.inspect} to the VCR::Cassette::Reader when it is the default :erb option and none is given" do
- VCR::Config.default_cassette_options = { :erb => erb }
+ VCR.configuration.default_cassette_options = { :erb => erb }
VCR::Cassette::Reader.should_receive(:new).with(
anything, erb
@@ -119,10 +121,10 @@
http_connections_allowed = (record_mode != :none)
stub_requests = (record_mode != :all)
- context "when VCR::Config.default_cassette_options[:record] is :#{record_mode}" do
- before(:each) { VCR::Config.default_cassette_options = { :record => record_mode } }
+ context "when VCR.configuration.default_cassette_options[:record] is :#{record_mode}" do
+ before(:each) { VCR.configuration.default_cassette_options = { :record => record_mode } }
- it "defaults the record mode to #{record_mode} when VCR::Config.default_cassette_options[:record] is #{record_mode}" do
+ it "defaults the record mode to #{record_mode} when VCR.configuration.default_cassette_options[:record] is #{record_mode}" do
cassette = VCR::Cassette.new(:test)
cassette.record_mode.should eq(record_mode)
end
@@ -131,7 +133,7 @@
context "when :#{record_mode} is passed as the record option" do
if record_mode == :none
it 'does not allow http connections when there is an existing cassette file with recorded interactions' do
- VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
+ VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
VCR.http_stubbing_adapter.should_receive(:http_connections_allowed=).with(false)
c = VCR::Cassette.new('example', :record => :once)
File.should exist(c.file)
@@ -139,7 +141,7 @@
end
it 'allows http connections when there is an empty existing cassette file' do
- VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
+ VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
VCR.http_stubbing_adapter.should_receive(:http_connections_allowed=).with(true)
c = VCR::Cassette.new('empty', :record => :once)
File.should exist(c.file)
@@ -147,7 +149,7 @@
end
it 'allows http connections when there is not an existing cassette file' do
- VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
+ VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
VCR.http_stubbing_adapter.should_receive(:http_connections_allowed=).with(true)
c = VCR::Cassette.new('non_existant_file', :record => :once)
File.should_not exist(c.file)
@@ -158,7 +160,7 @@
let(:interaction_1) { VCR::HTTPInteraction.new(VCR::Request.new(:get, 'http://example.com/'), VCR::Response.new(VCR::ResponseStatus.new)) }
let(:interaction_2) { VCR::HTTPInteraction.new(VCR::Request.new(:get, 'http://example.com/'), VCR::Response.new(VCR::ResponseStatus.new)) }
let(:interactions) { [interaction_1, interaction_2] }
- before(:each) { VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec" }
+ before(:each) { VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec" }
it 'updates the content_length headers when given :update_content_length_header => true' do
VCR::YAML.stub(:load => interactions)
@@ -179,7 +181,7 @@
end
context "and re_record_interval is 7.days" do
- let(:file_name) { File.join(VCR::Config.cassette_library_dir, "cassette_name.yml") }
+ let(:file_name) { File.join(VCR.configuration.cassette_library_dir, "cassette_name.yml") }
subject { VCR::Cassette.new(File.basename(file_name).gsub('.yml', ''), :record => record_mode, :re_record_interval => 7.days) }
context 'when the cassette file does not exist' do
@@ -227,17 +229,17 @@
end
it 'does not load ignored interactions' do
- VCR::Config.stub(:uri_should_be_ignored?) do |uri|
+ VCR.configuration.stub(:uri_should_be_ignored?) do |uri|
uri.to_s !~ /example\.com/
end
- VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
+ VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
cassette = VCR::Cassette.new('with_localhost_requests', :record => record_mode)
cassette.recorded_interactions.map { |i| URI.parse(i.uri).host }.should eq(%w[example.com])
end
it "loads the recorded interactions from the library yml file" do
- VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
+ VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
cassette = VCR::Cassette.new('example', :record => record_mode)
cassette.should have(3).recorded_interactions
@@ -259,7 +261,7 @@
if stub_requests
it 'invokes the appropriately tagged before_playback hooks' do
- VCR::Config.should_receive(:invoke_hook).with(
+ VCR.configuration.should_receive(:invoke_hook).with(
:before_playback,
:foo,
an_instance_of(VCR::HTTPInteraction),
@@ -271,29 +273,29 @@
end
it 'does not playback any interactions that are ignored in a before_playback hook' do
- VCR.config do |c|
+ VCR.configure do |c|
c.before_playback { |i| i.ignore! if i.request.uri =~ /foo/ }
end
- VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
+ VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
cassette = VCR::Cassette.new('example', :record => record_mode)
cassette.should have(2).recorded_interactions
end
it "stubs the recorded requests with the http stubbing adapter" do
- VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
+ VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
VCR.http_stubbing_adapter.should_receive(:stub_requests).with([an_instance_of(VCR::HTTPInteraction)]*3, anything)
VCR::Cassette.new('example', :record => record_mode)
end
it "passes the :match_request_on option to #stub_requests" do
- VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
+ VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
VCR.http_stubbing_adapter.should_receive(:stub_requests).with(anything, [:body, :headers])
VCR::Cassette.new('example', :record => record_mode, :match_requests_on => [:body, :headers])
end
else
it "does not stub the recorded requests with the http stubbing adapter" do
- VCR::Config.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
+ VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
VCR.http_stubbing_adapter.should_not_receive(:stub_requests)
VCR::Cassette.new('example', :record => record_mode)
end
@@ -337,7 +339,7 @@
cassette.stub!(:new_recorded_interactions).and_return(interactions)
interactions.each do |i|
- VCR::Config.should_receive(:invoke_hook).with(
+ VCR.configuration.should_receive(:invoke_hook).with(
:before_record,
:foo,
i,
@@ -389,7 +391,7 @@
before(:each) do
base_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
- FileUtils.cp(base_dir + "/example.yml", VCR::Config.cassette_library_dir + "/example.yml")
+ FileUtils.cp(base_dir + "/example.yml", VCR.configuration.cassette_library_dir + "/example.yml")
end
it "restore the stubs checkpoint on the http stubbing adapter" do
View
68 spec/vcr/config_spec.rb → spec/vcr/configuration_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
-describe VCR::Config do
+describe VCR.configuration do
def stub_no_http_stubbing_adapter
VCR.stub(:http_stubbing_adapter).and_raise(ArgumentError)
- VCR::Config.stub(:http_stubbing_libraries).and_return([])
+ VCR.configuration.stub(:http_stubbing_libraries).and_return([])
end
describe '.cassette_library_dir=' do
@@ -11,45 +11,45 @@ def stub_no_http_stubbing_adapter
after(:each) { FileUtils.rm_rf tmp_dir }
it 'creates the directory if it does not exist' do
- expect { VCR::Config.cassette_library_dir = tmp_dir }.to change { File.exist?(tmp_dir) }.from(false).to(true)
+ expect { VCR.configuration.cassette_library_dir = tmp_dir }.to change { File.exist?(tmp_dir) }.from(false).to(true)
end
it 'does not raise an error if given nil' do
- expect { VCR::Config.cassette_library_dir = nil }.to_not raise_error
+ expect { VCR.configuration.cassette_library_dir = nil }.to_not raise_error
end
end
describe '.default_cassette_options' do
it 'has a hash with some defaults even if it is set to nil' do
- VCR::Config.default_cassette_options = nil
- VCR::Config.default_cassette_options.should eq({
+ VCR.configuration.default_cassette_options = nil
+ VCR.configuration.default_cassette_options.should eq({
:match_requests_on => VCR::RequestMatcher::DEFAULT_MATCH_ATTRIBUTES,
:record => :once
})
end
it "returns #{VCR::RequestMatcher::DEFAULT_MATCH_ATTRIBUTES.inspect} for :match_requests_on when other defaults have been set" do
- VCR::Config.default_cassette_options = { :record => :none }
- VCR::Config.default_cassette_options.should include(:match_requests_on => VCR::RequestMatcher::DEFAULT_MATCH_ATTRIBUTES)
+ VCR.configuration.default_cassette_options = { :record => :none }
+ VCR.configuration.default_cassette_options.should include(:match_requests_on => VCR::RequestMatcher::DEFAULT_MATCH_ATTRIBUTES)
end
it "returns :once for :record when other defaults have been set" do
- VCR::Config.default_cassette_options = { :erb => :true }
- VCR::Config.default_cassette_options.should include(:record => :once)
+ VCR.configuration.default_cassette_options = { :erb => :true }
+ VCR.configuration.default_cassette_options.should include(:record => :once)
end
end
describe '.stub_with' do
it 'stores the given symbols in http_stubbing_libraries' do
- VCR::Config.stub_with :fakeweb, :typhoeus
- VCR::Config.http_stubbing_libraries.should eq([:fakeweb, :typhoeus])
+ VCR.configuration.stub_with :fakeweb, :typhoeus
+ VCR.configuration.http_stubbing_libraries.should eq([:fakeweb, :typhoeus])
end
end
describe '.http_stubbing_libraries' do
it 'returns an empty array even when the variable is nil' do
- VCR::Config.send(:remove_instance_variable, :@http_stubbing_libraries)
- VCR::Config.http_stubbing_libraries.should eq([])
+ VCR.configuration.send(:remove_instance_variable, :@http_stubbing_libraries)
+ VCR.configuration.http_stubbing_libraries.should eq([])
end
end
@@ -58,63 +58,63 @@ def stub_no_http_stubbing_adapter
before(:each) do
stubbing_adapter.send(:ignored_hosts).should be_empty
VCR.stub(:http_stubbing_adapter => stubbing_adapter)
- VCR::Config.ignored_hosts.should be_empty
+ VCR.configuration.ignored_hosts.should be_empty
end
it 'adds the given hosts to the ignored_hosts list' do
- VCR::Config.ignore_hosts 'example.com', 'example.net'
- VCR::Config.ignored_hosts.should eq(%w[ example.com example.net ])
- VCR::Config.ignore_host 'example.org'
- VCR::Config.ignored_hosts.should eq(%w[ example.com example.net example.org ])
+ VCR.configuration.ignore_hosts 'example.com', 'example.net'
+ VCR.configuration.ignored_hosts.should eq(%w[ example.com example.net ])
+ VCR.configuration.ignore_host 'example.org'
+ VCR.configuration.ignored_hosts.should eq(%w[ example.com example.net example.org ])
end
it 'removes duplicate hosts' do
- VCR::Config.ignore_host 'example.com'
- VCR::Config.ignore_host 'example.com'
- VCR::Config.ignored_hosts.should eq(['example.com'])
+ VCR.configuration.ignore_host 'example.com'
+ VCR.configuration.ignore_host 'example.com'
+ VCR.configuration.ignored_hosts.should eq(['example.com'])
end
it "updates the http_stubbing_adapter's ignored_hosts list" do
- VCR::Config.ignore_hosts 'example.com', 'example.org'
+ VCR.configuration.ignore_hosts 'example.com', 'example.org'
stubbing_adapter.send(:ignored_hosts).should eq(%w[ example.com example.org ])
end
end
describe '.ignore_localhost=' do
before(:each) do
- VCR::Config.ignored_hosts.should be_empty
+ VCR.configuration.ignored_hosts.should be_empty
end
it 'adds the localhost aliases to the ignored_hosts list when set to true' do
- VCR::Config.ignore_host 'example.com'
- VCR::Config.ignore_localhost = true
- VCR::Config.ignored_hosts.should eq(['example.com', *VCR::LOCALHOST_ALIASES])
+ VCR.configuration.ignore_host 'example.com'
+ VCR.configuration.ignore_localhost = true
+ VCR.configuration.ignored_hosts.should eq(['example.com', *VCR::LOCALHOST_ALIASES])
end
it 'removes the localhost aliases from the ignored_hosts list when set to false' do
- VCR::Config.ignore_host 'example.com', *VCR::LOCALHOST_ALIASES
- VCR::Config.ignore_localhost = false
- VCR::Config.ignored_hosts.should eq(['example.com'])
+ VCR.configuration.ignore_host 'example.com', *VCR::LOCALHOST_ALIASES
+ VCR.configuration.ignore_localhost = false
+ VCR.configuration.ignored_hosts.should eq(['example.com'])
end
end
describe '.allow_http_connections_when_no_cassette=' do
[true, false].each do |val|
it "sets the allow_http_connections_when_no_cassette to #{val} when set to #{val}" do
- VCR::Config.allow_http_connections_when_no_cassette = val
- VCR::Config.allow_http_connections_when_no_cassette?.should eq(val)
+ VCR.configuration.allow_http_connections_when_no_cassette = val
+ VCR.configuration.allow_http_connections_when_no_cassette?.should eq(val)
end
end
it 'sets http_connnections_allowed to the default' do
VCR.http_stubbing_adapter.should respond_to(:set_http_connections_allowed_to_default)
VCR.http_stubbing_adapter.should_receive(:set_http_connections_allowed_to_default)
- VCR::Config.allow_http_connections_when_no_cassette = true
+ VCR.configuration.allow_http_connections_when_no_cassette = true
end
it "works when the adapter hasn't been set yet" do
stub_no_http_stubbing_adapter
- VCR::Config.allow_http_connections_when_no_cassette = true
+ VCR.configuration.allow_http_connections_when_no_cassette = true
end
end
View
42 spec/vcr/deprecations/vcr_spec.rb
@@ -0,0 +1,42 @@
+require 'spec_helper'
+
+describe VCR, 'deprecations', :disable_warnings do
+ describe ".config" do
+ it 'delegates to VCR.configure' do
+ VCR.should_receive(:configure)
+ VCR.config { }
+ end
+
+ it 'yields the configuration object' do
+ config_object = nil
+ VCR.config { |c| config_object = c }
+ config_object.should be(VCR.configuration)
+ end
+
+ it 'prints a deprecation warning' do
+ VCR.should_receive(:warn).with \
+ "WARNING: `VCR.config` is deprecated. Use VCR.configure instead."
+
+ VCR.config { }
+ end
+ end
+
+ describe "Config" do
+ it 'returns the same object referenced by VCR.configuration' do
+ VCR::Config.should be(VCR.configuration)
+ end
+
+ it 'prints a deprecation warning' do
+ VCR.should_receive(:warn).with \
+ "WARNING: `VCR::Config` is deprecated. Use VCR.configuration instead."
+
+ VCR::Config
+ end
+
+ it 'preserves the normal undefined constant behavior' do
+ expect {
+ VCR::SomeUndefinedConstant
+ }.to raise_error(NameError)
+ end
+ end
+end
View
42 spec/vcr_spec.rb
@@ -86,32 +86,42 @@ def insert_cassette(name = :cassette_test)
end
end
- describe '.config' do
+ describe '.configuration' do
+ it 'returns the configuration object' do
+ VCR.configuration.should be_a(VCR::Configuration)
+ end
+
+ it 'memoizes the instance' do
+ VCR.configuration.should be(VCR.configuration)
+ end
+ end
+
+ describe '.configure' do
it 'yields the configuration object' do
yielded_object = nil
- VCR.config do |obj|
+ VCR.configure do |obj|
yielded_object = obj
end
- yielded_object.should eq(VCR::Config)
+ yielded_object.should eq(VCR.configuration)
end
it "sets http_stubbing_adapter.http_connections_allowed to the configured default" do
VCR.http_stubbing_adapter.should respond_to(:set_http_connections_allowed_to_default)
VCR.http_stubbing_adapter.should_receive(:set_http_connections_allowed_to_default)
- VCR.config { }
+ VCR.configure { }
end
it "checks the adapted library's version to make sure it's compatible with VCR" do
VCR.http_stubbing_adapter.should respond_to(:check_version!)
VCR.http_stubbing_adapter.should_receive(:check_version!)
- VCR.config { }
+ VCR.configure { }
end
it "sets http_stubbing_adapter.ignored_hosts to the configured hosts when the block completes" do
- VCR::Config.reset!(nil)
+ VCR.reset!(nil)
VCR::HttpStubbingAdapters::FakeWeb.send(:ignored_hosts).should be_empty
- VCR.config do |c|
+ VCR.configure do |c|
c.stub_with :fakeweb
c.ignore_hosts 'example.com', 'example.org'
end
@@ -137,7 +147,7 @@ def insert_cassette(name = :cassette_test)
end
it 'returns a multi object proxy for the configured stubbing libraries when multiple libs are configured', :unless => RUBY_PLATFORM == 'java' do
- VCR::Config.stub_with :fakeweb, :typhoeus
+ VCR.configuration.stub_with :fakeweb, :typhoeus
VCR.http_stubbing_adapter.proxied_objects.should eq([
VCR::HttpStubbingAdapters::FakeWeb,
VCR::HttpStubbingAdapters::Typhoeus
@@ -151,31 +161,31 @@ def insert_cassette(name = :cassette_test)
:excon => VCR::HttpStubbingAdapters::Excon
}.each do |symbol, klass|
it "returns #{klass} for :#{symbol}" do
- VCR::Config.stub_with symbol
+ VCR.configuration.stub_with symbol
VCR.http_stubbing_adapter.should eq(klass)
end
end
it 'calls #after_adapters_loaded on the configured stubbing adapter' do
VCR::HttpStubbingAdapters::FakeWeb.should_receive(:after_adapters_loaded)
- VCR::Config.stub_with :fakeweb
+ VCR.configuration.stub_with :fakeweb
VCR.http_stubbing_adapter
end
it 'raises an error if both :fakeweb and :webmock are configured' do
- VCR::Config.stub_with :fakeweb, :webmock
+ VCR.configuration.stub_with :fakeweb, :webmock
expect { VCR.http_stubbing_adapter }.to raise_error(ArgumentError, /cannot use both/)
end
it 'raises an error for unsupported stubbing libraries' do
- VCR::Config.stub_with :unsupported_library
+ VCR.configuration.stub_with :unsupported_library
expect { VCR.http_stubbing_adapter }.to raise_error(ArgumentError, /unsupported_library is not a supported HTTP stubbing library/i)
end
it 'raises an error when no stubbing libraries are configured' do
- VCR::Config.stub_with
+ VCR.configuration.stub_with
expect { VCR.http_stubbing_adapter }.to raise_error(ArgumentError, /the http stubbing library is not configured/i)
end
@@ -192,7 +202,7 @@ def insert_cassette(name = :cassette_test)
it 'does not record a request' do
# we can't set a message expectation on nil, but there is no place to record it to...
# this mostly tests that there is no error.
- VCR::Config.stub(:uri_should_be_ignored? => false)
+ VCR.configuration.stub(:uri_should_be_ignored? => false)
VCR.record_http_interaction(interaction)
end
end
@@ -201,13 +211,13 @@ def insert_cassette(name = :cassette_test)
let(:current_cassette) { mock('current cassette') }
it 'records the request when the uri should not be ignored' do
- VCR::Config.stub(:uri_should_be_ignored?).with(uri).and_return(false)
+ VCR.configuration.stub(:uri_should_be_ignored?).with(uri).and_return(false)
current_cassette.should_receive(:record_http_interaction).with(interaction)
VCR.record_http_interaction(interaction)
end
it 'does not record the request when the uri should be ignored' do
- VCR::Config.stub(:uri_should_be_ignored?).with(uri).and_return(true)
+ VCR.configuration.stub(:uri_should_be_ignored?).with(uri).and_return(true)
current_cassette.should_not_receive(:record_http_interaction)
VCR.record_http_interaction(interaction)
end
Please sign in to comment.
Something went wrong with that request. Please try again.