Skip to content

Commit

Permalink
Merge pull request #105 from kangkyu/view-count-error
Browse files Browse the repository at this point in the history
"View count not found" error
  • Loading branch information
mkk-fullscreen committed Jun 7, 2018
2 parents ad0e5dd + 9b411a2 commit 75c6a15
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/funky/errors.rb
@@ -1,4 +1,5 @@
module Funky
class ContentNotFound < StandardError; end
class ConnectionError < StandardError; end
class CountersNotFound < StandardError; end
end
1 change: 1 addition & 0 deletions lib/funky/video.rb
Expand Up @@ -115,6 +115,7 @@ def self.where(id:)
# and encapsulated into a Funky::Video object.
def self.find(video_id)
counters = @@html_parser.parse html: @@html_page.get(video_id: video_id), video_id: video_id
raise CountersNotFound, "View count not found with video ID #{video_id}" unless counters[:view_count]
new counters.merge(id: video_id)
end

Expand Down
9 changes: 9 additions & 0 deletions spec/videos/video_spec.rb
Expand Up @@ -127,6 +127,15 @@

include_examples 'server errors'
end

context 'given counters are not present' do
let(:video_id) { existing_video_id }

it do
expect_any_instance_of(Funky::HTML::Page).to receive(:get).with(video_id: existing_video_id).and_return('')
expect {video}.to raise_error(Funky::CountersNotFound)
end
end
end

describe '.find_by_url!(url)' do
Expand Down

0 comments on commit 75c6a15

Please sign in to comment.