Sha256: f0c342013cd7577db58dd4fe5bd3e1f745cce21255ec1b651cf409f532b3be83

Contents?: true

Size: 795 Bytes

Versions: 1

Compression:

Stored size: 795 Bytes

Contents

require 'webmock/rspec'

module ViaCep
  module Test
    module RequestMocker
      def mock_viacep_success
        WebMock.stub_request(:get, /viacep/).to_return(File.new("#{__dir__}/viacep_success.txt"))
      end

      def mock_viacep_not_found
        WebMock.stub_request(:get, /viacep/).to_return(File.new("#{__dir__}/viacep_not_found.txt"))
      end

      def mock_viacep_invalid_format
        WebMock.stub_request(:get, /viacep/).to_return(File.new("#{__dir__}/viacep_invalid_format.txt"))
      end

      def mock_viacep_slow_success(delay_in_seconds:)
        success = lambda do |request|
          sleep delay_in_seconds
          File.new("#{__dir__}/viacep_success.txt")
        end

        WebMock.stub_request(:get, /viacep/).to_return(success)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
viacep-2.0.3 spec/mock/request_mocker.rb