Skip to content

Commit

Permalink
UrlFetchTitle: タイムアウトエラー表示を実装した
Browse files Browse the repository at this point in the history
refs #5
  • Loading branch information
ochaochaocha3 committed Mar 15, 2015
1 parent 59a7a74 commit a9c493c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rgrb/plugin/url_fetch_title/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'uri'
require 'socket'
require 'net/http'
require 'mechanize'
require 'active_support'
require 'active_support/core_ext/numeric/conversions'
Expand Down Expand Up @@ -117,6 +118,8 @@ def fetch_title(url)
end
rescue SocketError
body = '(サーバーに接続できませんでした)'
rescue Net::HTTP::Persistent::Error
body = '(タイムアウト)'
rescue Mechanize::ResponseCodeError => response_code_error
response_code = response_code_error.response_code.to_i
reason_phrase =
Expand Down
15 changes: 15 additions & 0 deletions spec/rgrb/plugin/url_fetch_title/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@
end
end

context 'タイムアウトした場合' do
let(:url) { 'http://example.net/very_very_heavy' }

before do
stub_request(:get, url).to_timeout
end

subject { generator.fetch_title(url) }
it 'タイムアウトしたことを示すエラーメッセージを返す' do
expect(subject).to eq(
"#{default_prefix}(タイムアウト)#{default_suffix}"
)
end
end

context '401 Unauthorized' do
let(:url) { 'http://example.net/need_login' }

Expand Down

0 comments on commit a9c493c

Please sign in to comment.