vcr 2.9.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/features/about_these_examples.md +1 -1
  3. data/features/cassettes/automatic_re_recording.feature +4 -4
  4. data/features/cassettes/decompress.feature +3 -3
  5. data/features/cassettes/exclusive.feature +11 -8
  6. data/features/cassettes/format.feature +135 -32
  7. data/features/cassettes/naming.feature +2 -2
  8. data/features/cassettes/no_cassette.feature +4 -4
  9. data/features/configuration/allow_http_connections_when_no_cassette.feature +6 -3
  10. data/features/configuration/cassette_library_dir.feature +2 -2
  11. data/features/configuration/debug_logging.feature +15 -8
  12. data/features/configuration/filter_sensitive_data.feature +8 -7
  13. data/features/configuration/hook_into.feature +8 -8
  14. data/features/configuration/ignore_request.feature +13 -14
  15. data/features/configuration/preserve_exact_body_bytes.feature +5 -5
  16. data/features/configuration/uri_parser.feature +15 -11
  17. data/features/hooks/after_http_request.feature +5 -4
  18. data/features/hooks/around_http_request.feature +3 -3
  19. data/features/hooks/before_http_request.feature +4 -2
  20. data/features/hooks/before_playback.feature +14 -15
  21. data/features/hooks/before_record.feature +10 -10
  22. data/features/http_libraries/em_http_request.feature +6 -3
  23. data/features/http_libraries/net_http.feature +15 -5
  24. data/features/middleware/faraday.feature +2 -2
  25. data/features/middleware/rack.feature +4 -4
  26. data/features/record_modes/all.feature +5 -5
  27. data/features/record_modes/new_episodes.feature +2 -2
  28. data/features/record_modes/once.feature +3 -3
  29. data/features/step_definitions/cli_steps.rb +37 -39
  30. data/features/support/env.rb +29 -26
  31. data/features/support/http_lib_filters.rb +0 -7
  32. data/features/test_frameworks/cucumber.feature +11 -10
  33. data/features/test_frameworks/rspec_macro.feature +5 -30
  34. data/features/test_frameworks/rspec_metadata.feature +9 -8
  35. data/features/test_frameworks/test_unit.feature +5 -2
  36. data/lib/vcr.rb +86 -14
  37. data/lib/vcr/cassette.rb +4 -2
  38. data/lib/vcr/cassette/serializers.rb +10 -8
  39. data/lib/vcr/cassette/serializers/compressed.rb +45 -0
  40. data/lib/vcr/configuration.rb +38 -17
  41. data/lib/vcr/library_hooks/fakeweb.rb +1 -0
  42. data/lib/vcr/library_hooks/faraday.rb +5 -1
  43. data/lib/vcr/middleware/faraday.rb +13 -9
  44. data/lib/vcr/test_frameworks/cucumber.rb +39 -5
  45. data/lib/vcr/version.rb +1 -1
  46. data/spec/acceptance/concurrency_spec.rb +51 -0
  47. data/spec/{vcr → lib/vcr}/cassette/erb_renderer_spec.rb +0 -0
  48. data/spec/{vcr → lib/vcr}/cassette/http_interaction_list_spec.rb +0 -0
  49. data/spec/{vcr → lib/vcr}/cassette/migrator_spec.rb +10 -9
  50. data/spec/{vcr → lib/vcr}/cassette/persisters/file_system_spec.rb +0 -0
  51. data/spec/{vcr → lib/vcr}/cassette/persisters_spec.rb +0 -0
  52. data/spec/{vcr → lib/vcr}/cassette/serializers_spec.rb +8 -2
  53. data/spec/{vcr → lib/vcr}/cassette_spec.rb +0 -0
  54. data/spec/{vcr → lib/vcr}/configuration_spec.rb +0 -0
  55. data/spec/{vcr → lib/vcr}/deprecations_spec.rb +0 -0
  56. data/spec/{vcr → lib/vcr}/errors_spec.rb +0 -0
  57. data/spec/{vcr → lib/vcr}/extensions/net_http_response_spec.rb +0 -0
  58. data/spec/{vcr → lib/vcr}/library_hooks/excon_spec.rb +0 -0
  59. data/spec/{vcr → lib/vcr}/library_hooks/fakeweb_spec.rb +0 -0
  60. data/spec/{vcr → lib/vcr}/library_hooks/faraday_spec.rb +0 -0
  61. data/spec/{vcr → lib/vcr}/library_hooks/typhoeus_0.4_spec.rb +0 -0
  62. data/spec/{vcr → lib/vcr}/library_hooks/typhoeus_spec.rb +0 -0
  63. data/spec/{vcr → lib/vcr}/library_hooks/webmock_spec.rb +2 -2
  64. data/spec/{vcr → lib/vcr}/library_hooks_spec.rb +0 -0
  65. data/spec/{vcr → lib/vcr}/middleware/faraday_spec.rb +0 -0
  66. data/spec/{vcr → lib/vcr}/middleware/rack_spec.rb +0 -0
  67. data/spec/{vcr → lib/vcr}/request_ignorer_spec.rb +0 -0
  68. data/spec/{vcr → lib/vcr}/request_matcher_registry_spec.rb +0 -0
  69. data/spec/{vcr → lib/vcr}/structs_spec.rb +0 -0
  70. data/spec/{vcr → lib/vcr}/test_frameworks/cucumber_spec.rb +0 -0
  71. data/spec/{vcr → lib/vcr}/test_frameworks/rspec_spec.rb +0 -0
  72. data/spec/{vcr → lib/vcr}/util/hooks_spec.rb +0 -0
  73. data/spec/{vcr → lib/vcr}/util/internet_connection_spec.rb +0 -0
  74. data/spec/{vcr → lib/vcr}/util/version_checker_spec.rb +0 -0
  75. data/spec/{vcr → lib/vcr}/version_spec.rb +0 -0
  76. data/spec/{vcr_spec.rb → lib/vcr_spec.rb} +2 -2
  77. data/spec/spec_helper.rb +21 -50
  78. data/spec/support/cucumber_helpers.rb +39 -0
  79. data/spec/support/limited_uri.rb +1 -11
  80. data/spec/support/shared_example_groups/hook_into_http_library.rb +2 -1
  81. data/spec/support/vcr_localhost_server.rb +2 -3
  82. metadata +475 -123
  83. data/.gemtest +0 -0
  84. data/.gitignore +0 -52
  85. data/.gitmodules +0 -3
  86. data/.rspec +0 -2
  87. data/.travis.yml +0 -27
  88. data/.yardopts +0 -9
  89. data/Appraisals +0 -5
  90. data/CHANGELOG.md +0 -987
  91. data/CONTRIBUTING.md +0 -26
  92. data/Gemfile +0 -54
  93. data/Gemfile.lock +0 -159
  94. data/LICENSE +0 -20
  95. data/README.md +0 -243
  96. data/Rakefile +0 -197
  97. data/Upgrade.md +0 -289
  98. data/benchmarks/http_stubbing_libraries.rb +0 -59
  99. data/benchmarks/null_logging.rb +0 -62
  100. data/cucumber.yml +0 -16
  101. data/features/.nav +0 -62
  102. data/features/cassettes/persistence.feature +0 -63
  103. data/features/support/vcr_cucumber_helpers.rb +0 -46
  104. data/gemfiles/typhoeus_old.gemfile +0 -34
  105. data/gemfiles/typhoeus_old.gemfile.lock +0 -133
  106. data/script/ci.sh +0 -27
  107. data/spec/capture_warnings.rb +0 -73
  108. data/spec/quality_spec.rb +0 -51
  109. data/vcr.gemspec +0 -23
