yt 0.19.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,93 @@ require 'yt/models/playlist'
4
4
  describe Yt::Playlist do
5
5
  subject(:playlist) { Yt::Playlist.new attrs }
6
6
 
7
+
8
+ describe '#title' do
9
+ context 'given a snippet with a title' do
10
+ let(:attrs) { {snippet: {"title"=>"Fullscreen"}} }
11
+ it { expect(playlist.title).to eq 'Fullscreen' }
12
+ end
13
+
14
+ context 'given a snippet without a title' do
15
+ let(:attrs) { {snippet: {}} }
16
+ it { expect(playlist.title).to eq '' }
17
+ end
18
+ end
19
+
20
+ describe '#published_at' do
21
+ context 'given a snippet with a timestamp' do # always returned by YouTube
22
+ let(:attrs) { {snippet: {"publishedAt"=>"2014-04-22T19:14:49.000Z"}} }
23
+ it { expect(playlist.published_at.year).to be 2014 }
24
+ end
25
+ end
26
+
27
+ describe '#description' do
28
+ context 'given a snippet with a description' do
29
+ let(:attrs) { {snippet: {"description"=>"The first media company for the connected generation."}} }
30
+ it { expect(playlist.description).to eq 'The first media company for the connected generation.' }
31
+ end
32
+
33
+ context 'given a snippet without a description' do
34
+ let(:attrs) { {snippet: {}} }
35
+ it { expect(playlist.description).to eq '' }
36
+ end
37
+ end
38
+
39
+ describe '#tags' do
40
+ context 'given a snippet with tags' do
41
+ let(:attrs) { {snippet: {"tags"=>["promotion", "new media"]}} }
42
+ it { expect(playlist.tags).to eq ["promotion", "new media"] }
43
+ end
44
+
45
+ context 'given a snippet without tags' do
46
+ let(:attrs) { {snippet: {}} }
47
+ it { expect(playlist.tags).to eq [] }
48
+ end
49
+ end
50
+
51
+ describe '#thumbnail_url' do
52
+ context 'given a snippet with thumbnails' do
53
+ let(:attrs) { {snippet: {"thumbnails"=>{
54
+ "default"=>{"url"=> "http://example.com/88x88.jpg"},
55
+ "medium"=>{"url"=> "http://example.com/240x240.jpg"},
56
+ }}} }
57
+ it { expect(playlist.thumbnail_url).to eq 'http://example.com/88x88.jpg' }
58
+ it { expect(playlist.thumbnail_url 'default').to eq 'http://example.com/88x88.jpg' }
59
+ it { expect(playlist.thumbnail_url :default).to eq 'http://example.com/88x88.jpg' }
60
+ it { expect(playlist.thumbnail_url :medium).to eq 'http://example.com/240x240.jpg' }
61
+ it { expect(playlist.thumbnail_url :large).to be_nil }
62
+ end
63
+
64
+ context 'given a snippet without thumbnails' do
65
+ let(:attrs) { {snippet: {}} }
66
+ it { expect(playlist.thumbnail_url).to be_nil }
67
+ end
68
+ end
69
+
70
+ describe '#channel_id' do
71
+ context 'given a snippet with a channel ID' do
72
+ let(:attrs) { {snippet: {"channelId"=>"UCxO1tY8h1AhOz0T4ENwmpow"}} }
73
+ it { expect(playlist.channel_id).to eq 'UCxO1tY8h1AhOz0T4ENwmpow' }
74
+ end
75
+
76
+ context 'given a snippet without a channel ID' do
77
+ let(:attrs) { {snippet: {}} }
78
+ it { expect(playlist.channel_id).to be_nil }
79
+ end
80
+ end
81
+
82
+ describe '#channel_title' do
83
+ context 'given a snippet with a channel title' do
84
+ let(:attrs) { {snippet: {"channelTitle"=>"Fullscreen"}} }
85
+ it { expect(playlist.channel_title).to eq 'Fullscreen' }
86
+ end
87
+
88
+ context 'given a snippet without a channel title' do
89
+ let(:attrs) { {snippet: {}} }
90
+ it { expect(playlist.channel_title).to be_nil }
91
+ end
92
+ end
93
+
7
94
  describe '#exists?' do
