Sha256: 39b1694b5b36020102464f294f2e31c3fb586f16003a36dad4a4a1a0205ba29f

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

require File.expand_path("../test_helper", __dir__)

class SearchFlip::HTTPClientTest < SearchFlip::TestCase
  [:get, :put, :delete, :post, :head].each do |method|
    define_method :"test_#{method}" do
      stub_request(method, "http://localhost/path").with(body: "body", query: { key: "value" }).to_return(body: "success")

      assert_equal "success", SearchFlip::HTTPClient.send(method, "http://localhost/path", body: "body", params: { key: "value" }).body.to_s
    end
  end

  def test_headers
    stub_request(:get, "http://localhost/path").with(headers: { "X-Key" => "Value" }).to_return(body: "success")

    assert_equal "success", SearchFlip::HTTPClient.headers("X-Key" => "Value").get("http://localhost/path").body.to_s
  end

  def test_connection_error
    stub_request(:get, "http://localhost/path").to_raise(HTTP::ConnectionError)

    assert_raises SearchFlip::ConnectionError do
      SearchFlip::HTTPClient.get("http://localhost/path")
    end
  end

  def test_response_error
    stub_request(:get, "http://localhost/path").to_return(status: 500)

    assert_raises SearchFlip::ResponseError do
      SearchFlip::HTTPClient.get("http://localhost/path")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
search_flip-2.0.0.beta2 test/search_flip/http_client_test.rb
search_flip-2.0.0.beta test/search_flip/http_client_test.rb