@@ -1,41 +1,44 @@
1
- require 'rubygems'
2
1
  require 'bundler'
3
2
  Bundler.setup
4
3
 
5
- require 'ruby-debug' if !defined?(RUBY_ENGINE) && RUBY_VERSION != '1.9.3' && !ENV['CI']
4
+ ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
6
5
 
7
6
  require 'aruba/cucumber'
8
7
  require 'aruba/jruby' if RUBY_PLATFORM == 'java'
9
8
 
10
- additional_paths = []
11
- Before('@rspec-1') do
12
- additional_paths << File.join(%w[ .. .. vendor rspec-1 bin ])
13
- end
14
-
15
- Before do
16
- load_paths, requires = ['../../lib'], []
17
-
18
- # Put any bundler-managed gems (such as :git gems) on the load path for when aruba shells out.
19
- # Alternatively, we could hook up aruba to use bundler when it shells out, but invoking bundler
20
- # for each and every time aruba starts ruby would slow everything down. We really only need it for
21
- # bundler-managed gems.
22
- load_paths.push($LOAD_PATH.grep %r|bundler/gems|)
23
-
24
- if RUBY_VERSION < '1.9'
25
- requires << "rubygems"
9
+ gem_specs = Bundler.load.specs
10
+ load_paths = Dir.glob(gem_specs.map { |spec|
11
+ if spec.respond_to?(:lib_dirs_glob)
12
+ spec.lib_dirs_glob
26
13
  else
27
- load_paths << '.'
14
+ spec.load_paths
28
15
  end
16
+ }.flatten)
29
17
 
