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 6, 2015
1 parent ca98a80 commit 9d1f6f5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 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 'mechanize'
require 'rgrb/version'
require 'rgrb/plugin/configurable_generator'

module RGRB
Expand Down
10 changes: 10 additions & 0 deletions spec/rgrb/plugin/url_fetch_title/data/cre_ne_jp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8" />
<title>クリエイターズネットワーク</title>
</head>
<body>
<p><a href="http://www.cre.ne.jp/">クリエイターズネットワーク ホームページ</a></p>
</body>
</html>
47 changes: 47 additions & 0 deletions spec/rgrb/plugin/url_fetch_title/generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# vim: fileencoding=utf-8

require_relative '../../../spec_helper'
require 'rgrb/plugin/url_fetch_title/generator'

describe RGRB::Plugin::UrlFetchTitle::Generator do
let(:generator) { described_class.new }

describe '#fetch_title' do
let(:default_prefix) { 'Fetch title: ' }
let(:default_suffix) { '[end]' }

before do
config = {
:@no_ssl_verify => [],
:@reply_prefix => default_prefix,
:@reply_suffix => default_suffix
}
config.each do |var, value|
generator.instance_variable_set(var, value)
end
end

context 'HTML ファイル' do
let(:url) { 'http://www.cre.ne.jp/' }

before do
html_path = File.expand_path(
'data/cre_ne_jp.html', File.dirname(__FILE__)
)
response = {
body: File.read(html_path),
status: 200,
headers: {
'Content-Type' => 'text/html; charset=UTF-8'
}
}
stub_request(:get, url).to_return(response)
end

subject { generator.fetch_title(url) }
it do
should eq("#{default_prefix}クリエイターズネットワーク#{default_suffix}")
end
end
end
end

0 comments on commit 9d1f6f5

Please sign in to comment.