Sha256: 0dfa57491ec36961edfc5d7d96dcedb38fd06d9ce2077daaddbe4d62092dff0a

Contents?: true

Size: 1.97 KB

Versions: 12

Compression:

Stored size: 1.97 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))

class TestCurl < Test::Unit::TestCase
  def test_get
    curl = Curl.get(TestServlet.url, {:foo => "bar"})
    assert_equal "GETfoo=bar", curl.body_str

    curl = Curl.options(TestServlet.url, {:foo => "bar"}) do|http|
      http.headers['Cookie'] = 'foo=1;bar=2'
    end
    assert_equal "OPTIONSfoo=bar", curl.body_str
  end

  def test_post
    curl = Curl.post(TestServlet.url, {:foo => "bar"})
    assert_equal "POST\nfoo=bar",  curl.body_str
  end

  def test_put
    curl = Curl.put(TestServlet.url, {:foo => "bar"})
    assert_equal "PUT\nfoo=bar",  curl.body_str
  end

  def test_patch
    curl = Curl.patch(TestServlet.url, {:foo => "bar"})
    assert_equal "PATCH\nfoo=bar", curl.body_str
  end

  def test_options
    curl = Curl.options(TestServlet.url, {:foo => "bar"})
    assert_equal "OPTIONSfoo=bar", curl.body_str
  end

  def test_urlalize_without_extra_params
    url_no_params = 'http://localhost/test'
    url_with_params = 'http://localhost/test?a=1'

    assert_equal(url_no_params, Curl.urlalize(url_no_params))
    assert_equal(url_with_params, Curl.urlalize(url_with_params))
  end

  def test_urlalize_with_nil_as_params
    url = 'http://localhost/test'
    assert_equal(url, Curl.urlalize(url, nil))
  end

  def test_urlalize_with_extra_params
    url_no_params = 'http://localhost/test'
    url_with_params = 'http://localhost/test?a=1'
    extra_params = { :b => 2 }

    expected_url_no_params = 'http://localhost/test?b=2'
    expected_url_with_params = 'http://localhost/test?a=1&b=2'

    assert_equal(expected_url_no_params, Curl.urlalize(url_no_params, extra_params))
    assert_equal(expected_url_with_params, Curl.urlalize(url_with_params, extra_params))
  end

  def test_urlalize_does_not_strip_trailing_?
    url_empty_params = 'http://localhost/test?'
    assert_equal(url_empty_params, Curl.urlalize(url_empty_params))
  end

  include TestServerMethods

  def setup
    server_setup
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
curb-1.0.6 tests/tc_curl.rb
curb-1.0.5 tests/tc_curl.rb
curb-1.0.4 tests/tc_curl.rb
curb-1.0.3 tests/tc_curl.rb
curb-1.0.2 tests/tc_curl.rb
curb-1.0.1 tests/tc_curl.rb
curb-1.0.0 tests/tc_curl.rb
curb-0.9.11 tests/tc_curl.rb
curb-0.9.10 tests/tc_curl.rb
curb-0.9.9 tests/tc_curl.rb
curb-0.9.8 tests/tc_curl.rb
curb-0.9.7 tests/tc_curl.rb