hammer-cli-csv / test / vcr_setup.rb @ b50ceaa2
1 |
require 'rubygems'
|
---|---|
2 |
require 'vcr'
|
3 |
|
4 |
def configure_vcr(mode = :none) |
5 |
if ENV['record'] == 'false' && mode == :none |
6 |
fail "Record flag is not applicable for mode 'none', please use with 'mode=all'"
|
7 |
end
|
8 |
|
9 |
VCR.configure do |c| |
10 |
c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
|
11 |
c.hook_into :webmock
|
12 |
|
13 |
if ENV['record'] == 'false' && mode != :none |
14 |
server = HammerCLI::Settings.get(:csv, :host) || |
15 |
HammerCLI::Settings.get(:katello, :host) || |
16 |
HammerCLI::Settings.get(:foreman, :host) |
17 |
uri = URI.parse(server)
|
18 |
c.ignore_hosts uri.host |
19 |
end
|
20 |
|
21 |
c.default_cassette_options = { |
22 |
:record => mode,
|
23 |
:match_requests_on => [:method, :path, :params, :body_json], |
24 |
:decode_compressed_response => true |
25 |
} |
26 |
|
27 |
# rubocop:disable HandleExceptions
|
28 |
begin
|
29 |
c.register_request_matcher :body_json do |request_1, request_2| |
30 |
begin
|
31 |
json_1 = JSON.parse(request_1.body)
|
32 |
json_2 = JSON.parse(request_2.body)
|
33 |
|
34 |
json_1 == json_2 |
35 |
rescue
|
36 |
#fallback incase there is a JSON parse error
|
37 |
request_1.body == request_2.body |
38 |
end
|
39 |
end
|
40 |
rescue
|
41 |
#ignore the warning thrown about this matcher already being resgistered
|
42 |
end
|
43 |
|
44 |
begin
|
45 |
c.register_request_matcher :params do |request_1, request_2| |
46 |
URI(request_1.uri).query == URI(request_2.uri).query |
47 |
end
|
48 |
rescue
|
49 |
#ignore the warning thrown about this matcher already being resgistered
|
50 |
end
|
51 |
# rubocop:enable HandleExceptions
|
52 |
end
|
53 |
end
|