Sha256: fd8b22c90fffd37419c839099b84d86c375fad7c3f9a30f61ad10a3c43b3b3a2

Contents?: true

Size: 990 Bytes

Versions: 35

Compression:

Stored size: 990 Bytes

Contents

require 'webmock/rspec'

module WebMockHelper
  def mock_json(method, endpoint, response_file, options = {})
    stub_request(method, endpoint).with(
      request_for(method, options)
    ).to_return(
      response_for(response_file, options)
    )
    yield
    a_request(method, endpoint).with(
      request_for(method, options)
    ).should have_been_made.once
  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}.#{options[:format] || :json}"))
    if options[:status]
      response[:status] = options[:status]
    end
    response
  end
end

include WebMockHelper
WebMock.disable_net_connect!

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
openid_connect-0.1.5 spec/helpers/webmock_helper.rb
openid_connect-0.1.4 spec/helpers/webmock_helper.rb
openid_connect-0.1.3 spec/helpers/webmock_helper.rb
openid_connect-0.1.2 spec/helpers/webmock_helper.rb
openid_connect-0.1.1 spec/helpers/webmock_helper.rb
openid_connect-0.1.0 spec/helpers/webmock_helper.rb
openid_connect-0.0.33 spec/helpers/webmock_helper.rb
openid_connect-0.0.32 spec/helpers/webmock_helper.rb
openid_connect-0.0.31 spec/helpers/webmock_helper.rb
openid_connect-0.0.30 spec/helpers/webmock_helper.rb
openid_connect-0.0.29 spec/helpers/webmock_helper.rb
openid_connect-0.0.28 spec/helpers/webmock_helper.rb
openid_connect-0.0.27 spec/helpers/webmock_helper.rb
openid_connect-0.0.26 spec/helpers/webmock_helper.rb
openid_connect-0.0.25 spec/helpers/webmock_helper.rb
openid_connect-0.0.24 spec/helpers/webmock_helper.rb
openid_connect-0.0.23 spec/helpers/webmock_helper.rb
openid_connect-0.0.22 spec/helpers/webmock_helper.rb
openid_connect-0.0.21 spec/helpers/webmock_helper.rb
openid_connect-0.0.20 spec/helpers/webmock_helper.rb