30
- requires << '../../features/support/vcr_cucumber_helpers'
31
- requires.map! { |r| "-r#{r}" }
32
- set_env('RUBYOPT', "-I#{load_paths.join(':')} #{requires.join(' ')}")
18
+ load_paths << File.expand_path("../../../spec", __FILE__)
19
+ rubyopt = "-rsupport/cucumber_helpers"
33
20
 
34
- if additional_paths.any?
35
- existing_paths = ENV['PATH'].split(':')
36
- set_env('PATH', (additional_paths + existing_paths).join(':'))
21
+ if RUBY_VERSION > '1.9'
22
+ load_paths.unshift(".")
23
+ rubyopt = "--disable-gems #{rubyopt}" if "ruby" == ruby_engine
24
+ end
25
+
26
+ Before do
27
+ @aruba_timeout_seconds = 30
28
+ if "jruby" == ruby_engine
29
+ @aruba_io_wait_seconds = 0.1
30
+ else
31
+ @aruba_io_wait_seconds = 0.02
37
32
  end
33
+ end
38
34
 
39
- @aruba_timeout_seconds = 60
35
+ Before("~@with-bundler") do
36
+ set_env("RUBYLIB", load_paths.join(":"))
37
+ set_env("RUBYOPT", rubyopt)
40
38
  end
41
39
 
40
+ Before("@with-bundler") do
41
+ set_env("RUBYLIB", ".:#{ENV["RUBYLIB"]}:#{load_paths.last}")
42
+ set_env("RUBYOPT", "#{ENV["RUBYOPT"]} -rsupport/cucumber_helpers")
43
+ set_env("BUNDLE_GEMFILE", Bundler.default_gemfile.expand_path.to_s)
44
+ end
@@ -1,10 +1,3 @@
1
- # make the values of the example row cells available as an array...
2
- Cucumber::Ast::OutlineTable::ExampleRow.class_eval do
3
- def cell_values
4
- @cells.map { |c| c.value }
5
- end
6
- end
7
-
8
1
  if RUBY_VERSION == '1.8.7'
9
2
  # We get timeouts on 1.8.7 w/ Patron for some reason.
10
3
  UNSUPPORTED_HTTP_LIBS = %w[ patron ]
@@ -1,3 +1,4 @@
1
+ @with-bundler
1
2
  Feature: Usage with Cucumber
2
3
 
3
4
  VCR can be used with cucumber in two basic ways:
@@ -35,7 +36,7 @@ Feature: Usage with Cucumber
35
36
  Given a file named "lib/server.rb" with:
36
37
  """ruby
37
38
  if ENV['WITH_SERVER'] == 'true'
38
- start_sinatra_app(:port => 7777) do
39
+ $server = start_sinatra_app do
39
40
  get('/:path') { "Hello #{params[:path]}" }
40
41
  end
41
42
  end
@@ -49,6 +50,9 @@ Feature: Usage with Cucumber
49
50
  VCR.configure do |c|
50
51
  c.hook_into :webmock
51
52
  c.cassette_library_dir = 'features/cassettes'
53
+ c.default_cassette_options = {
54
+ :match_requests_on => [:method, :host, :path]
55
+ }
52
56
  end
53
57
 
54
58
  VCR.cucumber_tags do |t|
@@ -62,15 +66,17 @@ Feature: Usage with Cucumber
62
66
  require 'net/http'
63
67
 
64
68
  When /^a request is made to "([^"]*)"$/ do |url|
65
- @response = Net::HTTP.get_response(URI.parse(url))
69
+ uri = URI.parse(url)
70
+ uri.port = $server.port if $server
71
+ @response = Net::HTTP.get_response(uri)
66
72
  end
67
73
 
68
- When /^(.*) within a cassette named "([^"]*)"$/ do |step, cassette_name|
69
- VCR.use_cassette(cassette_name) { When step }
74
+ When /^(.*) within a cassette named "([^"]*)"$/ do |step_name, cassette_name|
75
+ VCR.use_cassette(cassette_name) { step(step_name) }
70
76
  end
71
77
 
72
78
  Then /^the response should be "([^"]*)"$/ do |expected_response|
73
- @response.body.should == expected_response
79
+ expect(@response.body).to eq(expected_response)
74
80
  end
75
81
  """
76
82
  And a file named "features/vcr_example.feature" with:
@@ -122,11 +128,6 @@ Feature: Usage with Cucumber
122
128
  And the directory "features/cassettes" does not exist
123
129
  When I run `cucumber WITH_SERVER=true features/vcr_example.feature`
124
130
  Then it should fail with "5 scenarios (2 failed, 3 passed)"
125
- And the output should contain each of the following:
126
- | An HTTP request has been made that VCR does not know how to handle: |
127
- | GET http://localhost:7777/disallowed_1 |
128
- | An HTTP request has been made that VCR does not know how to handle: |
129
- | GET http://localhost:7777/disallowed_2 |
130
131
  And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "Hello localhost_request_1"
131
132
  And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "Hello localhost_request_2"
132
133
  And the file "features/cassettes/nested_cassette.yml" should contain "Hello nested_cassette"
@@ -1,3 +1,4 @@
1
+ @with-bundler
1
2
  Feature: Usage with RSpec macro
2
3
 
3
4
  VCR provides a macro that makes it easy to use a VCR cassette for an RSpec
@@ -28,7 +29,7 @@ Feature: Usage with RSpec macro
28
29
  | spec/cassettes/net_http_example.yml |
29
30
  And a file named "spec/sinatra_app.rb" with:
30
31
  """ruby
31
- start_sinatra_app(:port => 7777) do
32
+ $server = start_sinatra_app do
32
33
  get('/') { "Hello" }
33
34
  end
34
35
  """
@@ -38,14 +39,14 @@ Feature: Usage with RSpec macro
38
39
 
39
40
  describe "VCR-RSpec integration" do
40
41
  def make_http_request
41
- Net::HTTP.get_response('localhost', '/', 7777).body
42
+ Net::HTTP.get_response('localhost', '/', $server.port).body
42
43
  end
43
44
 
44
45
  context "without an explicit cassette name" do
45
46
  use_vcr_cassette
46
47
 
47
48
  it 'records an http request' do