8
95
  context 'given a playlist with an id' do
9
96
  let(:attrs) { {id: 'PLSWYkYzOr'} }
@@ -3,7 +3,6 @@ require 'yt/models/snippet'
3
3
 
4
4
  describe Yt::Snippet do
5
5
  subject(:snippet) { Yt::Snippet.new data: data }
6
- let(:data) { {} }
7
6
 
8
7
  describe '#data' do
9
8
  let(:data) { {"key"=>"value"} }
@@ -11,120 +10,4 @@ describe Yt::Snippet do
11
10
  expect(snippet.data).to eq data
12
11
  end
13
12
  end
14
-
15
- describe '#title' do
16
- context 'given a snippet with a title' do
17
- let(:data) { {"title"=>"Fullscreen"} }
18
- it { expect(snippet.title).to eq 'Fullscreen' }
19
- end
20
-
21
- context 'given a snippet without a title' do
22
- it { expect(snippet.title).to eq '' }
23
- end
24
- end
25
-
26
- describe '#published_at' do
27
- context 'given a snippet with a timestamp' do # always returned by YouTube
28
- let(:data) { {"publishedAt"=>"2014-04-22T19:14:49.000Z"} }
29
- it { expect(snippet.published_at.year).to be 2014 }
30
- end
31
- end
32
-
33
- describe '#description' do
34
- context 'given a snippet with a description' do
35
- let(:data) { {"description"=>"The first media company for the connected generation."} }
36
- it { expect(snippet.description).to eq 'The first media company for the connected generation.' }
37
- end
38
-
39
- context 'given a snippet without a description' do
40
- it { expect(snippet.description).to eq '' }
41
- end
42
- end
43
-
44
- describe '#tags' do
45
- context 'given a snippet with tags' do
46
- let(:data) { {"tags"=>["promotion", "new media"]} }
47
- it { expect(snippet.tags).to eq ["promotion", "new media"] }
48
- end
49
-
50
- context 'given a snippet without tags' do
51
- it { expect(snippet.tags).to eq [] }
52
- end
53
- end
54
-
55
- describe '#thumbnail_url' do
56
- context 'given a snippet with thumbnails' do
57
- let(:data) { {"thumbnails"=>{
58
- "default"=>{"url"=> "http://example.com/88x88.jpg"},
59
- "medium"=>{"url"=> "http://example.com/240x240.jpg"},
60
- }} }
61
- it { expect(snippet.thumbnail_url).to eq 'http://example.com/88x88.jpg' }
62
- it { expect(snippet.thumbnail_url 'default').to eq 'http://example.com/88x88.jpg' }
63
- it { expect(snippet.thumbnail_url :default).to eq 'http://example.com/88x88.jpg' }
64
- it { expect(snippet.thumbnail_url :medium).to eq 'http://example.com/240x240.jpg' }
65
- it { expect(snippet.thumbnail_url :large).to be_nil }
66
- end
67
-
68
- context 'given a snippet without thumbnails' do
69
- it { expect(snippet.thumbnail_url).to be_nil }
70
- end
71
- end
72
-
73
- describe '#channel_id' do
74
- context 'given a snippet with a channel ID' do
75
- let(:data) { {"channelId"=>"UCxO1tY8h1AhOz0T4ENwmpow"} }
76
- it { expect(snippet.channel_id).to eq 'UCxO1tY8h1AhOz0T4ENwmpow' }
77
- end
78
-
79
- context 'given a snippet without a channel ID' do
80
- it { expect(snippet.channel_id).to be_nil }
81
- end
82
- end
83
-
84
- describe '#channel_title' do
85
- context 'given a snippet with a channel title' do
86
- let(:data) { {"channelTitle"=>"Fullscreen"} }
87
- it { expect(snippet.channel_title).to eq 'Fullscreen' }
88
- end
89
-
90
- context 'given a snippet without a channel title' do
91
- it { expect(snippet.channel_title).to be_nil }
92
- end
93
- end
94
-
95
- describe '#category_id' do
96
- context 'given a snippet with a category ID' do
97
- let(:data) { {"categoryId"=>"22"} }
98
- it { expect(snippet.category_id).to eq '22' }
99
- end
100
-
101
- context 'given a snippet without a category ID' do
102
- it { expect(snippet.category_id).to be_nil }
103
- end
104
- end
105
-
106
- describe '#live_broadcast_content' do
107
- context 'given a snippet with live broadcast content' do
108
- let(:data) { {"liveBroadcastContent"=>"live"} }
109
- it { expect(snippet.live_broadcast_content).to eq 'live' }
110
- end
111
-
112
- context 'given a snippet without live broadcast content' do
113
- it { expect(snippet.live_broadcast_content).to be_nil }
114
- end
115
- end
116
-
117
- describe '#video_id and #video' do
118
- context 'given a snippet with a video resource' do
119
- let(:data) { {"resourceId"=>{"kind"=>"youtube#video","videoId"=>"W4GhTprSsOY"}} }
120
- it { expect(snippet.video_id).to eq 'W4GhTprSsOY' }
121
- it { expect(snippet.video).to be_a Yt::Models::Video }
122
- it { expect(snippet.video.id).to eq 'W4GhTprSsOY' }
123
- end
124
-
125
- context 'given a snippet without a video resource' do
126
- it { expect(snippet.video_id).to be_nil }
127
- it { expect(snippet.video).to be_nil }
128
- end
129
- end
130
- end
13
+ end
@@ -3,7 +3,6 @@ require 'yt/models/statistics_set'
3
3
 
