root/platform/tdiary/test/my_hotentry_test.rb @ 3281

Revision 3281, 1.8 kB (checked in by hsbt, 6 years ago)

platform/tdiary/test: create directory,and remove unit test file.

Line 
1#!/usr/bin/env ruby
2$KCODE = 'e'
3require 'test/unit'
4require 'tmpdir'
5require 'fileutils'
6begin
7  require 'my_hotentry'
8rescue
9end
10
11class MyHotEntryTest < Test::Unit::TestCase
12  def setup
13    # @cache_path �ϡ֥ե�����-�ץ�����
14    @cache_path = File.join(Dir.tmpdir, "#{__FILE__}-#{$$}")
15    Dir.mkdir(@cache_path)
16    @dbfile = "#{@cache_path}/my_hotentry.dat"
17  end
18
19  def teardown
20    FileUtils.rmtree(@cache_path)
21  end
22
23  def test_update
24    # �͵����������   base_url = 'http://d.hatena.ne.jp/'
25    hotentry = MyHotEntry.new(@dbfile)
26    hotentry.update(base_url)
27    # �������������뤬���������뤳��    assert(File.file?(@dbfile))
28    # �͵������Ǥ��Ƥ��뤳��    entries = hotentry.entries
29    assert(entries.size > 0)
30    entries.each do |entry|
31      assert(entry[:url].include?(base_url), 'base_url �ǻ�ꤷ��URL���ޤޤ����뤳��)
32      assert(entry[:title].size > 0)
33    end
34  end
35
36  # ���������Ƥ⥭�����奵������������ʤ�������  def test_double_update
37    base_url = 'http://d.hatena.ne.jp/'
38    hotentry = MyHotEntry.new(@dbfile)
39    sleep 0.5
40    hotentry.update(base_url)
41    assert(hotentry.entries.size > 0)
42    size = hotentry.entries.size
43    sleep 0.5
44    hotentry.update(base_url)
45    assert_equal(size, hotentry.entries.size)
46  end
47
48  # ����������ϥ����������ꥢ���ʤ�
49  def test_update_noentry
50    exist_url = 'http://d.hatena.ne.jp/'
51    empty_url = 'http://empty-url-123456'
52    hotentry = MyHotEntry.new(@dbfile)
53
54    sleep 0.5
55    hotentry.update(empty_url)
56    assert_equal(0, hotentry.entries.size)
57
58    sleep 0.5
59    hotentry.update(exist_url)
60    assert(hotentry.entries.size > 0)
61    exist_size = hotentry.entries.size
62
63    sleep 0.5
64    hotentry.update(empty_url)
65    assert_equal(exist_size, hotentry.entries.size)
66  end
67end
68
Note: See TracBrowser for help on using the browser.