Sha256: a2880d15ae637f54c4ef94ab8e6058b8c74c4244ef6c600dafda8dd6ab71bf49
Contents?: true
Size: 890 Bytes
Versions: 2
Compression:
Stored size: 890 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.1 | spec/helpers/webmock_helper.rb |
swd-2.0.0 | spec/helpers/webmock_helper.rb |