forked from vcr/vcr
-
Notifications
You must be signed in to change notification settings - Fork 15
/
config.rb
78 lines (63 loc) · 2.15 KB
/
config.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
require 'fileutils'
require 'vcr/util/hooks'
module VCR
module Config
include VCR::Hooks
include VCR::VariableArgsBlockCaller
extend self
define_hook :before_record
define_hook :before_playback
attr_reader :cassette_library_dir
def cassette_library_dir=(cassette_library_dir)
@cassette_library_dir = cassette_library_dir
FileUtils.mkdir_p(cassette_library_dir) if cassette_library_dir
end
attr_writer :default_cassette_options
def default_cassette_options
@default_cassette_options ||= {}
@default_cassette_options[:match_requests_on] ||= RequestMatcher::DEFAULT_MATCH_ATTRIBUTES
@default_cassette_options[:record] ||= :once
@default_cassette_options
end
def stub_with(*http_stubbing_libraries)
@http_stubbing_libraries = http_stubbing_libraries
end
def http_stubbing_libraries
@http_stubbing_libraries ||= []
end
def ignore_hosts(*hosts)
ignored_hosts.push(*hosts).uniq!
VCR.http_stubbing_adapter.ignored_hosts = ignored_hosts if http_stubbing_libraries.any?
end
alias ignore_host ignore_hosts
def ignored_hosts
@ignored_hosts ||= []
end
def ignore_localhost=(value)
if value
ignore_hosts *VCR::LOCALHOST_ALIASES
else
ignored_hosts.reject! { |h| VCR::LOCALHOST_ALIASES.include?(h) }
end
end
def allow_http_connections_when_no_cassette=(value)
@allow_http_connections_when_no_cassette = value
VCR.http_stubbing_adapter.set_http_connections_allowed_to_default if http_stubbing_libraries.any?
end
def allow_http_connections_when_no_cassette?
!!@allow_http_connections_when_no_cassette
end
def filter_sensitive_data(placeholder, tag = nil, &block)
before_record(tag) do |interaction|
interaction.filter!(call_block(block, interaction), placeholder)
end
before_playback(tag) do |interaction|
interaction.filter!(placeholder, call_block(block, interaction))
end
end
def uri_should_be_ignored?(uri)
uri = URI.parse(uri) unless uri.respond_to?(:host)
ignored_hosts.include?(uri.host)
end
end
end