Skip to content

Commit 355e028

Browse files
committed
Adding spec common_helpers
1 parent 937e703 commit 355e028

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

spec/support/common_helpers.rb

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module Quickpay
2+
module CommonHelpers
3+
4+
def secret
5+
'foo:bar'
6+
end
7+
8+
def url_with_secret
9+
"https://#{secret}@#{Quickpay::BASE_URI.split('://').last}"
10+
end
11+
12+
def stub_qp_request(method, path, status, response_body)
13+
url = URI.join(url_with_secret, path)
14+
15+
stub_request(method, url)
16+
.with(:headers => headers)
17+
.to_return(:status => status, :body => response_body.to_json)
18+
19+
end
20+
21+
def expect_qp_request(method, path, body)
22+
url = URI.join(url_with_secret, path)
23+
24+
expect(WebMock).to have_requested(method, url).with(
25+
:body => body,
26+
:headers => headers)
27+
end
28+
29+
def headers
30+
user_agent = "quickpay-ruby-client, v#{Quickpay::VERSION}"
31+
user_agent += ", #{RUBY_VERSION}, #{RUBY_PLATFORM}, #{RUBY_PATCHLEVEL}"
32+
if defined?(RUBY_ENGINE)
33+
user_agent += ", #{RUBY_ENGINE}"
34+
end
35+
36+
{ "Accept-Version" => "v10",
37+
"User-Agent" => user_agent
38+
}
39+
end
40+
end
41+
end

0 commit comments

Comments
 (0)