imdb_lists 1.0.4 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/README.md +59 -0
- data/imdb_lists.gemspec +5 -3
- data/lib/imdb_lists.rb +164 -27
- data/lib/imdb_lists/object.rb +11 -0
- data/spec/fixtures/vcr_cassettes/qJi7_i3l25Y.yml +550 -0
- data/spec/fixtures/vcr_cassettes/random.yml +646 -0
- data/spec/fixtures/vcr_cassettes/ur10777143.yml +2099 -0
- data/spec/imdb_list_spec.rb +143 -0
- data/spec/spec_helper.rb +11 -3
- metadata +17 -36
- data/README.markdown +0 -77
- data/lib/imdb_lists/base.rb +0 -31
- data/lib/imdb_lists/container.rb +0 -49
- data/lib/imdb_lists/history.rb +0 -35
- data/lib/imdb_lists/watchlist.rb +0 -46
- data/spec/container_spec.rb +0 -38
- data/spec/fixtures/32558051.html +0 -8401
- data/spec/fixtures/empty_watchlist.html +0 -761
- data/spec/fixtures/non_public.html +0 -992
- data/spec/fixtures/non_public_watchlist.html +0 -668
- data/spec/fixtures/pagination.html +0 -1057
- data/spec/fixtures/pagination_end.html +0 -956
- data/spec/fixtures/redirect_watchlist.html +0 -2701
- data/spec/fixtures/watchlist.html +0 -3365
- data/spec/history_spec.rb +0 -124
- data/spec/watchlist_spec.rb +0 -170
data/spec/history_spec.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe ImdbLists::History do
|
4
|
-
before(:all) do
|
5
|
-
@url = "http://www.imdb.com/mymovies/list?l=32558051"
|
6
|
-
@id = "32558051"
|
7
|
-
@count = 937
|
8
|
-
|
9
|
-
@valid_urls = [
|
10
|
-
"http://imdb.com/mymovies/list?l=1234",
|
11
|
-
"imdb.com/mymovies/list?l=1234",
|
12
|
-
"www.imdb.com/mymovies/list?l=1234"
|
13
|
-
]
|
14
|
-
|
15
|
-
@invalid_urls = [
|
16
|
-
"http://www.imdb.com/mymovieslist?l=32558051",
|
17
|
-
"mymovieslist?l=32558051",
|
18
|
-
"http://www.imdb.com/mymovieslist?l=32558abc051"
|
19
|
-
]
|
20
|
-
end
|
21
|
-
|
22
|
-
after(:each) do
|
23
|
-
WebMock.reset!
|
24
|
-
end
|
25
|
-
|
26
|
-
before(:each) do
|
27
|
-
@ivh = ImdbLists::History.new(@id)
|
28
|
-
end
|
29
|
-
|
30
|
-
context "200 success" do
|
31
|
-
before(:each) do
|
32
|
-
stub_request(:get, "#{@url}&a=1").to_return(:body => File.new("spec/fixtures/32558051.html"), :status => 200)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should return a list of movies" do
|
36
|
-
@ivh.should have(@count).movies
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should be able to cache" do
|
40
|
-
object = Container::Movie.new(:imdb_link => "http://www.imdb.com/title/tt0460649/")
|
41
|
-
Container::Movie.should_receive(:new).exactly(@count).times.and_return(object)
|
42
|
-
10.times { @ivh.movies }
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should have a user method" do
|
46
|
-
@ivh.user.should eq("eddyproca")
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should have a id method" do
|
50
|
-
@ivh.id.should eq(32558051)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should contain a list of movies" do
|
54
|
-
@ivh.movies.all? { |m| m.should be_instance_of(Container::Movie) }
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should have an url method" do
|
58
|
-
@ivh.url.should eq(@url)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "404 error" do
|
63
|
-
before(:each) do
|
64
|
-
stub_request(:get, "#{@url}&a=1").to_return(:body => "", :status => 404)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should return an empty list if something goes wrong" do
|
68
|
-
@ivh.movies.should be_empty
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should not return a user" do
|
72
|
-
@ivh.user.should be_nil
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context "a non public list" do
|
77
|
-
before(:each) do
|
78
|
-
stub_request(:get, "#{@url}&a=1").to_return(:body => File.new("spec/fixtures/non_public.html"), :status => 200)
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should return an empty list" do
|
82
|
-
@ivh.should have(0).movies
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should not have a user" do
|
86
|
-
@ivh.user.should be_nil
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should have an id" do
|
90
|
-
@ivh.id.should eq(32558051)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context "the find_by_id method" do
|
95
|
-
it "should be possible to pass an id" do
|
96
|
-
["32558051", 32558051].each do |id|
|
97
|
-
ImdbLists::History.should_receive(:new).with(id)
|
98
|
-
lambda { ImdbLists::find_by_id(id) }.should_not raise_error(ArgumentError)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should not be possible to pass nil or n <= 9" do
|
103
|
-
["0", nil, "1", "9"].each do |id|
|
104
|
-
lambda { ImdbLists::find_by_id(id) }.should raise_error(ArgumentError)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context "the find_by_url method" do
|
110
|
-
it "should raise an error if the url is invalid" do
|
111
|
-
ImdbLists::History.should_not_receive(:new)
|
112
|
-
@invalid_urls.each do |url|
|
113
|
-
lambda { ImdbLists::find_by_url(url) }.should raise_error(ArgumentError)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should not raise an error if the url is valid" do
|
118
|
-
ImdbLists::History.should_receive(:new).with("1234").exactly(@valid_urls.length).times
|
119
|
-
@valid_urls.each do |url|
|
120
|
-
lambda { ImdbLists::find_by_url(url) }.should_not raise_error(ArgumentError)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
data/spec/watchlist_spec.rb
DELETED
@@ -1,170 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe ImdbLists::Watchlist do
|
4
|
-
before(:all) do
|
5
|
-
@url = "http://www.imdb.com/list/2BZy80bxY2U"
|
6
|
-
@id = "2BZy80bxY2U"
|
7
|
-
@count = 79
|
8
|
-
@full_url = "http://www.imdb.com/list/2BZy80bxY2U/?view=compact&sort=listorian:asc"
|
9
|
-
end
|
10
|
-
|
11
|
-
before(:each) do
|
12
|
-
@ivh = ImdbLists::Watchlist.new(@id)
|
13
|
-
end
|
14
|
-
|
15
|
-
context "200 success - internet" do
|
16
|
-
before(:each) do
|
17
|
-
stub_request(:get, @full_url).to_return(:body => File.read("spec/fixtures/watchlist.html"), :status => 200)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should return a list of movies" do
|
21
|
-
@ivh.should have(@count).movies
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should have a user method" do
|
25
|
-
@ivh.user.should eq("savagestreets")
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should have a title" do
|
29
|
-
@ivh.title.should eq("My favorite movies of alltime! some of them are so bad, but so f....g brilliant")
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should be valid" do
|
33
|
-
@ivh.should be_valid
|
34
|
-
end
|
35
|
-
|
36
|
-
after(:each) do
|
37
|
-
a_request(:get, @full_url).should have_been_made
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "offline" do
|
43
|
-
it "should have a id method" do
|
44
|
-
@ivh.id.should eq("2BZy80bxY2U")
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should have an url method" do
|
48
|
-
@ivh.url.should eq(@url)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "empty list" do
|
53
|
-
before(:each) do
|
54
|
-
stub_request(:get, @full_url).to_return(:body => File.new("spec/fixtures/empty_watchlist.html"), :status => 200)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should return an empty list" do
|
58
|
-
@ivh.should have(0).movies
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should not have a user" do
|
62
|
-
@ivh.user.should eq("Oleeander")
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should have an id" do
|
66
|
-
@ivh.id.should eq("2BZy80bxY2U")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "non public" do
|
71
|
-
before(:each) do
|
72
|
-
stub_request(:get, @full_url).to_return(:body => File.new("spec/fixtures/non_public_watchlist.html"), :status => 200)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should return an empty list" do
|
76
|
-
@ivh.should have(0).movies
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should not have a user" do
|
80
|
-
@ivh.user.should be_nil
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should not have a title" do
|
84
|
-
@ivh.title.should be_nil
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should have an id" do
|
88
|
-
@ivh.id.should eq("2BZy80bxY2U")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context "empty page" do
|
93
|
-
before(:each) do
|
94
|
-
stub_request(:get, @full_url).to_return(:body => "<html></html>", :status => 200)
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should return an empty list" do
|
98
|
-
@ivh.should have(0).movies
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should not have a user" do
|
102
|
-
@ivh.user.should be_nil
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should not have a title" do
|
106
|
-
@ivh.title.should be_nil
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should have an id" do
|
110
|
-
@ivh.id.should eq("2BZy80bxY2U")
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should not be valid" do
|
114
|
-
@ivh.should_not be_valid
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context "the find_by_id method" do
|
119
|
-
it "should be possible to pass an id" do
|
120
|
-
ImdbLists::Watchlist.should_receive(:new).with("2BZy80bxY2U")
|
121
|
-
lambda { ImdbLists::find_by_id("2BZy80bxY2U") }.should_not raise_error(ArgumentError)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "the find_by_url method" do
|
126
|
-
it "should not raise an error if the url is valid" do
|
127
|
-
ImdbLists::Watchlist.should_receive(:new).exactly(2).times.with("2BZy80bxY2U")
|
128
|
-
lambda { ImdbLists::find_by_url(@full_url) }.should_not raise_error(ArgumentError)
|
129
|
-
lambda { ImdbLists::find_by_url(@url) }.should_not raise_error(ArgumentError)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context "errors" do
|
134
|
-
before(:each) do
|
135
|
-
stub_request(:get, @full_url).to_return do
|
136
|
-
raise RestClient::Exception
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should raise an error" do
|
141
|
-
lambda { @ivh.movies }.should_not raise_error(RestClient::Exception)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should be possible to turn of request errors" do
|
145
|
-
lambda { @ivh.errors(true).movies }.should raise_error(RestClient::Exception)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context "redirect" do
|
150
|
-
before(:each) do
|
151
|
-
stub_request(:get, @full_url).to_return(:body => File.new("spec/fixtures/redirect_watchlist.html"), :status => 200)
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should not return any movies" do
|
155
|
-
@ivh.should have(0).movies
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should find any title" do
|
159
|
-
@ivh.title.should be_nil
|
160
|
-
end
|
161
|
-
|
162
|
-
it "should still have an id" do
|
163
|
-
@ivh.id.should eq("2BZy80bxY2U")
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should not have a user" do
|
167
|
-
@ivh.user.should be_nil
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|