1 |
8db5edf8
|
Eric D Helms
|
require 'rubygems'
|
2 |
|
|
require 'vcr'
|
3 |
|
|
|
4 |
3e3ad61c
|
Partha Aji
|
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 |
0f799794
|
Eric D. Helms
|
end
|
8 |
|
|
|
9 |
926b9789
|
Justin Sherrill
|
if mode != :none
|
10 |
|
|
unless system("sudo cp -rf #{File.dirname(__FILE__)}/fixtures/repositories /var/www/")
|
11 |
|
|
fail "Cannot copy repository fixtures to /var/www, ensure sudo access"
|
12 |
|
|
end
|
13 |
61c9e238
|
Partha Aji
|
unless system("sudo tar zxf /var/www/repositories/ostree/*.tgz -C /var/www/repositories/ostree")
|
14 |
|
|
fail "Could not extract the ostree repo"
|
15 |
|
|
end
|
16 |
|
|
|
17 |
926b9789
|
Justin Sherrill
|
end
|
18 |
|
|
|
19 |
8db5edf8
|
Eric D Helms
|
VCR.configure do |c|
|
20 |
634c90e7
|
Eric D. Helms
|
c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
|
21 |
8db5edf8
|
Eric D Helms
|
c.hook_into :webmock
|
22 |
0f799794
|
Eric D. Helms
|
|
23 |
3e3ad61c
|
Partha Aji
|
if ENV['record'] == 'false' && mode != :none
|
24 |
63540c7c
|
Eric D. Helms
|
uri = URI.parse(TestRuncible.server.config[:url])
|
25 |
0f799794
|
Eric D. Helms
|
c.ignore_hosts uri.host
|
26 |
|
|
end
|
27 |
|
|
|
28 |
634c90e7
|
Eric D. Helms
|
c.default_cassette_options = {
|
29 |
0f799794
|
Eric D. Helms
|
:record => mode,
|
30 |
926b9789
|
Justin Sherrill
|
:match_requests_on => [:method, :path, :params, :body_json],
|
31 |
|
|
:decode_compressed_response => true
|
32 |
634c90e7
|
Eric D. Helms
|
}
|
33 |
|
|
|
34 |
|
|
begin
|
35 |
|
|
c.register_request_matcher :body_json do |request_1, request_2|
|
36 |
|
|
begin
|
37 |
50bf07ad
|
Eric D. Helms
|
json_1 = JSON.parse(request_1.body)
|
38 |
634c90e7
|
Eric D. Helms
|
json_2 = JSON.parse(request_2.body)
|
39 |
|
|
|
40 |
|
|
json_1 == json_2
|
41 |
|
|
rescue
|
42 |
|
|
|
43 |
|
|
request_1.body == request_2.body
|
44 |
|
|
end
|
45 |
|
|
end
|
46 |
f8bc785b
|
Partha Aji
|
rescue
|
47 |
634c90e7
|
Eric D. Helms
|
|
48 |
|
|
end
|
49 |
|
|
|
50 |
|
|
begin
|
51 |
|
|
c.register_request_matcher :params do |request_1, request_2|
|
52 |
|
|
URI(request_1.uri).query == URI(request_2.uri).query
|
53 |
|
|
end
|
54 |
f8bc785b
|
Partha Aji
|
rescue
|
55 |
634c90e7
|
Eric D. Helms
|
|
56 |
|
|
end
|
57 |
8db5edf8
|
Eric D Helms
|
end
|
58 |
|
|
end |