Sha256: 49d448bfab6b5d094124462e9c67c83fe5170dfd4aaa203b742c243529777a5f
Contents?: true
Size: 888 Bytes
Versions: 2
Compression:
Stored size: 888 Bytes
Contents
require 'webmock/rspec' module WebMockHelper def mock_json(endpoint, response_file, options = {}) endpoint = endpoint.to_s stub_request(:get, endpoint).with( request_for(options) ).to_return( response_for(response_file, options) ) yield a_request(:get, endpoint).with( request_for(options) ).should have_been_made.once end private def request_for(options = {}) request = {} request[:query] = options[:query] request end def response_for(response_file, options = {}) response = {} response[:headers] = { 'Content-Type': 'application/json' } response[:body] = File.new(File.join(File.dirname(__FILE__), '../mock_json', "#{response_file}.json")) if options[:status] response[:status] = options[:status] end response end end include WebMockHelper WebMock.disable_net_connect!
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
swd-2.0.3 | spec/helpers/webmock_helper.rb |
swd-2.0.2 | spec/helpers/webmock_helper.rb |