File: test_rubyforge_client.rb

package info (click to toggle)
ruby-rubyforge 2.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 116 kB
  • ctags: 87
  • sloc: ruby: 811; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,363 bytes parent folder | download
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
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'test/unit' unless defined? $ZENTEST and $ZENTEST
require 'rubyforge'

class RubyForge::FakeAgent
  class << self
    attr_accessor :t_data, :t_request
  end

  def initialize(*args)
  end

  def request(request, data)
    self.class.t_request = request
    self.class.t_data = data
    response = Net::HTTPOK.new('1.1', 200, '')
    def response.read_body; ''; end
    return response
  end

  class Post
    def initialize(*args)
      @args = args
      @stuff = {}
    end

    def [] key
      @stuff[key.downcase]
    end

    def []= key, val
      @stuff[key.downcase] = val
    end

    def method_missing(*stuff)
      # warn stuff.inspect
    end
  end
end

class TestRubyForgeClient < Test::Unit::TestCase
  def setup
    @client                        = RubyForge::Client.new
    @client.agent_class            = RubyForge::FakeAgent
    RubyForge::FakeAgent.t_data    = :unassigned
    RubyForge::FakeAgent.t_request = :unassigned
  end

  def test_post_with_params
    @client.post_content('http://example.com', { :f => 'adsf aoeu'}, {}, {"username" => "tom", "password" => "secret"})
    assert_equal('f=adsf+aoeu', RubyForge::FakeAgent.t_data)

    @client.post_content('http://example.com', { :a => 'b', :c => 'd' }, {}, {"username" => "tom", "password" => "secret"})
    assert_equal('a=b&c=d', RubyForge::FakeAgent.t_data)
  end


end