Sha256: 328735a26eda9bfba2e36e326055279780b2043914651ce0378a41e4574ccd39

Contents?: true

Size: 848 Bytes

Versions: 2

Compression:

Stored size: 848 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 = {}
    if options[:query]
      request[:query] = options[:query]
    end
    request
  end

  def response_for(response_file, options = {})
    response = {}
    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
webfinger-2.1.0 spec/helpers/webmock_helper.rb
webfinger-2.0.0 spec/helpers/webmock_helper.rb