4
4
  describe Yt::StatisticsSet do
5
5
  subject(:statistics_set) { Yt::StatisticsSet.new data: data }
6
- let(:value) { 42 }
7
6
 
8
7
  describe '#data' do
9
8
  let(:data) { {"key"=>"value"} }
@@ -11,66 +10,4 @@ describe Yt::StatisticsSet do
11
10
  expect(statistics_set.data).to eq data
12
11
  end
13
12
  end
14
-
15
- # TODO: Remove these specs when these methods are tested in video, channel, ..
16
- describe '#view_count' do
17
- context 'given a video with views' do
18
- let(:data) { {"viewCount"=>value} }
19
- it { expect(statistics_set.view_count).to be value }
20
- end
21
- end
22
-
23
- describe '#comment_count' do
24
- context 'given a video with comments' do
25
- let(:data) { {"commentCount"=>value} }
26
- it { expect(statistics_set.comment_count).to be value }
27
- end
28
- end
29
-
30
- describe '#like_count' do
31
- context 'given a video with likes' do
32
- let(:data) { {"likeCount"=>value} }
33
- it { expect(statistics_set.like_count).to be value }
34
- end
35
- end
36
-
37
- describe '#dislike_count' do
38
- context 'given a video with dislikes' do
39
- let(:data) { {"dislikeCount"=>value} }
40
- it { expect(statistics_set.dislike_count).to be value }
41
- end
42
- end
43
-
44
- describe '#favorite_count' do
45
- context 'given a video with favorites' do
46
- let(:data) { {"favoriteCount"=>value} }
47
- it { expect(statistics_set.favorite_count).to be value }
48
- end
49
- end
50
-
51
- describe '#video_count' do
52
- context 'given a video with videos' do
53
- let(:data) { {"videoCount"=>value} }
54
- it { expect(statistics_set.video_count).to be value }
55
- end
56
- end
57
-
58
- describe '#subscriber_count' do
59
- context 'given a video with subscribers' do
60
- let(:data) { {"subscriberCount"=>value} }
61
- it { expect(statistics_set.subscriber_count).to be value }
62
- end
63
- end
64
-
65
- describe '#subscriber_count_visible?' do
66
- context 'given a video with publicly visible subscribers' do
67
- let(:data) { {"hiddenSubscriberCount"=>false} }
68
- it { expect(statistics_set).to be_subscriber_count_visible }
69
- end
70
-
71
- context 'given a video with hidden subscribers' do
72
- let(:data) { {"hiddenSubscriberCount"=>true} }
73
- it { expect(statistics_set).not_to be_subscriber_count_visible }
74
- end
75
- end
76
- end
13
+ end
@@ -11,6 +11,118 @@ describe Yt::Video do
11
11
  end
