summaryrefslogtreecommitdiffstats
path: root/test/net_test.rb
blob: e00d16adc021864574ff1be60e8804d2b839f001 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'test_helper'

class NetTest < HCl::TestCase

  def test_configure
    assert_equal 'bob', HCl::Net.login
    assert_equal 'secret', HCl::Net.password
    assert_equal 'bobclock', HCl::Net.subdomain
    assert_equal true, HCl::Net.ssl
  end

  def test_http_deep_unescape
    FakeWeb.register_uri(:get, "https://bob:secret@bobclock.harvestapp.com/foo",
                         :body => Yajl::Encoder.encode({
      status:'gotten &amp; got!',
      comparisons:['burrito &gt; taco', 'rain &lt; sun']
    }))
    body = HCl::Net.get 'foo'
    assert_equal 'gotten & got!', body[:status]
    assert_equal 'burrito > taco', body[:comparisons][0]
    assert_equal 'rain < sun', body[:comparisons][1]
  end

  def test_http_get
    FakeWeb.register_uri(:get, "https://bob:secret@bobclock.harvestapp.com/foo",
                         :body => 'gotten!'.inspect)
    body = HCl::Net.get 'foo'
    assert_equal 'gotten!', body
  end

  def test_http_post
    FakeWeb.register_uri(:post, "https://bob:secret@bobclock.harvestapp.com/foo",
                         :body => 'posted!'.inspect)
    body = HCl::Net.post 'foo', {pizza:'taco'}
    assert_equal 'posted!', body
  end

  def test_http_delete
    FakeWeb.register_uri(:delete, "https://bob:secret@bobclock.harvestapp.com/foo",
                         :body => 'wiped!'.inspect)
    body = HCl::Net.delete 'foo'
    assert_equal 'wiped!', body
  end
end