48
- make_http_request.should == 'Hello'
49
+ expect(make_http_request).to eq('Hello')
49
50
  end
50
51
  end
51
52
 
@@ -53,7 +54,7 @@ Feature: Usage with RSpec macro
53
54
  use_vcr_cassette "net_http_example"
54
55
 
55
56
  it 'records an http request' do
56
- make_http_request.should == 'Hello'
57
+ expect(make_http_request).to eq('Hello')
57
58
  end
58
59
  end
59
60
  end
@@ -78,29 +79,3 @@ Feature: Usage with RSpec macro
78
79
  Then the output should contain "2 examples, 0 failures"
79
80
  And the file "spec/cassettes/VCR-RSpec_integration/without_an_explicit_cassette_name.yml" should contain "Hello"
80
81
  And the file "spec/cassettes/net_http_example.yml" should contain "Hello"
81
-
82
- @rspec-1 @exclude-jruby
83
- Scenario: Use `use_vcr_cassette` macro with RSpec 1
84
- Given a file named "spec/spec_helper.rb" with:
85
- """ruby
86
- require 'sinatra_app'
87
-
88
- require 'spec'
89
- require 'spec/autorun'
90
-
91
- require 'vcr'
92
-
93
- VCR.configure do |c|
94
- c.cassette_library_dir = 'spec/cassettes'
95
- c.hook_into :webmock
96
- end
97
-
98
- Spec::Runner.configure do |c|
99
- c.extend VCR::RSpec::Macros
100
- end
101
- """
102
- When I run `spec spec/vcr_example_spec.rb`
103
- Then the output should contain "2 examples, 0 failures"
104
- And the file "spec/cassettes/VCR-RSpec_integration/without_an_explicit_cassette_name.yml" should contain "Hello"
105
- And the file "spec/cassettes/net_http_example.yml" should contain "Hello"
106
-
@@ -1,3 +1,4 @@
1
+ @with-bundler
1
2
  Feature: Usage with RSpec metadata
2
3
 
3
4
  VCR provides easy integration with RSpec using metadata. To set this
@@ -57,35 +58,35 @@ Feature: Usage with RSpec metadata
57
58
  Scenario: Use `:vcr` metadata
58
59
  Given a file named "spec/vcr_example_spec.rb" with:
59
60
  """ruby
60
- start_sinatra_app(:port => 7777) do
61
+ $server = start_sinatra_app do
61
62
  get('/') { "Hello" }
62
63
  end
63
64
 
64
65
  def make_http_request
65
- Net::HTTP.get_response('localhost', '/', 7777).body
66
+ Net::HTTP.get_response('localhost', '/', $server.port).body
66
67
  end
67
68
 
68
69
  require 'spec_helper'
69
70
 
70
71
  describe "VCR example group metadata", :vcr do
71
72
  it 'records an http request' do
72
- make_http_request.should == 'Hello'
73
+ expect(make_http_request).to eq('Hello')
73
74
  end
74
75
 
75
76
  it 'records another http request' do
76
- make_http_request.should == 'Hello'
77
+ expect(make_http_request).to eq('Hello')
77
78
  end
78
79
 
79
80
  context 'in a nested example group' do
80
81
  it 'records another one' do
81
- make_http_request.should == 'Hello'
82
+ expect(make_http_request).to eq('Hello')
82
83
  end
83
84
  end
84
85
  end
85
86
 
86
87
  describe "VCR example metadata" do
87
88
  it 'records an http request', :vcr do
88
- make_http_request.should == 'Hello'
89
+ expect(make_http_request).to eq('Hello')
89
90
  end
90
91
  end
91
92
  """
@@ -137,11 +138,11 @@ Feature: Usage with RSpec metadata
137
138
  vcr_options = { :cassette_name => "example", :record => :new_episodes }
138
139
  describe "Using an options hash", :vcr => vcr_options do
139
140
  it 'uses the provided cassette name' do
