1
$:.unshift(File.dirname(__FILE__))
7
describe "MyHotEntry" do
9
"#{File.basename(__FILE__, ".rb")}-#{$$}"
12
fake_plugin(:my_hotentry)
13
@cache_path = File.join(Dir.tmpdir, cache_filename)
14
Dir.mkdir(@cache_path)
15
@dbfile = "#{@cache_path}/my_hotentry.dat"
16
@base_url = 'http://d.hatena.ne.jp/'
17
@hotentry = MyHotEntry.new(@dbfile)
21
FileUtils.rmtree(@cache_path)
26
@hotentry.update(@base_url)
27
@entries = @hotentry.entries
30
it "キャッシュファイルが生成されていること" do
31
File.should be_file(@dbfile)
34
it "人気の日記が取得できていること" do
35
@entries.size.should > 0
38
it "取得したエントリにbase_urlとタイトルが含まれていること" do
39
@entries.each do |entry|
40
entry[:url].should be_include(@base_url)
41
entry[:title].size.should > 0
46
describe "何度もupdateした場合" do
48
@hotentry.update(@base_url)
49
@original_entry_size = @hotentry.entries.size
50
@hotentry.update(@base_url)
51
@entry_size = @hotentry.entries.size
54
it "キャッシュサイズが大きくならないこと" do
55
@entry_size.should == @original_entry_size
59
describe "取得結果が空の場合" do
61
@exist_url = 'http://d.hatena.ne.jp/'
62
@empty_url = 'http://empty-url.example.com/'
65
it "キャッシュをクリアしないこと" do
66
@hotentry.update(@empty_url)
67
@hotentry.entries.size.should == 0
69
@hotentry.update(@exist_url)
70
@hotentry.entries.size.should > 0
71
exist_size = @hotentry.entries.size
73
@hotentry.update(@empty_url)
74
@hotentry.entries.size.should == exist_size