Sha256: 453df34a2a10913e454a0248d24280f504cc139c8eb87e527c3957572a841f8b

Contents?: true

Size: 1.44 KB

Versions: 19

Compression:

Stored size: 1.44 KB

Contents

require 'helper'

module Bixby
module Test

class TestHttpClient < TestCase

  include WebMock::API

  def teardown
    super
    WebMock.reset!
  end

  class Foo
    include Bixby::HttpClient
  end

  def test_http_get
    stub_request(:get, "http://www.google.com/").
      to_return(:status => 200, :body => "foobar", :headers => {})
    body = Foo.new.http_get("http://www.google.com")
    assert_equal "foobar", body
  end

  def test_http_post
    stub_request(:post, "http://www.google.com/").
      with(:body => "foo=bar").
      to_return(:status => 200, :body => "foobar", :headers => {})
    body = Foo.new.http_post("http://www.google.com", {:foo => "bar"})
    assert_equal "foobar", body
  end

  def test_http_post_json
    # string bodies should pass through directly
    stub_request(:post, "http://www.google.com/").
      with(:body => "{\"foo\":\"bar\"}").
      to_return(:status => 200, :body => "foobar", :headers => {})
    body = Foo.new.http_post("http://www.google.com", MultiJson.dump({:foo => "bar"}))
    assert_equal "foobar", body
  end

  def test_http_post_download
    stub_request(:post, "http://www.google.com/").
      with(:body => "fooey").
      to_return(:status => 200, :body => "baznab", :headers => {})

    tmp = Tempfile.new("bc-post-")
    body = Foo.new.http_post_download("http://www.google.com", "fooey", tmp.path)

    s = File.read(tmp.path)
    assert_equal "baznab", s
  end

end # TestHttpClient

end # Test
end # Bixby

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
bixby-common-0.7.1 test/util/http_client_test.rb
bixby-common-0.7.0 test/util/http_client_test.rb
bixby-common-0.6.6 test/util/http_client_test.rb
bixby-common-0.6.5 test/util/http_client_test.rb
bixby-common-0.6.4 test/util/http_client_test.rb
bixby-common-0.6.3 test/util/http_client_test.rb
bixby-common-0.6.2 test/util/http_client_test.rb
bixby-common-0.6.1 test/util/http_client_test.rb
bixby-common-0.6.0 test/util/http_client_test.rb
bixby-common-0.5.0 test/util/http_client_test.rb
bixby-common-0.4.13 test/util/http_client_test.rb
bixby-common-0.4.12 test/util/http_client_test.rb
bixby-common-0.4.11 test/util/http_client_test.rb
bixby-common-0.4.10 test/util/http_client_test.rb
bixby-common-0.4.9 test/util/http_client_test.rb
bixby-common-0.4.8 test/util/http_client_test.rb
bixby-common-0.4.7 test/util/http_client_test.rb
bixby-common-0.4.6 test/util/http_client_test.rb
bixby-common-0.4.5 test/util/http_client_test.rb