forked from jtarchie/github-pullrequest-resource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_helper.rb
82 lines (68 loc) · 2.06 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
require 'billy'
require 'open3'
Billy.configure do |c|
c.cache = true
c.merge_cached_responses_whitelist = [/github/]
c.non_successful_error_level = :error
c.non_whitelisted_requests_disabled = true
end
module StubCacheHandler
def handle_request(method, url, headers, body)
if response = super
Billy::Cache.instance.store(method.downcase, url, headers, body, response[:headers], response[:status], response[:content])
return response
end
end
end
Billy::StubHandler.prepend(StubCacheHandler)
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
end
def check(payload)
path = ['./assets/check', '/opt/resource/check'].find { |p| File.exist? p }
payload[:source][:no_ssl_verify] = true
output = `echo '#{JSON.generate(payload)}' | env http_proxy=#{proxy.url} #{path}`
JSON.parse(output)
end
def get(payload = {})
path = ['./assets/in', '/opt/resource/in'].find { |p| File.exist? p }
payload[:source][:no_ssl_verify] = true
output, error, = with_resource do |_dir|
Open3.capture3("echo '#{JSON.generate(payload)}' | env http_proxy=#{proxy.url} #{path} #{dest_dir}")
end
[(begin
JSON.parse(output)
rescue
nil
end), error]
end
def put(payload = {})
path = ['./assets/out', '/opt/resource/out'].find { |p| File.exist? p }
payload[:source][:no_ssl_verify] = true
output, error, = with_resource do |dir|
Open3.capture3("echo '#{JSON.generate(payload)}' | env http_proxy=#{proxy.url} #{path} #{dir}")
end
[(begin
JSON.parse(output)
rescue
nil
end), error]
end
def with_resource
tmp_dir = Dir.mktmpdir
FileUtils.cp_r(dest_dir, File.join(tmp_dir, 'resource'))
yield(tmp_dir)
end
def must_stub_query_params
around do |example|
old_strip_params = Billy.config.strip_query_params
Billy.config.strip_query_params = false
example.run
Billy.config.strip_query_params = old_strip_params
end
end