Sha256: 1abfa0e7e8ce769391fed9b1cf93809dd055a5ae738f4167221765468f55c8ba

Contents?: true

Size: 1.69 KB

Versions: 6

Compression:

Stored size: 1.69 KB

Contents

class TestClient < Test::Unit::TestCase
  def setup
    stub(Yao.config).debug { false }
    stub(Yao.config).debug_record_response { false }
  end

  def test_gen_client
    cli = Yao::Client.gen_client("http://cool-api.example.com:12345/v3.0")
    assert { cli.url_prefix.to_s == "http://cool-api.example.com:12345/v3.0" }

    handlers = [
      Faraday::Request::Accept,
      Faraday::Request::UrlEncoded,
      Faraday::Request::ReadOnly,
      Faraday::Response::OSErrorDetector,
      FaradayMiddleware::ParseJson,
      Faraday::Adapter::NetHttp
    ]
    assert { cli.builder.handlers == handlers }
  end

  def test_gen_with_token
    cli = Yao::Client.gen_client("http://cool-api.example.com:12345/v3.0", token: "deadbeaf")
    handlers = [
      Faraday::Request::Accept,
      Faraday::Request::UrlEncoded,
      Faraday::Request::OSToken,
      Faraday::Request::ReadOnly,
      Faraday::Response::OSErrorDetector,
      FaradayMiddleware::ParseJson,
      Faraday::Adapter::NetHttp
    ]
    assert { cli.builder.handlers == handlers }
  end

  def test_debug_mode
    stub(Yao.config).debug { true }

    cli = Yao::Client.gen_client("http://cool-api.example.com:12345/v3.0")
    handlers = [
      Faraday::Request::Accept,
      Faraday::Request::UrlEncoded,
      Faraday::Request::ReadOnly,
      Faraday::Response::OSErrorDetector,
      FaradayMiddleware::ParseJson,
      Faraday::Response::Logger,
      Faraday::Response::OSDumper,
      Faraday::Adapter::NetHttp
    ]
    assert { cli.builder.handlers == handlers }
  end

  def test_timeout
    stub(Yao.config).timeout { 300 }
    cli = Yao::Client.gen_client("http://cool-api.example.com:12345/v3.0")
    assert { cli.options.timeout == 300 }
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
yao-0.3.1 test/yao/test_client.rb
yao-0.3.0 test/yao/test_client.rb
yao-0.2.13 test/yao/test_client.rb
yao-0.2.12 test/yao/test_client.rb
yao-0.2.11 test/yao/test_client.rb
yao-0.2.10 test/yao/test_client.rb