12
12
  end
13
13
 
14
+
15
+ describe '#title' do
16
+ context 'given a snippet with a title' do
17
+ let(:attrs) { {snippet: {"title"=>"Fullscreen Creator Platform"}} }
18
+ it { expect(video.title).to eq 'Fullscreen Creator Platform' }
19
+ end
20
+
21
+ context 'given a snippet without a title' do
22
+ let(:attrs) { {snippet: {}} }
23
+ it { expect(video.title).to eq '' }
24
+ end
25
+ end
26
+
27
+ describe '#description' do
28
+ context 'given a snippet with a description' do
29
+ let(:attrs) { {snippet: {"description"=>"A cool video."}} }
30
+ it { expect(video.description).to eq 'A cool video.' }
31
+ end
32
+
33
+ context 'given a snippet without a description' do
34
+ let(:attrs) { {snippet: {}} }
35
+ it { expect(video.description).to eq '' }
36
+ end
37
+ end
38
+
39
+ describe '#thumbnail_url' do
40
+ context 'given a snippet with thumbnails' do
41
+ let(:attrs) { {snippet: {"thumbnails"=>{
42
+ "default"=>{"url"=> "http://example.com/120x90.jpg"},
43
+ "medium"=>{"url"=> "http://example.com/320x180.jpg"},
44
+ }}} }
45
+ it { expect(video.thumbnail_url).to eq 'http://example.com/120x90.jpg' }
46
+ it { expect(video.thumbnail_url 'default').to eq 'http://example.com/120x90.jpg' }
47
+ it { expect(video.thumbnail_url :default).to eq 'http://example.com/120x90.jpg' }
48
+ it { expect(video.thumbnail_url :medium).to eq 'http://example.com/320x180.jpg' }
49
+ it { expect(video.thumbnail_url :high).to be_nil }
50
+ end
51
+
52
+ context 'given a snippet without thumbnails' do
53
+ let(:attrs) { {snippet: {}} }
54
+ it { expect(video.thumbnail_url).to be_nil }
55
+ end
56
+ end
57
+
58
+ describe '#published_at' do
59
+ context 'given a snippet with a timestamp' do
60
+ let(:attrs) { {snippet: {"publishedAt"=>"2014-04-22T19:14:49.000Z"}} }
61
+ it { expect(video.published_at.year).to be 2014 }
62
+ end
63
+ end
64
+
65
+ describe '#channel_id' do
66
+ context 'given a snippet with a channel ID' do
67
+ let(:attrs) { {snippet: {"channelId"=>"UCxO1tY8h1AhOz0T4ENwmpow"}} }
68
+ it { expect(video.channel_id).to eq 'UCxO1tY8h1AhOz0T4ENwmpow' }
69
+ end
70
+
71
+ context 'given a snippet without a channel ID' do
72
+ let(:attrs) { {snippet: {}} }
73
+ it { expect(video.channel_id).to be_nil }
74
+ end
75
+ end
76
+
77
+ describe '#channel_title' do
78
+ context 'given a snippet with a channel title' do
79
+ let(:attrs) { {snippet: {"channelTitle"=>"Fullscreen"}} }
80
+ it { expect(video.channel_title).to eq 'Fullscreen' }
81
+ end
82
+
83
+ context 'given a snippet without a channel title' do
84
+ let(:attrs) { {snippet: {}} }
85
+ it { expect(video.channel_title).to be_nil }
86
+ end
87
+ end
88
+
89
+ describe '#live_broadcast_content' do
90
+ context 'given a snippet with live broadcast content' do
91
+ let(:attrs) { {snippet: {"liveBroadcastContent"=>"live"}} }
92
+ it { expect(video.live_broadcast_content).to eq 'live' }
93
+ end
94
+
95
+ context 'given a snippet without live broadcast content' do
96
+ let(:attrs) { {snippet: {}} }
97
+ it { expect(video.live_broadcast_content).to be_nil }
98
+ end
99
+ end
100
+
101
+ describe '#tags' do
102
+ context 'given a snippet with tags' do
103
+ let(:attrs) { {snippet: {"tags"=>["promotion", "new media"]}} }
104
+ it { expect(video.tags).to eq ["promotion", "new media"] }
105
+ end
106
+
107
+ context 'given a snippet without tags' do
108
+ let(:attrs) { {snippet: {}} }
109
+ it { expect(video.tags).to eq [] }
110
+ end
111
+ end
112
+
113
+ describe '#category_id' do
114
+ context 'given a snippet with a category ID' do
115
+ let(:attrs) { {snippet: {"categoryId"=>"22"}} }
116
+ it { expect(video.category_id).to eq '22' }
117
+ end
118
+
119
+ context 'given a snippet without a category ID' do
120
+ let(:attrs) { {snippet: {}} }
121
+ it { expect(video.category_id).to be_nil }
122
+ end
123
+ end
124
+
125
+
14
126
  describe '#deleted?' do
