Skip to content

Commit

Permalink
Raise NotFound when we can't find a set
Browse files Browse the repository at this point in the history
  • Loading branch information
pelf committed Jul 10, 2017
1 parent 4f61fc1 commit bfd71f0
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/brickset/models/legoset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ def url
"https://brickset.com/sets/#{@legoset_id}-1"
end
end

class Legoset::NotFound < StandardError; end
end
7 changes: 5 additions & 2 deletions lib/brickset/services/get_legoset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ def legoset
end

def parse_details(html)
# TODO: refactor / cleanup
details = { }
eol = 0
html.css('section.featurebox dl').css('dt,dd').to_a.each_slice(2) do |dt, dd|

featurebox = html.css('section.featurebox dl')
raise Brickset::Legoset::NotFound unless featurebox.any?

featurebox.css('dt,dd').to_a.each_slice(2) do |dt, dd|
case dt.text.strip
when 'Name'
details[:name] = dd.text
Expand Down
8 changes: 8 additions & 0 deletions spec/brickset/services/get_legoset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,13 @@
expect(subject.send(attr)).to be_present
end
end

context 'for an inexistent set', vcr: { cassette_name: 'not_found' } do
let(:legoset_id) { '123456' }

it 'raises a not found exception' do
expect { subject }.to raise_error(Brickset::Legoset::NotFound)
end
end
end
end
Loading

0 comments on commit bfd71f0

Please sign in to comment.