/
the_pirate_bay_spec.rb
65 lines (54 loc) · 2.48 KB
/
the_pirate_bay_spec.rb
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
describe Trackers::ThePirateBay do
def rest_client(url, type)
RestClient.should_receive(:get).with(url, {:timeout => 10, :cookies => nil}).any_number_of_times.and_return(File.read("spec/data/the_pirate_bay/#{type}.html"))
end
def create_torrent
Container::Torrent.new({
details: "http://thepiratebay.org/torrent/6173093/",
torrent: "http://torrents.thepiratebay.org/6173093/value.torrent",
title: "The title",
tracker: "the_pirate_bay"
})
end
it "should only list torrents with the right title" do
rest_client("http://thepiratebay.org/search/chuck/0/99/0", "search")
torrents = Torrents.the_pirate_bay.search("chuck")
torrents.results.each do |torrent|
torrent.title.should match(/chuck/i)
torrent.title.should_not eq(torrent.torrent)
end
torrents.should have(30).results
end
it "should be possible to parse the details view" do
rest_client("http://thepiratebay.org/torrent/6173093/", "details")
torrent = create_torrent
torrent.seeders.should eq(9383)
end
it "should be possible to list recent torrents" do
rest_client("http://thepiratebay.org/recent/4", "recent")
Torrents.the_pirate_bay.page(5).should have(30).results
end
it "should found 30 recent movies" do
rest_client("http://thepiratebay.org/browse/201/4/3", "movies")
Torrents.the_pirate_bay.page(5).category(:movies).should have(30).results
end
it "should return the right details link when trying to fetch recent torrents" do
rest_client("http://thepiratebay.org/torrent/6173093/", "recent")
Torrents.the_pirate_bay.results.each do |torrent|
torrent.details.should match(/http:\/\/thepiratebay\.org\/torrent\/\d+/)
end
end
it "should have a working find_by_details method" do
rest_client("http://thepiratebay.org/torrent/6173093/", "details")
torrent = Torrents.the_pirate_bay.find_by_details("http://thepiratebay.org/torrent/6173093/")
torrent.should_not be_dead
torrent.seeders.should eq(9383)
torrent.tid.should eq("bdc14130add1a279625bf3774c12e89d")
torrent.domain.should eq("thepiratebay.org")
torrent.imdb.should eq("http://www.imdb.com/title/tt0990407")
torrent.imdb_id.should eq("tt0990407")
torrent.id.should eq(6173093)
torrent.torrent.should eq("http://torrents.thepiratebay.org/6108060/The.Green.Hornet.2010.TS.XViD-T0XiC-iNK.6108060.TPB.torrent")
torrent.title.should eq("The.Green.Hornet.2010.TS.XViD-T0XiC-iNK")
end
end