Sha256: 9be066e73b143060b34d43affabc5109d806b1db5e239faa4978e8fae15871d4

Contents?: true

Size: 925 Bytes

Versions: 49

Compression:

Stored size: 925 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 = {}
    params = options.try(:[], :params) || {}
    case method
    when :post, :put, :delete
      request[:body] = params
    else
      request[:query] = params
    end
    if options[:request_header]
      request[:headers] = options[:request_header]
    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

49 entries across 49 versions & 1 rubygems

Version Path
rack-oauth2-2.0.1 spec/helpers/webmock_helper.rb
rack-oauth2-2.0.0 spec/helpers/webmock_helper.rb
rack-oauth2-2.0.0.rc3 spec/helpers/webmock_helper.rb
rack-oauth2-2.0.0.rc2 spec/helpers/webmock_helper.rb
rack-oauth2-2.0.0.rc1 spec/helpers/webmock_helper.rb
rack-oauth2-1.21.3 spec/helpers/webmock_helper.rb
rack-oauth2-1.21.2 spec/helpers/webmock_helper.rb
rack-oauth2-1.21.1 spec/helpers/webmock_helper.rb
rack-oauth2-1.21.0 spec/helpers/webmock_helper.rb
rack-oauth2-1.20.0 spec/helpers/webmock_helper.rb
rack-oauth2-1.19.0 spec/helpers/webmock_helper.rb
rack-oauth2-1.18.0 spec/helpers/webmock_helper.rb
rack-oauth2-1.17.0 spec/helpers/webmock_helper.rb
rack-oauth2-1.16.0 spec/helpers/webmock_helper.rb
rack-oauth2-1.15.0 spec/helpers/webmock_helper.rb
rack-oauth2-1.14.0 spec/helpers/webmock_helper.rb
rack-oauth2-1.13.0 spec/helpers/webmock_helper.rb
rack-oauth2-1.13.0.beta spec/helpers/webmock_helper.rb
rack-oauth2-1.12.0 spec/helpers/webmock_helper.rb
rack-oauth2-1.11.0 spec/helpers/webmock_helper.rb