Sha256: 91537a1374706450ca44f41b73bb5d3198ddf513f6576a36e850069efb6571c6

Contents?: true

Size: 844 Bytes

Versions: 14

Compression:

Stored size: 844 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[: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

14 entries across 14 versions & 1 rubygems

Version Path
rack-oauth2-0.14.2 spec/helpers/webmock_helper.rb
rack-oauth2-0.14.1 spec/helpers/webmock_helper.rb
rack-oauth2-0.14.0 spec/helpers/webmock_helper.rb
rack-oauth2-0.13.0 spec/helpers/webmock_helper.rb
rack-oauth2-0.12.2 spec/helpers/webmock_helper.rb
rack-oauth2-0.12.1 spec/helpers/webmock_helper.rb
rack-oauth2-0.12.0 spec/helpers/webmock_helper.rb
rack-oauth2-0.11.0 spec/helpers/webmock_helper.rb
rack-oauth2-0.10.1 spec/helpers/webmock_helper.rb
rack-oauth2-0.10.0 spec/helpers/webmock_helper.rb
rack-oauth2-0.10.0.alpha spec/helpers/webmock_helper.rb
rack-oauth2-0.9.5 spec/helpers/webmock_helper.rb
rack-oauth2-0.9.4 spec/helpers/webmock_helper.rb
rack-oauth2-0.9.3 spec/helpers/webmock_helper.rb