Sha256: 447eb5a5e556d583b9012eeaedc9cad0acfe93c8718867396d0681910b2a1dfc
Contents?: true
Size: 979 Bytes
Versions: 13
Compression:
Stored size: 979 Bytes
Contents
require 'webmock/rspec' module WebMockHelper def mock_response(method, endpoint, response_file, options = {}) stub_request(method, endpoint).with( request_for(method, options) ).to_return( response_for(response_file, options) ) end private def request_for(method, options = {}) request = {} if options[:access_token] options[:params] ||= {} options[:params][:oauth_token] = options[:access_token].to_s end if options[:params] case method when :post, :put request[:body] = options[:params] else request[:query] = options[:params] end end request end def response_for(response_file, options = {}) response = {} response[:body] = File.new(File.join(File.dirname(__FILE__), '../mock_response', response_file)) if options[:status] response[:status] = options[:status] end response end end include WebMockHelper WebMock.disable_net_connect!
Version data entries
13 entries across 13 versions & 1 rubygems