Add ci.
Add travis, coverall and fix rubocop issues.
diff --git a/.coveralls.yml b/.coveralls.yml
new file mode 100644
index 0000000..9160059
--- /dev/null
+++ b/.coveralls.yml
@@ -0,0 +1 @@
+service_name: travis-ci
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..2495b95
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,8 @@
+language: ruby
+rvm:
+ - 2.0.0
+ - 2.1.4
+ - ruby-head
+before_install:
+ - gem update --system
+ - gem --version
diff --git a/.yardopts b/.yardopts
new file mode 100644
index 0000000..00ec034
--- /dev/null
+++ b/.yardopts
@@ -0,0 +1,5 @@
+--no-private
+lib/**/*.rb
+exe/mathnet
+-
+LICENSE
diff --git a/Gemfile.lock b/Gemfile.lock
index b75a4c4..636be91 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- mathnet-crawler (0.1.0)
+ mathnet-crawler (0.1.1)
commander (~> 4.3)
exponential-backoff
nokogiri (~> 1.6)
@@ -18,28 +18,44 @@
coderay (1.1.0)
commander (4.3.5)
highline (~> 1.7.2)
+ coveralls (0.8.3)
+ json (~> 1.8)
+ rest-client (>= 1.6.8, < 2)
+ simplecov (~> 0.10.0)
+ term-ansicolor (~> 1.3)
+ thor (~> 0.19.1)
crack (0.4.2)
safe_yaml (~> 1.0.0)
diff-lcs (1.2.5)
docile (1.1.5)
+ domain_name (0.5.25)
+ unf (>= 0.0.5, < 1.0.0)
exponential-backoff (0.0.2)
hashdiff (0.2.2)
highline (1.7.8)
+ http-cookie (1.0.2)
+ domain_name (~> 0.5)
json (1.8.3)
method_source (0.8.2)
+ mime-types (2.6.2)
mini_portile (0.6.2)
+ netrc (0.10.3)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
parallel (1.6.1)
- parser (2.2.2.6)
+ parser (2.2.3.0)
ast (>= 1.1, < 3.0)
powerpack (0.1.1)
- pry (0.10.1)
+ pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rainbow (2.0.0)
rake (10.4.2)
+ rest-client (1.8.0)
+ http-cookie (>= 1.0.2, < 2.0)
+ mime-types (>= 1.16, < 3.0)
+ netrc (~> 0.7)
rspec (3.3.0)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
@@ -67,10 +83,18 @@
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
+ term-ansicolor (1.3.2)
+ tins (~> 1.0)
+ thor (0.19.1)
+ tins (1.6.0)
+ unf (0.1.4)
+ unf_ext
+ unf_ext (0.0.7.1)
webmock (1.22.1)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
+ yard (0.8.7.6)
PLATFORMS
ruby
@@ -78,6 +102,7 @@
DEPENDENCIES
bundler (~> 1.10)
byebug (~> 6.0)
+ coveralls (~> 0.8.3)
mathnet-crawler!
pry (~> 0.10)
rake (~> 10.0)
@@ -85,6 +110,7 @@
rubocop (~> 0.34.2)
simplecov (~> 0.10.0)
webmock (~> 1.22.1)
+ yard (~> 0.8)
BUNDLED WITH
1.10.6
diff --git a/README.md b/README.md
index 70484d1..33edfd6 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,6 @@
# Mathnet::Crawler
+[](https://travis-ci.org/EvgeneOskin/ruby-mathnet-crawler)
+[](https://coveralls.io/github/EvgeneOskin/ruby-mathnet-crawler?branch=master)
The Project is ruby library and cli tool to search and download articles from [MathNet](http://mathnet.ru/).
@@ -22,7 +24,7 @@
$ gem install mathnet-crawler
```
-## Usagerm
+## Usage
TODO: Write usage instructions here
diff --git a/exe/mathnet b/exe/mathnet
index b39976a..c3b1f1a 100755
--- a/exe/mathnet
+++ b/exe/mathnet
@@ -6,118 +6,125 @@
require 'mathnet/crawler'
require 'exponential_backoff'
+# CLI for search and download articles from mathnet site.
class MathnetApplication
include Commander::Methods
+ # Initialize constances.
def initialize
@minimal_interval = 1.0
@maximal_elapsed_time = 600.0
@base_dir = 'mathnet'
end
+ # Process programm call via command line.
def run
program :name, 'Mathnet crawler.'
program :version, Mathnet::Crawler::VERSION
program :description, 'Command that act like missed mathnet client.'
-
+ add_download_all_command
+ add_articles_command
+ add_journals_command
+ run!
+ end
+
+ def add_download_all_command
command :'download all' do |c|
- c.syntax = 'download all'
c.description = 'Download all articals.'
- c.action do |args, options|
+ c.action do
journals = list_journals
issues = list_issues journals
articles = list_articals issues
download_aricles articles
end
end
+ end
+ def add_articles_command
command :articles do |c|
- c.syntax = 'articles'
c.description = 'List articles per journal.'
- c.action do |args, options|
- journals = list_journals
- issues = list_issues journals
- articles = list_articals issues
+ c.action do
+ articles = list_articals list_issues list_journals
articles.each do |article|
say "#{article.journal_title}/#{article.title}"
end
end
end
+ end
+ def add_journals_command
command :journals do |c|
- c.syntax = 'journals'
c.description = 'List journals on mathnet.'
- c.action do |args, options|
+ c.action do
journals = list_journals
journals.each do |journal|
say journal.title
end
end
end
- run!
end
+ # Return all journals published on mathnet.
def list_journals
- process_backoff do
+ process_backoff do
Mathnet::Crawler::Journal.list Mathnet::Crawler::Library.new
end
end
+ # Return all issues that existing in passed journals.
+ # @param journals [Array] of [Mathnet::Crawler::Journals] that having issues.
def list_issues(journals)
- issues_lists = Parallel.map(journals, :progress => 'List issues') do |journal|
- process_backoff do
- Mathnet::Crawler::Issue.list journal
- end
+ issues_lists = Parallel.map(journals, progress: 'List issues') do |journal|
+ process_backoff { Mathnet::Crawler::Issue.list journal }
end
issues_lists.reduce do |initial, item|
initial + item
end
end
+ # Return all articles that existing in passed issues.
+ # @param issues [Array] of [Mathnet::Crawler::Issue] that having articles.
def list_articals(issues)
- articals_lists = Parallel.map(issues, :progress => 'List articals') do |issue|
- process_backoff do
- Mathnet::Crawler::Article.list issue
- end
+ articals_lists = Parallel.map(issues, progress: 'List articals') do |issue|
+ process_backoff { Mathnet::Crawler::Article.list issue }
end
articals_lists.reduce do |initial, item|
- if not item
- return initial
- end
- initial + item
+ (item && initial + item) || initial
end
end
+ # Store full texts of passed articles.
+ # @param articles [Array] of [Mathnet::Crawler::Article] that having
+ # full texts.
def download_aricles(articles)
- Parallel.each(articles, :progress => 'Download texts') do |article|
+ Parallel.each(articles, progress: 'Download texts') do |article|
pdf_path = article_path article
- process_backoff do
+ process_backoff do
article.full_text do |body|
pdf = File.new pdf_path, 'w'
pdf.write body
pdf.close
end
- true
end
end
end
+ # Execut block with exponential backoff
+ # @param &block [block] do http request and if http error occured,
+ # we would retry it.
def process_backoff(&block)
backoff.until_success do
begin
- result = block.call()
+ block.call
rescue Net::HTTPServerException
- result = false
+ false
end
- return result
end
end
def article_path(article)
- directory = File.join @base_dir, article.journal_title
- if not Dir.exist? directory
- FileUtils.mkdir_p directory
- end
+ directory = File.join @base_dir, article.journal_title
+ FileUtils.mkdir_p directory if Dir.exist?(directory)
File.join directory, "#{article.title}.pdf"
end
diff --git a/lib/mathnet/crawler.rb b/lib/mathnet/crawler.rb
index ab4ef11..efd4c72 100644
--- a/lib/mathnet/crawler.rb
+++ b/lib/mathnet/crawler.rb
@@ -3,10 +3,14 @@
require 'net/http'
require 'nokogiri'
-module Mathnet # :nodoc:
- module Crawler # :nodoc:
+# Major module for Mathnet API.
+module Mathnet
+ # WEB Crawler to simulate mathnet web site via API.
+ module Crawler
+ # Base class for main kind of data on mathnet.
class Entry
- module Listable
+ # Module to store list operations with entries.
+ module Listable
CSS_FILTER = 'a.SLink'
def list(parent)
@@ -20,12 +24,13 @@
end
end
end
-
+
def title
@title.delete("\r\n").delete("\n")
end
end
+ # Custom client to make http requests.
class HTTPClient
def initialize(host: 'www.mathnet.ru')
@base_uri = URI('http://' + host)
@@ -64,12 +69,14 @@
end
end
+ # Class represent mathnet main page.
class Library
def children_url
'/ej.phtml'
end
end
+ # Science journal.
class Journal < Entry
@detail_url_reqexp = %r{/php/journal.phtml}
@@ -89,6 +96,7 @@
end
end
+ # Single issues of journal.
class Issue < Entry
@detail_url_reqexp = %r{/php/archive.phtml?.*wshow=issue}
@@ -110,6 +118,7 @@
end
end
+ # Single article of issues.
class Article < Entry
@detail_url_reqexp = %r{/rus/}
@@ -140,14 +149,12 @@
def full_text(&block)
client = HTTPClient.new
payload = client.get full_text_url
- if payload['Content-Type'] != 'text/html'
- block.call payload.body
- end
+ block.call payload.body if payload['Content-Type'] != 'text/html'
end
def journal_title
@parent.journal_title
- end
+ end
end
end
end
diff --git a/lib/mathnet/crawler/version.rb b/lib/mathnet/crawler/version.rb
index 127b2f8..f3b7830 100644
--- a/lib/mathnet/crawler/version.rb
+++ b/lib/mathnet/crawler/version.rb
@@ -1,5 +1,5 @@
module Mathnet # :nodoc:
module Crawler # :nodoc:
- VERSION = '0.1.0'
+ VERSION = '0.1.1'
end
end
diff --git a/mathnet-crawler.gemspec b/mathnet-crawler.gemspec
index c21f659..3bf55ab 100644
--- a/mathnet-crawler.gemspec
+++ b/mathnet-crawler.gemspec
@@ -10,7 +10,8 @@
spec.email = ['eoskin@crystalnix.com']
spec.summary = 'Tool kit to operate with mathnet.ru'
- spec.description = 'The Library provides API and CLI to operate with mathnet.ru.'
+ spec.description = 'The Library provides API and CLI to' \
+ 'operate with mathnet.ru.'
spec.homepage = 'https://github.com/EvgeneOskin/ruby-mathnet-crawler'
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
@@ -41,4 +42,6 @@
spec.add_development_dependency 'rspec', '~> 3.3.0'
spec.add_development_dependency 'simplecov', '~> 0.10.0'
spec.add_development_dependency 'webmock', '~> 1.22.1'
+ spec.add_development_dependency 'coveralls', '~> 0.8.3'
+ spec.add_development_dependency 'yard', '~> 0.8'
end
diff --git a/spec/crawler_spec.rb b/spec/crawler_spec.rb
index e8332c9..12805f6 100644
--- a/spec/crawler_spec.rb
+++ b/spec/crawler_spec.rb
@@ -12,269 +12,345 @@
end
it 'single journal' do
- single_journal = %{
+ single_journal = %q(
<table><tbody><tr>
- <td><a name="JPUBLISHER8"><b><i>Российская академия наук, Отделение математических наук</i></b></a></td>
+ <td><a name="JPUBLISHER8"><b><i>Российская академия наук,
+ Отделение математических наук</i></b></a></td>
</tr>
<tr>
- <td><a class="SLink" title="Алгебра и анализ" href="/php/journal.phtml?jrnid=aa&option_lang=rus">Алгебра и анализ</a></td>
- <td>Свободный доступ к полным текстам предоставляется по прошествии трех лет с момента выхода соответствующего номера журнала</td>
+ <td><a class="SLink" title="Алгебра и анализ"
+ href="/php/journal.phtml?jrnid=aa&option_lang=rus">
+ Алгебра и анализ
+ </a></td>
+ <td>Свободный доступ к полным текстам предоставляется по прошествии
+ трех лет с момента выхода соответствующего номера журнала</td>
</tr></tbody></table>
- }
- stub_request(:get, @download_link).
- to_return(status: 200, body: single_journal, headers: {})
+ )
+ stub_request(:get, @download_link)
+ .to_return(status: 200, body: single_journal, headers: {})
journals = Journal.list Library.new
expect(journals).to be_a Array
expect(journals.size).to eq 1
expect(journals[0].title).to eq 'Алгебра и анализ'
- expect(journals[0].children_url).to eq '/php/archive.phtml?wshow=contents&jrnid=aa&option_lang=rus'
+ expect(journals[0].children_url).to eq '/php/archive.phtml' \
+ '?wshow=contents&jrnid=aa&option_lang=rus'
end
it 'no journals' do
- stub_request(:get, @download_link).
- to_return(status: 200, body: '', headers: {})
+ stub_request(:get, @download_link)
+ .to_return(status: 200, body: '', headers: {})
journals = Journal.list Library.new
expect(journals).to be_a Array
expect(journals).to eq []
end
it 'raise socket error' do
- stub_request(:get, @download_link).
- to_raise SocketError
+ stub_request(:get, @download_link)
+ .to_raise SocketError
expect { Journal.list Library.new } .to raise_error SocketError
end
it 'raise server exception' do
- stub_request(:get, @download_link).
- to_return(status: 400, body: '', headers: {})
+ stub_request(:get, @download_link)
+ .to_return(status: 400, body: '', headers: {})
expect { Journal.list Library.new } .to raise_error Net::HTTPServerException
end
-
end
RSpec.describe Issue, '#list' do
-
before :each do
- tag = {'title' => 'Test', 'href' => '/php/journal.phtml?jrnid=aa'}
+ tag = { 'title' => 'Test', 'href' => '/php/journal.phtml?jrnid=aa' }
@journal = Journal.new Library.new, tag
@download_link = 'www.mathnet.ru/php/archive.phtml?jrnid=aa&wshow=contents'
end
it 'single issue' do
- single_journal = %{
+ issue_link = '/php/archive.phtml?jrnid=da&wshow=issue&series=0' \
+ '&year=2015&volume=22&volume_alt=&issue=1&issue_alt=&option_lang=rus'
+ single_issue = %(
<table><tbody><tr>
- <td"7"><br>Дискретный анализ и исследование операций</td>
- </tr>
- <tr><td>
- <img align="absmiddle" src="/gifs/wvols.gif" border="0"> том 22, 2015
- / <a class="SLink" target="_top" href="/php/contents.phtml?jrnid=da&wshow=aindex&year=2015&volume=22&volume_alt=&option_lang=rus">Именной указатель</a>
+ <td"7"><br>Дискретный анализ и исследование операций</td>
+ </tr>
+ <tr><td>
+ <img align="absmiddle" src="/gifs/wvols.gif" border="0"> том 22, 2015
+ <a class="SLink" target="_top"
+ href="/php/contents.phtml?jrnid=da&wshow=aindex&year=2015
+ &volume=22&volume_alt=&option_lang=rus">Именной указатель
+ </a>
</td></tr>
- <tr>
+ <tr>
<td class="series"></td>
- <td title="Дискретн. анализ и исслед. опер., том 22, 2015, номер 1">
- <a title="Дискретн. анализ и исслед. опер., том 22, 2015, номер 1" class="SLink" href="/php/archive.phtml?jrnid=da&wshow=issue&series=0&year=2015&volume=22&volume_alt=&issue=1&issue_alt=&option_lang=rus"><nobr>1</nobr></a>
+ <td title="Дискретн. анализ и исслед. опер., том 22, 2015, номер 1">
+ <a title="Дискретн. анализ и исслед. опер., том 22, 2015, номер 1"
+ class="SLink" href="#{issue_link}">
+ <nobr>1</nobr>
+ </a>
</td>
<img align="absmiddle" src="/gifs/wvols.gif" border="0"> том 21, 2014
- / <a class="SLink" target="_top" href="Дискретн. анализ и исслед. опер., том 22, 2015, номер 1">Именной указатель</a></td>
- </tr>
+ <a class="SLink" target="_top"
+ href="Дискретн. анализ и исслед. опер., том 22, 2015, номер 1">
+ Именной указатель
+ </a>
+ </tr>
</tbody></table>
- }
- stub_request(:get, @download_link).
- to_return(status: 200, body: single_journal, headers: {})
+ )
+ stub_request(:get, @download_link)
+ .to_return(status: 200, body: single_issue, headers: {})
issues = Issue.list @journal
expect(issues).to be_a Array
expect(issues.size).to eq 1
- expect(issues[0].title).to eq 'Дискретн. анализ и исслед. опер., том 22, 2015, номер 1'
- expect(issues[0].children_url).to eq '/php/archive.phtml?jrnid=da&wshow=issue&series=0&year=2015&volume=22&volume_alt=&issue=1&issue_alt=&option_lang=rus'
+ expect(issues[0].title).to eq 'Дискретн. анализ и исслед. опер., том 22' \
+ ', 2015, номер 1'
+ expect(issues[0].children_url).to eq issue_link
end
it '3 issues' do
- single_journal = %{
+ issue_links = [
+ '/php/archive.phtml?jrnid=da&wshow=issue&' \
+ 'series=0&year=2015&volume=22&volume_alt=&' \
+ 'issue=1&issue_alt=&option_lang=rus',
+ '/php/archive.phtml?jrnid=da&wshow=issue&series=0&' \
+ 'year=2012&volume=19&volume_alt=&issue=1&' \
+ 'issue_alt=&option_lang=rus',
+ '/php/archive.phtml?' \
+ 'jrnid=da&wshow=issue&series=0&year=2011&' \
+ 'volume=18&volume_alt=&issue=1&issue_alt=&' \
+ 'option_lang=rus'
+ ]
+ three_issues = %(
<table><tbody>
- <tr>
- <td title="Дискретн. анализ и исслед. опер., том 22, 2015, номер 1">
- <a title="Дискретн. анализ и исслед. опер., том 22, 2015, номер 1" class="SLink" href="/php/archive.phtml?jrnid=da&wshow=issue&series=0&year=2015&volume=22&volume_alt=&issue=1&issue_alt=&option_lang=rus"><nobr>1</nobr></a>
- </td>
- <img align="absmiddle" src="/gifs/wvols.gif" border="0"> том 21, 2014
- / <a class="SLink" target="_top" href="Дискретн. анализ и исслед. опер., том 22, 2015, номер 1">Именной указатель</a></td>
- <td title="Дискретн. анализ и исслед. опер., том 19, 2012, номер 1 Доступны полные тексты статей"class="issue_with_corner" align="center">
- <a title="Дискретн. анализ и исслед. опер., том 19, 2012, номер 1 Доступны полные тексты статей" class="SLink" href="/php/archive.phtml?jrnid=da&wshow=issue&series=0&year=2012&volume=19&volume_alt=&issue=1&issue_alt=&option_lang=rus"><nobr>1</nobr></a>
- </td>
- </tr>
<tr>
- <td title="Дискретн. анализ и исслед. опер., том 18, 2011, номер 1 Доступны полные тексты статей" class="issue_with_corner" align="center">
- <a title="Дискретн. анализ и исслед. опер., том 18, 2011, номер 1 Доступны полные тексты статей" class="SLink" href="/php/archive.phtml?jrnid=da&wshow=issue&series=0&year=2011&volume=18&volume_alt=&issue=1&issue_alt=&option_lang=rus"><nobr>1</nobr></a>
+ <td title="Дискретн. анализ и исслед. опер., том 22, 2015, номер 1">
+ <a title="Дискретн. анализ и исслед. опер., том 22, 2015, номер 1"
+ class="SLink" href="#{issue_links[0]}"><nobr>1</nobr>
+ </a>
</td>
- </tr>
+ <img align="absmiddle" src="/gifs/wvols.gif" border="0"> том 21, 2014
+ <a class="SLink" target="_top" href="Дискретн. анализ и исслед. опер.,
+ том 22, 2015, номер 1">Именной указатель</a></td>
+ <td title="Дискретн. анализ и исслед. опер., том 19, 2012,
+ номер 1 Доступны полные тексты статей"class="issue_with_corner"
+ align="center">
+ <a title="Дискретн. анализ и исслед. опер., том 19, 2012, номер 1"
+ class="SLink"
+ href="#{issue_links[1]}"><nobr>1</nobr></a>
+ </td>
+ </tr>
+ <tr>
+ <td title="Дискретн. анализ и исслед. опер., том 18, 2011,
+ номер 1 Доступны полные тексты статей" class="issue_with_corner"
+ align="center">
+ <a title="Дискретн. анализ и исслед. опер., том 18, 2011, номер 1"
+ class="SLink" href="#{issue_links[2]}">
+ <nobr>1</nobr>
+ </a>
+ </td>
+ </tr>
</tbody></table>
- }
- stub_request(:get, @download_link).
- to_return(status: 200, body: single_journal, headers: {})
+ )
+ stub_request(:get, @download_link)
+ .to_return(status: 200, body: three_issues, headers: {})
issues = Issue.list @journal
expect(issues).to be_a Array
expect(issues.size).to eq 3
- expect(issues[0].title).to eq 'Дискретн. анализ и исслед. опер., том 22, 2015, номер 1'
- expect(issues[0].children_url).to eq '/php/archive.phtml?jrnid=da&wshow=issue&series=0&year=2015&volume=22&volume_alt=&issue=1&issue_alt=&option_lang=rus'
- expect(issues[1].title).to eq 'Дискретн. анализ и исслед. опер., том 19, 2012, номер 1 Доступны полные тексты статей'
- expect(issues[1].children_url).to eq '/php/archive.phtml?jrnid=da&wshow=issue&series=0&year=2012&volume=19&volume_alt=&issue=1&issue_alt=&option_lang=rus'
- expect(issues[2].title).to eq 'Дискретн. анализ и исслед. опер., том 18, 2011, номер 1 Доступны полные тексты статей'
- expect(issues[2].children_url).to eq '/php/archive.phtml?jrnid=da&wshow=issue&series=0&year=2011&volume=18&volume_alt=&issue=1&issue_alt=&option_lang=rus'
-
+ expect(issues[0].title).to eq 'Дискретн. анализ и исслед. опер., том 22' \
+ ', 2015, номер 1'
+ expect(issues[0].children_url).to eq '/php/archive.phtml?jrnid=da&' \
+ 'wshow=issue&series=0&year=2015&volume=22&volume_alt=&issue=1&' \
+ 'issue_alt=&option_lang=rus'
+ expect(issues[1].title).to eq 'Дискретн. анализ и исслед. опер., том 19' \
+ ', 2012, номер 1'
+ expect(issues[1].children_url).to eq '/php/archive.phtml?jrnid=da&' \
+ 'wshow=issue&series=0&year=2012&volume=19&volume_alt=&issue=1&' \
+ 'issue_alt=&option_lang=rus'
+ expect(issues[2].title).to eq 'Дискретн. анализ и исслед. опер., том 18' \
+ ', 2011, номер 1'
+ expect(issues[2].children_url).to eq '/php/archive.phtml?jrnid=da&' \
+ 'wshow=issue&series=0&year=2011&volume=18&volume_alt=&issue=1&' \
+ 'issue_alt=&option_lang=rus'
end
it 'no issues' do
- stub_request(:get, @download_link).
- to_return(status: 200, body: '', headers: {})
+ stub_request(:get, @download_link)
+ .to_return(status: 200, body: '', headers: {})
issues = Issue.list @journal
expect(issues).to be_a Array
expect(issues).to eq []
end
it 'raise socket error' do
- stub_request(:get, @download_link).
- to_raise SocketError
- expect { Issue.list @journal } .to raise_error SocketError
+ stub_request(:get, @download_link)
+ .to_raise SocketError
+ expect { Issue.list @journal } .to raise_error SocketError
end
it 'raise server exception' do
- stub_request(:get, @download_link).
- to_return(status: 400, body: '', headers: {})
+ stub_request(:get, @download_link)
+ .to_return(status: 400, body: '', headers: {})
expect { Issue.list @journal } .to raise_error Net::HTTPServerException
end
-
end
RSpec.describe Article, '#list' do
-
before :each do
- journal_tag = {'title' => 'Test', 'href' => '/php/journal.phtml?jrnid=aa'}
+ journal_tag = {
+ 'title' => 'Test',
+ 'href' => '/php/journal.phtml?jrnid=aa'
+ }
journal = Journal.new Library.new, journal_tag
- issues_tag = {'title' => 'Test issue 1', 'href' => '/php/archive.phtml?jrnid=da&wshow=issue&series=0&year=2015&volume=22&volume_alt=&issue=1&issue_alt=&option_lang=rus'}
+ issues_tag = {
+ 'title' => 'Test issue 1',
+ 'href' => '/php/archive.phtml?jrnid=da&wshow=issue&series=0&year=2015&' \
+ 'volume=22&volume_alt=&issue=1&issue_alt=&option_lang=rus'
+ }
@issue = Issue.new journal, issues_tag
- @download_link = 'www.mathnet.ru/php/archive.phtml?issue=1&issue_alt=&jrnid=da&option_lang=rus&series=0&volume=22&volume_alt=&wshow=issue&year=2015'
+ @download_link = 'www.mathnet.ru/php/archive.phtml?issue=1&issue_alt=&' \
+ 'jrnid=da&option_lang=rus&series=0&volume=22&volume_alt=&wshow=issue&' \
+ 'year=2015'
end
it 'single issue' do
- single_journal = %{
+ issue_title = 'Алгоритм ветвей и границ для задачи конкурентного ' \
+ 'размещения предприятий с предписанным выбором поставщиков'
+ single_journal = %(
<table><tbody><tr>
- <td valign="top" width="11">
- <img title="Доступен полный текст статьи" align="absmiddle" src="/gifs/wvolsa.gif" border="0">
- </td>
- <td colspan="2" width="90%" valign="top" align="left">
- <a class="SLink" href="/rus/da763">Алгоритм ветвей и границ для задачи конкурентного размещения предприятий с предписанным выбором поставщиков</a><br>В. Л. Береснев, А. А. Мельников
- </td>
- <td valign="top" align="right">3</td>
- </tr></tbody></table>
- }
- stub_request(:get, @download_link).
- to_return(status: 200, body: single_journal, headers: {})
+ <td valign="top" width="11">
+ <img title="Доступен полный текст статьи" align="absmiddle"
+ src="/gifs/wvolsa.gif" border="0">
+ </td>
+ <td colspan="2" width="90%" valign="top" align="left">
+ <a class="SLink" href="/rus/da763">#{issue_title}</a>
+ <br>В. Л. Береснев, А. А. Мельников
+ </td>
+ <td valign="top" align="right">3</td>
+ </tr></tbody></table>
+ )
+ stub_request(:get, @download_link)
+ .to_return(status: 200, body: single_journal, headers: {})
articles = Article.list @issue
expect(articles).to be_a Array
expect(articles.size).to eq 1
- expect(articles[0].title).to eq 'Алгоритм ветвей и границ для задачи конкурентного размещения предприятий с предписанным выбором поставщиков'
+ expect(articles[0].title).to eq issue_title
expect(articles[0].children_url).to eq '/rus/da763'
end
it '3 issues' do
- single_journal = %{
+ issue_titles = [
+ 'Пороговое свойство квадратичных булевых функций',
+ 'Функция Шеннона быстрого вычисления сложности по Арнольду ' \
+ 'двоичных слов длины',
+ 'Совершенные 22-раскраски бесконечных циркулянтных графов со сплошным' \
+ 'набором дистанций'
+ ]
+ single_journal = %(
<table><tbody>
<tr>
- <td valign="top" width="11">
- <img title="Доступен полный текст статьи" align="absmiddle" src="/gifs/wvolsa.gif" border="0">
- </td>
- <td colspan="2" width="90%" valign="top" align="left">
- <a class="SLink" href="/rus/da766">Пороговое свойство квадратичных булевых функций</a><br>Н. А. Коломеец
- </td>
- <td valign="top" align="right">52</td>
- </tr>
+ <td valign="top" width="11">
+ <img title="Доступен полный текст статьи" align="absmiddle"
+ src="/gifs/wvolsa.gif" border="0">
+ </td>
+ <td colspan="2" width="90%" valign="top" align="left">
+ <a class="SLink" href="/rus/da766">#{issue_titles[0]}</a>
+ <br>Н. А. Коломеец
+ </td>
+ <td valign="top" align="right">52</td>
+ </tr>
<tr>
- <td valign="top" width="11">
- <img title="Доступен полный текст статьи" align="absmiddle" src="/gifs/wvolsa.gif" border="0">
- </td>
- <td colspan="2" width="90%" valign="top" align="left">
- <a class="SLink" href="/rus/da767">Функция Шеннона быстрого вычисления сложности по Арнольду двоичных слов длины <nobr><span class="MathJax_Preview" style="color: inherit;"></span><span class="MathJax" id="MathJax-Element-1-Frame" style=""><nobr><span class="math" id="MathJax-Span-1" role="math" style="width: 1.253em; display: inline-block;"><span style="display: inline-block; position: relative; width: 1.044em; height: 0px; font-size: 120%;"><span style="position: absolute; clip: rect(0.107em, 1000.003em, 1.148em, -999.997em); top: -0.987em; left: 0.003em;"><span class="mrow" id="MathJax-Span-2"><span class="msubsup" id="MathJax-Span-3"><span style="display: inline-block; position: relative; width: 0.992em; height: 0px;"><span style="position: absolute; clip: rect(3.18em, 1000.003em, 4.169em, -999.997em); top: -4.008em; left: 0.003em;"><span class="mn" id="MathJax-Span-4" style="font-family: MathJax_Main;">2</span><span style="display: inline-block; width: 0px; height: 4.013em;"></span></span><span style="position: absolute; top: -4.424em; left: 0.523em;"><span class="mi" id="MathJax-Span-5" style="font-size: 70.7%; font-family: MathJax_Math-italic;">n</span><span style="display: inline-block; width: 0px; height: 4.013em;"></span></span></span></span></span><span style="display: inline-block; width: 0px; height: 0.992em;"></span></span></span><span style="border-left-width: 0.003em; border-left-style: solid; display: inline-block; overflow: hidden; width: 0px; height: 1.003em; vertical-align: -0.059em;"></span></span></nobr></span><script type="math/tex" id="MathJax-Element-1">2^n</script></nobr> для произвольных значений <nobr><span class="MathJax_Preview" style="color: inherit;"></span><span class="MathJax" id="MathJax-Element-2-Frame" style=""><nobr><span class="math" id="MathJax-Span-6" role="math" style="width: 0.784em; display: inline-block;"><span style="display: inline-block; position: relative; width: 0.628em; height: 0px; font-size: 120%;"><span style="position: absolute; clip: rect(1.93em, 1000.003em, 2.659em, -999.997em); top: -2.497em; left: 0.003em;"><span class="mrow" id="MathJax-Span-7"><span class="mi" id="MathJax-Span-8" style="font-family: MathJax_Math-italic;">n</span></span><span style="display: inline-block; width: 0px; height: 2.503em;"></span></span></span><span style="border-left-width: 0.003em; border-left-style: solid; display: inline-block; overflow: hidden; width: 0px; height: 0.691em; vertical-align: -0.059em;"></span></span></nobr></span><script type="math/tex" id="MathJax-Element-2">n</script></nobr></a><br>Ю. В. Мерекин
- </td>
- <td valign="top" align="right">59</td>
- </tr>
+ <td valign="top" width="11">
+ <img title="Доступен полный текст статьи" align="absmiddle"
+ src="/gifs/wvolsa.gif" border="0">
+ </td>
+ <td colspan="2" width="90%" valign="top" align="left">
+ <a class="SLink" href="/rus/da767">#{issue_titles[1]}</a>
+ <br>Ю. В. Мерекин
+ </td>
+ <td valign="top" align="right">59</td>
+ </tr>
<tr>
- <td valign="top" width="11">
- <img title="Доступен полный текст статьи" align="absmiddle" src="/gifs/wvolsa.gif" border="0">
- </td>
- <td colspan="2" width="90%" valign="top" align="left">
- <a class="SLink" href="/rus/da768">Совершенные <nobr><span class="MathJax_Preview" style="color: inherit;"></span><span class="MathJax" id="MathJax-Element-3-Frame" style=""><nobr><span class="math" id="MathJax-Span-9" role="math" style="width: 0.628em; display: inline-block;"><span style="display: inline-block; position: relative; width: 0.523em; height: 0px; font-size: 120%;"><span style="position: absolute; clip: rect(1.878em, 1000.003em, 2.867em, -999.997em); top: -2.706em; left: 0.003em;"><span class="mrow" id="MathJax-Span-10"><span class="mn" id="MathJax-Span-11" style="font-family: MathJax_Main;">2</span></span><span style="display: inline-block; width: 0px; height: 2.711em;"></span></span></span><span style="border-left-width: 0.003em; border-left-style: solid; display: inline-block; overflow: hidden; width: 0px; height: 0.941em; vertical-align: -0.059em;"></span></span></nobr></span><script type="math/tex" id="MathJax-Element-3">2</script></nobr>-раскраски бесконечных циркулянтных графов со сплошным набором дистанций</a><br>О. Г. Паршина
- </td>
- <td valign="top" align="right">76</td>
- </tr>
+ <td valign="top" width="11">
+ <img title="Доступен полный текст статьи" align="absmiddle"
+ src="/gifs/wvolsa.gif" border="0">
+ </td>
+ <td colspan="2" width="90%" valign="top" align="left">
+ <a class="SLink" href="/rus/da768">#{issue_titles[2]}</a>
+ <br>О. Г. Паршина
+ </td>
+ <td valign="top" align="right">76</td>
+ </tr>
</tbody></table>
- }
- stub_request(:get, @download_link).
- to_return(status: 200, body: single_journal, headers: {})
+ )
+ stub_request(:get, @download_link)
+ .to_return(status: 200, body: single_journal, headers: {})
articles = Article.list @issue
expect(articles).to be_a Array
expect(articles.size).to eq 3
- expect(articles[0].title).to eq 'Пороговое свойство квадратичных булевых функций'
+ expect(articles[0].title).to eq issue_titles[0]
expect(articles[0].children_url).to eq '/rus/da766'
- expect(articles[1].title).to eq 'Функция Шеннона быстрого вычисления сложности по Арнольду двоичных слов длины 2n2^n для произвольных значений nn'
+ expect(articles[1].title).to eq issue_titles[1]
expect(articles[1].children_url).to eq '/rus/da767'
- expect(articles[2].title).to eq 'Совершенные 22-раскраски бесконечных циркулянтных графов со сплошным набором дистанций'
+ expect(articles[2].title).to eq issue_titles[2]
expect(articles[2].children_url).to eq '/rus/da768'
end
it 'no issues' do
- stub_request(:get, @download_link).
- to_return(status: 200, body: '', headers: {})
+ stub_request(:get, @download_link)
+ .to_return(status: 200, body: '', headers: {})
articles = Article.list @issue
expect(articles).to be_a Array
expect(articles).to eq []
end
it 'raise socket error' do
- stub_request(:get, @download_link).
- to_raise SocketError
- expect { Article.list @issue } .to raise_error SocketError
+ stub_request(:get, @download_link)
+ .to_raise SocketError
+ expect { Article.list @issue } .to raise_error SocketError
end
it 'raise server exception' do
- stub_request(:get, @download_link).
- to_return(status: 400, body: '', headers: {})
+ stub_request(:get, @download_link)
+ .to_return(status: 400, body: '', headers: {})
expect { Article.list @issue } .to raise_error Net::HTTPServerException
end
-
end
RSpec.describe Article, '#full_text' do
-
before :each do
- journal_tag = {'title' => 'Test', 'href' => '/php/journal.phtml?jrnid=aa'}
+ journal_tag = {
+ 'title' => 'Test',
+ 'href' => '/php/journal.phtml?jrnid=aa'
+ }
journal = Journal.new Library.new, journal_tag
- issues_tag = {'title' => 'Test issue 1', 'href' => '/php/archive.phtml?jrnid=da&wshow=issue&series=0&year=2015&volume=22&volume_alt=&issue=1&issue_alt=&option_lang=rus'}
+ issues_tag = {
+ 'title' => 'Test issue 1',
+ 'href' => '/php/archive.phtml?jrnid=da&wshow=issue&series=0&year=2015&' \
+ 'volume=22&volume_alt=&issue=1&issue_alt=&option_lang=rus'
+ }
issue = Issue.new journal, issues_tag
- article_tag = double("Article Tag", :text => 'Article')
+ article_tag = double('Article Tag', text: 'Article')
allow(article_tag).to receive(:[]).with('title').and_return 'Test article 1'
allow(article_tag).to receive(:[]).with('href').and_return '/rus/da766'
@article = Article.new issue, article_tag
@download_link = 'www.mathnet.ru/rus/da766'
- @full_text_url = '/php/getFT.phtml?jrnid=da&paperid=763&what=fullt&option_lang=rus'
+ @full_text_url = '/php/getFT.phtml?jrnid=da&paperid=763&what=fullt&' \
+ 'option_lang=rus'
@full_text_link = "www.mathnet.ru#{@full_text_url}"
end
it 'single issue' do
- single_journal = %{
+ single_journal = %(
<a class="SLink" href="#{@full_text_url}">PDF файл</a>
- }
- stub_request(:get, @download_link).
- to_return(status: 200, body: single_journal, headers: {})
- stub_request(:get, @full_text_link).
- to_return(status: 200, body: single_journal, headers: {})
+ )
+ stub_request(:get, @download_link)
+ .to_return(status: 200, body: single_journal, headers: {})
+ stub_request(:get, @full_text_link)
+ .to_return(status: 200, body: single_journal, headers: {})
@article.full_text {}
end
it 'no full test' do
- single_journal = %{}
- stub_request(:get, @download_link).
- to_return(status: 200, body: single_journal, headers: {})
+ single_journal = ''
+ stub_request(:get, @download_link)
+ .to_return(status: 200, body: single_journal, headers: {})
expect { @article.full_text {} } .to raise_error ArgumentError
end
-
end
-
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index b12cd84..f8f0847 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,6 +1,11 @@
require 'simplecov'
+require 'coveralls'
+
+SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
+ SimpleCov::Formatter::HTMLFormatter,
+ Coveralls::SimpleCov::Formatter
+]
SimpleCov.start
-SimpleCov.command_name "features" + (ENV['TEST_ENV_NUMBER'] || '')
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|