15
127
  context 'given fetching a status returns uploadStatus "deleted"' do
16
128
  let(:attrs) { {status: {"uploadStatus"=>"deleted"}} }
@@ -13,7 +13,7 @@ describe Yt::Channel, :device_app do
13
13
  expect(channel.description).to be_a String
14
14
  expect(channel.thumbnail_url).to be_a String
15
15
  expect(channel.published_at).to be_a Time
16
- expect(channel.privacy_status).to be_in Yt::Status::PRIVACY_STATUSES
16
+ expect(channel.privacy_status).to be_a String
17
17
  expect(channel.view_count).to be_an Integer
18
18
  expect(channel.comment_count).to be_an Integer
19
19
  expect(channel.video_count).to be_an Integer
@@ -18,7 +18,7 @@ describe Yt::PlaylistItem, :device_app do
18
18
  expect(item.position).to be_an Integer
19
19
  expect(item.video_id).to be_a String
20
20
  expect(item.video).to be_a Yt::Video
21
- expect(item.privacy_status).to be_in Yt::Status::PRIVACY_STATUSES
21
+ expect(item.privacy_status).to be_a String
22
22
  end
23
23
  end
24
24
 
@@ -17,7 +17,7 @@ describe Yt::Playlist, :device_app do
17
17
  expect(playlist.tags).to be_an Array
18
18
  expect(playlist.channel_id).to be_a String
19
19
  expect(playlist.channel_title).to be_a String
20
- expect(playlist.privacy_status).to be_in Yt::Status::PRIVACY_STATUSES
20
+ expect(playlist.privacy_status).to be_a String
21
21
  end
22
22
 
23
23
  it { expect(playlist.playlist_items.first).to be_a Yt::PlaylistItem }
@@ -16,12 +16,12 @@ describe Yt::Video, :device_app do
16
16
  expect(video.description).to be_a String
17
17
  expect(video.thumbnail_url).to be_a String
18
18
  expect(video.published_at).to be_a Time
19
- expect(video.privacy_status).to be_in Yt::Status::PRIVACY_STATUSES
19
+ expect(video.privacy_status).to be_a String
20
20
  expect(video.tags).to be_an Array
21
21
  expect(video.channel_id).to be_a String
22
22
  expect(video.channel_title).to be_a String
23
23
  expect(video.category_id).to be_a String
24
- expect(video.live_broadcast_content).to be_in Yt::Snippet::BROADCAST_TYPES
24
+ expect(video.live_broadcast_content).to be_a String
25
25
  expect(video.view_count).to be_an Integer
26
26
  expect(video.like_count).to be_an Integer
27
27
  expect(video.dislike_count).to be_an Integer