Sha256: 1ae2a9696e2dde0a050c701fc1f8aae8de126657aeebdb5f63d1ad216d8bdaa5
Contents?: true
Size: 1.56 KB
Versions: 4
Compression:
Stored size: 1.56 KB
Contents
require 'webmock/rspec' module StubHelper def initialize(*args) @base_url = 'http://www.example.com/' end def mock_get(url, response_headers = {}, status = 200) stub_request(:get, @base_url + url).to_return(headers: response_headers, body: get_json_response_file(url), status: status) end def mock_post(url, options = {}, status = 200) stub_request(:post, @base_url + url).with(body: options[:request_body] || {}) .to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url), status: status) end def mock_put(url, options = {}, status = 200) stub_request(:put, @base_url + url).with(body: options[:request_body] || {}) .to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url), status: status) end def mock_patch(url, options = {}, status = 200) stub_request(:patch, @base_url + url).with(body: options[:request_body] || {}) .to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url), status: status) end def mock_delete(url) stub_request(:delete, @base_url + url) end def mock_head(url, response_headers = {}, status = 200) stub_request(:head, @base_url + url).to_return(headers: response_headers, body: nil, status: status) end def mock_options(url, response_headers = {}, status = 200) stub_request(:options, @base_url + url).to_return(headers: response_headers, body: nil, status: status) end private def get_json_response_file(name) IO.read(File.join('spec/test_responses', name + ".json")) end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
airborne-0.1.15 | spec/stub_helper.rb |
airborne-0.1.14 | spec/stub_helper.rb |
airborne-0.1.13 | spec/stub_helper.rb |
airborne-0.1.12 | spec/stub_helper.rb |