140
- VCR.current_cassette.name.should == "example"
141
+ expect(VCR.current_cassette.name).to eq("example")
141
142
  end
142
143
 
143
144
  it 'sets the given options' do
144
- VCR.current_cassette.record_mode.should == :new_episodes
145
+ expect(VCR.current_cassette.record_mode).to eq(:new_episodes)
145
146
  end
146
147
  end
147
148
  """
@@ -6,7 +6,7 @@ Feature: Usage with Test::Unit
6
6
  Scenario: Use `VCR.use_cassette` in a test
7
7
  Given a file named "test/test_server.rb" with:
8
8
  """ruby
9
- start_sinatra_app(:port => 7777) do
9
+ $server = start_sinatra_app do
10
10
  get('/') { "Hello" }
11
11
  end
12
12
  """
@@ -19,6 +19,9 @@ Feature: Usage with Test::Unit
19
19
  VCR.configure do |c|
20
20
  c.hook_into :webmock
21
21
  c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
22
+ c.default_cassette_options = {
23
+ :match_requests_on => [:method, :host, :path]
24
+ }
22
25
  end
23
26
  """
24
27
  And a file named "test/vcr_example_test.rb" with:
@@ -28,7 +31,7 @@ Feature: Usage with Test::Unit
28
31
  class VCRExampleTest < Test::Unit::TestCase
29
32
  def test_use_vcr
30
33
  VCR.use_cassette('test_unit_example') do
31
- response = Net::HTTP.get_response('localhost', '/', 7777)
34
+ response = Net::HTTP.get_response('localhost', '/', $server ? $server.port : 0)
32
35
  assert_equal "Hello", response.body
33
36
  end
34
37
  end
data/lib/vcr.rb CHANGED
@@ -22,6 +22,12 @@ module VCR
22
22
 
23
23
  extend self
24
24
 
25
+ # Mutex to synchronize access to cassettes in a threaded environment
26
+ CassetteMutex = Mutex.new
27
+
28
+ # The main thread in which VCR was loaded
29
+ MainThread = Thread.current
30
+
25
31
  autoload :CucumberTags, 'vcr/test_frameworks/cucumber'
26
32
  autoload :InternetConnection, 'vcr/util/internet_connection'
27
33
 
@@ -201,7 +207,7 @@ module VCR
201
207
 
202
208
  # @return [VCR::Configuration] the VCR configuration.
203
209
  def configuration
204
- @configuration ||= Configuration.new
210
+ @configuration
205
211
  end
206
212
 
207
213
  # Sets up `Before` and `After` cucumber hooks in order to
@@ -256,13 +262,13 @@ module VCR
256
262
  "You must eject it before you can turn VCR off."
257
263
  end
258
264
 
259
- @ignore_cassettes = options[:ignore_cassettes]
265
+ set_context_value(:ignore_cassettes, options[:ignore_cassettes])
260
266
  invalid_options = options.keys - [:ignore_cassettes]
261
267
  if invalid_options.any?
262
268
  raise ArgumentError.new("You passed some invalid options: #{invalid_options.inspect}")
263
269
  end
264
270
 
265
- @turned_off = true
271
+ set_context_value(:turned_off, true)
266
272
  end
267
273
 
268
274
  # Turns on VCR, if it has previously been turned off.
@@ -271,7 +277,7 @@ module VCR
271
277
  # @see #turned_off
272
278
  # @see #turned_on?
273
279
  def turn_on!
274
- @turned_off = false
280
+ set_context_value(:turned_off, false)
275
281
  end
276
282
 
277
283
  # @return whether or not VCR is turned on
@@ -281,7 +287,7 @@ module VCR
281
287
  # @see #turn_off!
282
288
  # @see #turned_off
283
289
  def turned_on?
284
- !@turned_off
290
+ !context_value(:turned_off)
285
291
  end
286
292
 
287
293
  # @private
@@ -293,32 +299,32 @@ module VCR
293
299
  # @private
