forked from vcr/vcr
/
spec_helper.rb
91 lines (69 loc) · 2.27 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require 'rubygems'
using_git = File.exist?(File.expand_path('../../.git/', __FILE__))
if using_git
require 'bundler'
Bundler.setup
end
require 'rspec'
# Ruby 1.9.1 has a different yaml serialization format.
YAML_SERIALIZATION_VERSION = RUBY_VERSION == '1.9.1' ? '1.9.1' : 'not_1.9.1'
Dir['./spec/support/**/*.rb'].each { |f| require f }
require 'vcr'
require 'monkey_patches'
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
end
end
end
RSpec.configure do |config|
config.color_enabled = true
config.debug = (using_git && RUBY_INTERPRETER == :mri && RUBY_VERSION != '1.9.1')
config.treat_symbols_as_metadata_keys_with_true_values = true
tmp_dir = File.expand_path('../../tmp/cassette_library_dir', __FILE__)
config.before(:each) do
VCR::Config.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!
FakeWeb.allow_net_connect = true
FakeWeb.clean_registry
VCR::HttpStubbingAdapters::Faraday.reset!
VCR::HttpStubbingAdapters::Excon.reset!
end
config.after(:each) do
FileUtils.rm_rf tmp_dir
VCR::HttpStubbingAdapters::Common.adapters.each do |a|
a.ignored_hosts = []
end
end
config.before(:all, :disable_warnings => true) do
@orig_std_err = $stderr
$stderr = StringIO.new
end
config.after(:all, :disable_warnings => true) do
$stderr = @orig_std_err
end
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
config.alias_it_should_behave_like_to :it_performs, 'it performs'
end
http_stubbing_dir = File.join(File.dirname(__FILE__), '..', 'lib', 'vcr', 'http_stubbing_adapters')
Dir[File.join(http_stubbing_dir, '*.rb')].each do |file|
next if RUBY_INTERPRETER != :mri && file =~ /(typhoeus)/
require "vcr/http_stubbing_adapters/#{File.basename(file)}"
end