Sha256: 08543b91752e5c277941c4203b49b2984ae0751a73c885f7193df02245fc0eb3

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

$:.unshift File.dirname(__FILE__)

require 'spec_helper'
require 'json'

include SpecHelper

describe TextConverter::Service do
  before do
    @converter = TextConverter.new
    @converter.stub!(:json).and_return(JSON.load(open(fixture('items.json')).read))
  end

  it 'should build url' do
    service = @converter.service('アレ')

    service.build_url('テストです').should eql('http://areare.jgate.de/convert?q=%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99')
  end

  it 'should parse html' do
    service = TextConverter::Service.new('foo', 'url' => 'http://example.com/', 'charset' => 'utf8', 'xpath' => '(//p)[2]')

    service.parse(<<_HTML_).should eql('かきくけこ')
<html>
<head>
<title>foo</title>
</head>
<body>
<p>あいうえお</p>
<p>かきくけこ</p>
</body>
</html>
_HTML_
  end

  it 'should parse html without DOCTYPE with xpath id() function' do
    service = TextConverter::Service.new('foo', 'url' => 'http://example.com/', 'charset' => 'utf8', 'xpath' => 'id("bar")')

    service.parse(<<_HTML_).should eql('かきくけこ')
<html>
<head>
<title>foo</title>
</head>
<body>
<p>あいうえお</p>
<p id="bar">かきくけこ</p>
</body>
</html>
_HTML_
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
youpy-text-converter-0.0.1 spec/service_spec.rb
youpy-text-converter-0.0.2 spec/service_spec.rb