294
300
  def real_http_connections_allowed?
295
301
  return current_cassette.recording? if current_cassette
296
- !!(configuration.allow_http_connections_when_no_cassette? || @turned_off)
302
+ !!(configuration.allow_http_connections_when_no_cassette? || !turned_on?)
297
303
  end
298
304
 
299
305
  # @return [RequestMatcherRegistry] the request matcher registry
300
306
  def request_matchers
301
- @request_matchers ||= RequestMatcherRegistry.new
307
+ @request_matchers
302
308
  end
303
309
 
304
310
  # @private
305
311
  def request_ignorer
306
- @request_ignorer ||= RequestIgnorer.new
312
+ @request_ignorer
307
313
  end
308
314
 
309
315
  # @private
310
316
  def library_hooks
311
- @library_hooks ||= LibraryHooks.new
317
+ @library_hooks
312
318
  end
313
319
 
314
320
  # @private
315
321
  def cassette_serializers
316
- @cassette_serializers ||= Cassette::Serializers.new
322
+ @cassette_serializers
317
323
  end
318
324
 
319
325
  # @private
320
326
  def cassette_persisters
321
- @cassette_persisters ||= Cassette::Persisters.new
327
+ @cassette_persisters
322
328
  end
323
329
 
324
330
  # @private
@@ -329,18 +335,84 @@ module VCR
329
335
  cassette.record_http_interaction(interaction)
330
336
  end
331
337
 
338
+ # @private
339
+ def link_context(from_thread, to_key)
340
+ @context[to_key] = get_context(from_thread)
341
+ end
342
+
343
+ # @private
344
+ def unlink_context(key)
345
+ @context.delete(key)
346
+ end
347
+
348
+ # @private
349
+ def fibers_available?
350
+ @fibers_available
351
+ end
352
+
332
353
  private
354
+ def current_context
355
+ get_context(Thread.current, Fiber.current)
356
+ end
357
+
358
+ def get_context(thread_key, fiber_key = nil)
359
+ context = @context[fiber_key] if fiber_key
360
+ context ||= @context[thread_key]
361
+ if context
362
+ context
363
+ else
364
+ @context[thread_key] = dup_context(@context[MainThread])
365
+ end
366
+ end
367
+
368
+ def context_value(name)
369
+ current_context[name]
370
+ end
371
+
372
+ def set_context_value(name, value)
373
+ current_context[name] = value
374
+ end
375
+
376
+ def dup_context(context)
377
+ {
378
+ :turned_off => context[:turned_off],
379
+ :ignore_cassettes => context[:ignore_cassettes].dup,
380
+ :cassettes => context[:cassettes].dup
381
+ }
382
+ end
333
383
 
334
384
  def ignore_cassettes?
335
- @ignore_cassettes
385
+ context_value(:ignore_cassettes)
336
386
  end
337
387
 
338
388
  def cassettes
339
- @cassettes ||= []
389
+ context_value(:cassettes)
390
+ end
391
+
392
+ def initialize_fibers
393
+ begin
394
+ require 'fiber'
395
+ @fibers_available = true
396
+ rescue LoadError
397
+ @fibers_available = false
398
+ end
340
399
  end
341
400
 
342
401
  def initialize_ivars
343
- @turned_off = false
402
+ initialize_fibers
403
+ @context = {
404
+ MainThread => {
405
+ :turned_off => false,
406
+ :ignore_cassettes => [],
407
+ :cassettes => []
408
+ }
409
+ }
410
+ @configuration = Configuration.new
411
+ @request_matchers = RequestMatcherRegistry.new
412
+ @request_ignorer = RequestIgnorer.new
413
+ @library_hooks = LibraryHooks.new
414
+ @cassette_serializers = Cassette::Serializers.new
415
+ @cassette_persisters = Cassette::Persisters.new
344
416
  end
345
417
 
346
418
  initialize_ivars # to avoid warnings