Sha256: 66ac0cde411af386b4f9c3bcf82e117d3fb265992740a87a4ecc58bfc6167d14

Contents?: true

Size: 679 Bytes

Versions: 7

Compression:

Stored size: 679 Bytes

Contents

require 'webmock/rspec'

module FakeResponseHelper

  def fake_response(file_path, api = :NVP)
    endpoint = case api
    when :NVP
      Paypal::NVP::Request.endpoint
    when :IPN
      Paypal::IPN.endpoint
    else
      raise "Non-supported API: #{api}"
    end
    stub_request(:post, endpoint)
      .to_return(
        body: File.read(File.join(File.dirname(__FILE__), '../fake_response', "#{file_path}.txt"))
      )
  end

  def request_to(endpoint, method = :get)
    raise_error(
      WebMock::NetConnectNotAllowedError,
      /Real HTTP connections are disabled. Unregistered request: #{method.to_s.upcase} #{endpoint}/
    )
  end

end

include FakeResponseHelper

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ianfleeton-paypal-express-1.0.0 spec/helpers/fake_response_helper.rb
ianfleeton-paypal-express-0.8.7 spec/helpers/fake_response_helper.rb
ianfleeton-paypal-express-0.8.6 spec/helpers/fake_response_helper.rb
ianfleeton-paypal-express-0.8.5 spec/helpers/fake_response_helper.rb
ianfleeton-paypal-express-0.8.4 spec/helpers/fake_response_helper.rb
ianfleeton-paypal-express-0.8.3 spec/helpers/fake_response_helper.rb
ianfleeton-paypal-express-0.8.2 spec/helpers/fake_response_helper.rb