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 a9c493c commit 84af1a8
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions spec/rgrb/plugin/url_fetch_title/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
describe '#fetch_title' do
let(:default_prefix) { 'Fetch title: ' }
let(:default_suffix) { '[end]' }
let(:format) do
lambda { |str| "#{default_prefix}#{str}#{default_suffix}" }
end

before do
config = {
Expand Down Expand Up @@ -40,7 +43,7 @@

subject { generator.fetch_title(url) }
it '<title> タグの内容を含む' do
should eq("#{default_prefix}クリエイターズネットワーク#{default_suffix}")
expect(subject).to eq(format['クリエイターズネットワーク'])
end
end

Expand All @@ -65,9 +68,7 @@

subject { generator.fetch_title(url) }
it 'Content-Type と読みやすい Content-Length を含む' do
should eq(
"#{default_prefix}(#{content_type}; 4.2 KB)#{default_suffix}"
)
expect(subject).to eq(format["(#{content_type}; 4.2 KB)"])
end
end

Expand All @@ -90,9 +91,7 @@

subject { generator.fetch_title(url) }
it 'Content-Type と読みやすい Content-Length を含む' do
should eq(
"#{default_prefix}(#{content_type}; 20 Bytes)#{default_suffix}"
)
expect(subject).to eq(format["(#{content_type}; 20 Bytes)"])
end
end

Expand All @@ -105,9 +104,7 @@

subject { generator.fetch_title(url) }
it 'サーバーに接続できないことを示すエラーメッセージを返す' do
expect(subject).to eq(
"#{default_prefix}(サーバーに接続できませんでした)#{default_suffix}"
)
expect(subject).to eq(format['(サーバーに接続できませんでした)'])
end
end

Expand All @@ -120,9 +117,7 @@

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

Expand All @@ -135,9 +130,7 @@

subject { generator.fetch_title(url) }
it '"401 Unauthorized" エラーメッセージが返る' do
should eq(
"#{default_prefix}(401 Unauthorized)#{default_suffix}"
)
expect(subject).to eq(format['(401 Unauthorized)'])
end
end

Expand All @@ -150,9 +143,7 @@

subject { generator.fetch_title(url) }
it '"403 Forbidden" エラーメッセージが返る' do
should eq(
"#{default_prefix}(403 Forbidden)#{default_suffix}"
)
expect(subject).to eq(format['(403 Forbidden)'])
end
end

Expand All @@ -165,9 +156,7 @@

subject { generator.fetch_title(url) }
it '"404 Not Found" エラーメッセージが返る' do
should eq(
"#{default_prefix}(404 Not Found)#{default_suffix}"
)
expect(subject).to eq(format['(404 Not Found)'])
end
end

Expand All @@ -180,9 +169,7 @@

subject { generator.fetch_title(url) }
it '"不明なエラー" エラーメッセージが返る' do
should eq(
"#{default_prefix}(999 不明なエラー)#{default_suffix}"
)
expect(subject).to eq(format['(999 不明なエラー)'])
end
end
end
Expand Down

0 comments on commit 84af1a8

Please sign in to comment.