spec/object/movie_spec.rb in nicoquery-0.1.6.1 vs spec/object/movie_spec.rb in nicoquery-0.1.7
- old
+ new
@@ -1,7 +1,10 @@
require 'nicoquery/object/movie'
require 'fixture/getthumbinfo_deleted'
+require 'fixture/getthumbinfo_community'
+require 'fixture/video_array_community'
+require 'fixture/getthumbinfo_notfound'
require 'webmock/rspec'
describe "NicoQuery::Object::Movie" do
context "when specified video id and this movie is exist" do
@@ -13,14 +16,12 @@
end
subject { @movie }
describe "#deleted?" do
- subject { @movie.deleted? }
-
it "returns false" do
- expect(subject).to be_false
+ expect(subject.deleted?).to be_false
end
end
describe "title" do
it "returns string of title" do
@@ -59,11 +60,11 @@
expect(subject).to include(text: '陰陽師', lock: true)
end
end
end
- context "when specified video id and this movie is exist" do
+ context "when specified thread id and this movie is exist" do
before do
# thread_id:1173108780 == video_id:sm9
@movie = NicoQuery::Object::Movie.new(1173108780)
end
@@ -76,24 +77,63 @@
end
end
context "when specified movie is deleted" do
before do
+ WebMock.enable!
WebMock.stub_request(:get, "http://ext.nicovideo.jp/api/getthumbinfo/sm999999?").
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
to_return(:status => 200, :body => Fixture.getthumbinfo_deleted, :headers => {})
@movie = NicoQuery::Object::Movie.new('sm999999')
end
+ after do
+ WebMock.disable!
+ end
+
subject { @movie }
describe "#deleted?" do
- subject { @movie.deleted? }
+ it "returns true" do
+ expect(subject.deleted?).to be_true
+ end
+ end
+ describe "getter methods" do
+ specify "all returns nil" do
+ expect(subject.title).to be_nil
+ expect(subject.url).to be_nil
+ expect(subject.view_counter).to be_nil
+ expect(subject.tags).to be_nil
+ end
+ end
+ end
+
+ context "when specified movie belongs to community" do
+ before do
+ WebMock.enable!
+ WebMock.stub_request(:get, "http://ext.nicovideo.jp/api/getthumbinfo/sm99999901?").
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
+ to_return(:status => 200, :body => Fixture.getthumbinfo_community, :headers => {})
+
+ WebMock.stub_request(:get, "http://i.nicovideo.jp/v3/video.array?v=sm99999901").
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
+ to_return(:status => 200, :body => Fixture.video_array_community, :headers => {})
+
+ @movie = NicoQuery::Object::Movie.new('sm99999901')
+ end
+
+ after do
+ WebMock.disable!
+ end
+
+ subject { @movie }
+
+ describe "#community?" do
it "returns true" do
- expect(subject).to be_true
+ expect(subject.community?).to be_true
end
end
describe "getter methods" do
specify "all returns nil" do
@@ -101,8 +141,39 @@
expect(subject.url).to be_nil
expect(subject.view_counter).to be_nil
expect(subject.tags).to be_nil
end
end
+ end
+ context "when specified movie doesn't exist" do
+ before do
+ WebMock.enable!
+ WebMock.stub_request(:get, "http://ext.nicovideo.jp/api/getthumbinfo/sm99999901?").
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
+ to_return(:status => 200, :body => Fixture.getthumbinfo_notfound, :headers => {})
+
+ @movie = NicoQuery::Object::Movie.new('sm99999901')
+ end
+
+ after do
+ WebMock.disable!
+ end
+
+ subject { @movie }
+
+ describe "#exist?" do
+ it "returns false" do
+ expect(subject.exist?).to be_false
+ end
+ end
+
+ describe "getter methods" do
+ specify "all returns nil" do
+ expect(subject.title).to be_nil
+ expect(subject.url).to be_nil
+ expect(subject.view_counter).to be_nil
+ expect(subject.tags).to be_nil
+ end
+ end
end
end