summaryrefslogtreecommitdiff
path: root/test/support/http_stub_helper.rb
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-09-12 16:34:25 +0200
committerAzul <azul@riseup.net>2016-09-12 16:34:57 +0200
commitec875169b0231d84bb8c55bbe91c52b896561f1e (patch)
treebb4b47a79d32744bda8d66b2c02e9343bfc61698 /test/support/http_stub_helper.rb
parentbc8ddfa1c49b438a563a8a8b9e0472944f71c71c (diff)
test: separate remote tests into own directory
Dropped the webmock dependency. We have our own http adapter. So we can stub that to inject a mock. As an added bonus this does not mess with other http requests. Also wrote down testing strategy. Not completely implemented yet.
Diffstat (limited to 'test/support/http_stub_helper.rb')
-rw-r--r--test/support/http_stub_helper.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/support/http_stub_helper.rb b/test/support/http_stub_helper.rb
new file mode 100644
index 0000000..6b05f98
--- /dev/null
+++ b/test/support/http_stub_helper.rb
@@ -0,0 +1,38 @@
+module HttpStubHelper
+
+ def stubbing_http
+ Nickserver::Adapters::CelluloidHttp.stub :new, adapter do
+ yield
+ end
+ adapter.verify
+ end
+
+ def stub_sks_vindex_reponse(uid, response = {})
+ stub_http_request :get, config.hkp_url,
+ query: {op: 'vindex', search: uid, exact: 'on', options: 'mr', fingerprint: 'on'},
+ response: response
+ end
+
+ def stub_sks_get_reponse(key_id, response = {})
+ stub_http_request :get, config.hkp_url,
+ query: {op: 'get', search: "0x"+key_id, exact: 'on', options: 'mr'},
+ response: response
+ end
+
+ def stub_couch_response(uid, response = {})
+ query = "\?key=#{"%22#{uid}%22"}&reduce=false"
+ stub_http_request :get,
+ /#{Regexp.escape(config.couch_url)}.*#{query}/,
+ response: response
+ end
+
+ def stub_http_request(verb, url, options = {})
+ response = {status: 200, body: ""}.merge(options.delete(:response) || {})
+ adapter.expect :get, [response[:status], response[:body]],
+ [url, options]
+ end
+
+ def adapter
+ @adapter ||= MiniTest::Mock.new
+ end
+end