Skip to content

Commit

Permalink
close #19 IIDXIDの書式が正しくない場合のテストを記述
Browse files Browse the repository at this point in the history
  • Loading branch information
8398a7 committed Mar 31, 2015
1 parent 5b24423 commit 9df9c1e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/scrape/iidxme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ def process(iidxid)
end

def user_id_search(iidxid)
return false unless iidxid =~ /\A\d{4}-\d{4}\z/
uri = URI.parse("http://json.iidx.me/?name=#{ iidxid }")
res = Net::HTTP.get(uri)
hash = JSON.parse(res)
return false if hash['users'][0].nil?
return false unless hash['users'].count == 1
hash['users'][0]['userid']
end

Expand Down
15 changes: 15 additions & 0 deletions spec/lib/scrape/iidxme_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@
end
end
context '異常系' do
describe 'IIDXIDの書式が正しくない場合' do
let(:iidxids) { ['1', '1110'] }
it '#async' do
iidxids.each { |iidxid| expect(iidxme.async(iidxid)).to be_falsy }
end
it '#process' do
iidxids.each { |iidxid| expect(iidxme.send(:process, iidxid)).to be_falsy }
end
it '#user_id_search' do
iidxids.each { |iidxid| expect(iidxme.send(:user_id_search, iidxid)).to be_falsy }
end
it '#data_get' do
iidxids.each { |iidxid| expect(iidxme.send(:data_get, iidxid)).to be_falsy }
end
end
describe '存在しないIIDXIDで処理を行う場合' do
let(:iidxid) { { iidxid: '0000-0000' } }
it '#async' do
Expand Down

0 comments on commit 9df9c1e

Please sign in to comment.