File: tag_test.rb

package info (click to toggle)
libwww-delicious-ruby 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 320 kB
  • ctags: 366
  • sloc: ruby: 2,178; xml: 106; makefile: 2
file content (69 lines) | stat: -rw-r--r-- 1,454 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
58
59
60
61
62
63
64
65
66
67
68
69
# 
# = WWW::Delicious
#
# Ruby client for del.icio.us API.
# 
#
# Category::    WWW
# Package::     WWW::Delicious
# Author::      Simone Carletti <weppos@weppos.net>
# License::     MIT License
#
#--
# SVN: $Id$
#++


require 'test_helper'
require 'www/delicious/tag'


class TagTest < Test::Unit::TestCase
  
  def test_tag
    expected = { :name => 'MyTag', :count => 2 }
    assert_attributes(instance(expected), expected)
  end
  
  def test_tag_from_rexml
    dom = REXML::Document.new(File.read(TESTCASES_PATH + '/element/tag.xml'))
    expected = { :count => 1, :name => 'activedesktop' }
    
    element = WWW::Delicious::Tag.from_rexml(dom.root)
    assert_attributes(element, expected)
  end
  
  
  def test_tag_name_strips_whitespaces
    [' foo   ', 'foo  ', ' foo ', '  foo'].each do |v|
      assert_equal('foo', instance(:name => v).name) # => 'foo'
    end
  end
  
  def test_to_s_returns_name_as_string
    assert_equal('foobar', instance(:name => 'foobar', :count => 4).to_s)
  end
  
  def test_to_s_returns_empty_string_with_name_nil
    assert_equal('', instance(:name => nil).to_s)
  end
  
  
  # def test_api_valid
  #   ['foo', ' foo '].each do |v|
  #     assert(instance(v).api_valid?)
  #   end
  #   ['', '  '].each do |v|
  #     assert(!instance(v).api_valid?)
  #   end
  # end
  
  
  protected
  
    # returns a stub instance
    def instance(values = {}, &block)
      WWW::Delicious::Tag.new(values)
    end

end