rika 1.6.0-java → 2.0.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +6 -4
- data/.rubocop.yml +49 -0
- data/Gemfile +12 -0
- data/README.md +226 -47
- data/RELEASE_NOTES.md +43 -0
- data/Rakefile +4 -7
- data/bin/rika +13 -0
- data/lib/rika/cli/args_parser.rb +131 -0
- data/lib/rika/cli/rika_command.rb +129 -0
- data/lib/rika/formatters.rb +39 -0
- data/lib/rika/parse_result.rb +34 -0
- data/lib/rika/parser.rb +84 -0
- data/lib/rika/tika_loader.rb +65 -0
- data/lib/rika/version.rb +3 -1
- data/lib/rika.rb +96 -104
- data/pom.xml +2 -2
- data/rika.gemspec +30 -15
- data/rika_helper.rb +30 -0
- data/spec/fixtures/de.txt +21 -1
- data/spec/fixtures/document.doc +0 -0
- data/spec/fixtures/document.docx +0 -0
- data/spec/fixtures/document.pdf +0 -0
- data/spec/fixtures/document.txt +23 -0
- data/spec/fixtures/en.txt +23 -1
- data/spec/fixtures/es.txt +21 -1
- data/spec/fixtures/fr.txt +23 -1
- data/spec/fixtures/image_jpg_without_extension +0 -0
- data/spec/fixtures/ru.txt +21 -1
- data/spec/fixtures/tiny.txt +1 -0
- data/spec/rika/cli/args_parser_spec.rb +117 -0
- data/spec/rika/cli/rika_command_spec.rb +120 -0
- data/spec/rika/formatters_spec.rb +23 -0
- data/spec/rika/parse_result_spec.rb +42 -0
- data/spec/rika/parser_spec.rb +304 -0
- data/spec/rika/rika_spec.rb +10 -0
- data/spec/rika/tika_loader_spec.rb +57 -0
- data/spec/spec_helper.rb +13 -5
- metadata +54 -98
- data/.travis.yml +0 -7
- data/spec/fixtures/over_100k_file.txt +0 -1241
- data/spec/fixtures/text_file.txt +0 -1
- data/spec/fixtures/text_file_without_extension +0 -1
- data/spec/rika_spec.rb +0 -202
- data/target/dependency/apache-mime4j-core-0.7.2.jar +0 -0
- data/target/dependency/apache-mime4j-dom-0.7.2.jar +0 -0
- data/target/dependency/asm-debug-all-4.1.jar +0 -0
- data/target/dependency/aspectjrt-1.8.0.jar +0 -0
- data/target/dependency/bcmail-jdk15-1.45.jar +0 -0
- data/target/dependency/bcprov-jdk15-1.45.jar +0 -0
- data/target/dependency/boilerpipe-1.1.0.jar +0 -0
- data/target/dependency/commons-codec-1.9.jar +0 -0
- data/target/dependency/commons-compress-1.8.1.jar +0 -0
- data/target/dependency/commons-httpclient-3.1.jar +0 -0
- data/target/dependency/commons-logging-1.1.1.jar +0 -0
- data/target/dependency/fontbox-1.8.6.jar +0 -0
- data/target/dependency/isoparser-1.0.2.jar +0 -0
- data/target/dependency/java-libpst-0.8.1.jar +0 -0
- data/target/dependency/jcip-annotations-1.0.jar +0 -0
- data/target/dependency/jdom-1.0.jar +0 -0
- data/target/dependency/jempbox-1.8.6.jar +0 -0
- data/target/dependency/jhighlight-1.0.jar +0 -0
- data/target/dependency/jmatio-1.0.jar +0 -0
- data/target/dependency/juniversalchardet-1.0.3.jar +0 -0
- data/target/dependency/metadata-extractor-2.6.2.jar +0 -0
- data/target/dependency/netcdf-4.2.20.jar +0 -0
- data/target/dependency/pdfbox-1.8.6.jar +0 -0
- data/target/dependency/poi-3.11-beta2.jar +0 -0
- data/target/dependency/poi-ooxml-3.11-beta2.jar +0 -0
- data/target/dependency/poi-ooxml-schemas-3.11-beta2.jar +0 -0
- data/target/dependency/poi-scratchpad-3.11-beta2.jar +0 -0
- data/target/dependency/rome-1.0.jar +0 -0
- data/target/dependency/slf4j-api-1.6.1.jar +0 -0
- data/target/dependency/tagsoup-1.2.1.jar +0 -0
- data/target/dependency/tika-core-1.6.jar +0 -0
- data/target/dependency/tika-parsers-1.6.jar +0 -0
- data/target/dependency/unidataCommon-4.2.20.jar +0 -0
- data/target/dependency/vorbis-java-core-0.6.jar +0 -0
- data/target/dependency/vorbis-java-tika-0.6.jar +0 -0
- data/target/dependency/xercesImpl-2.8.1.jar +0 -0
- data/target/dependency/xml-apis-1.3.03.jar +0 -0
- data/target/dependency/xmlbeans-2.6.0.jar +0 -0
- data/target/dependency/xmpcore-5.1.2.jar +0 -0
- data/target/dependency/xz-1.5.jar +0 -0
data/spec/fixtures/de.txt
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
Eines verschneiten Abends im Wald verhaltend (German)
|
|
2
|
+
|
|
3
|
+
Wohl weiß ich, wer den Wald besitzt,
|
|
4
|
+
Sein Haus jedoch im Dorf dort ist;
|
|
5
|
+
Er merkt nicht, wie ich hier verharr'
|
|
6
|
+
Zu schaun, wie Wald den Schnee begrüßt.
|
|
7
|
+
|
|
8
|
+
Mein Pferdchen denkt, ich wär ein Narr,
|
|
9
|
+
Zu halten, wo nicht Haus noch Farm,
|
|
10
|
+
Im Wald, nah beim gefrornen Teich,
|
|
11
|
+
Am finstersten Abend im Jahr.
|
|
12
|
+
|
|
13
|
+
Des Zaumzeugs Glöckchen klingen leis:
|
|
14
|
+
Es fragt: was ist? geht's weiter gleich?
|
|
15
|
+
Ansonsten hört man nur ganz sacht
|
|
16
|
+
Den Schneefall und den Wind, der streicht.
|
|
17
|
+
|
|
18
|
+
Der Wald ist nett, tief wie die Nacht,
|
|
19
|
+
Doch halte ich, was ich versprach,
|
|
20
|
+
Und Meilen sind's noch bis zum Schlaf,
|
|
21
|
+
Und Meilen sind's noch bis zum Schlaf.
|
data/spec/fixtures/document.doc
CHANGED
|
Binary file
|
data/spec/fixtures/document.docx
CHANGED
|
Binary file
|
data/spec/fixtures/document.pdf
CHANGED
|
Binary file
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Stopping by Woods on a Snowy Evening
|
|
2
|
+
|
|
3
|
+
By Robert Frost
|
|
4
|
+
|
|
5
|
+
Whose woods these are I think I know.
|
|
6
|
+
His house is in the village though;
|
|
7
|
+
He will not see me stopping here
|
|
8
|
+
To watch his woods fill up with snow.
|
|
9
|
+
|
|
10
|
+
My little horse must think it queer
|
|
11
|
+
To stop without a farmhouse near
|
|
12
|
+
Between the woods and frozen lake
|
|
13
|
+
The darkest evening of the year.
|
|
14
|
+
|
|
15
|
+
He gives his harness bells a shake
|
|
16
|
+
To ask if there is some mistake.
|
|
17
|
+
The only other sound’s the sweep
|
|
18
|
+
Of easy wind and downy flake.
|
|
19
|
+
|
|
20
|
+
The woods are lovely, dark and deep,
|
|
21
|
+
But I have promises to keep,
|
|
22
|
+
And miles to go before I sleep,
|
|
23
|
+
And miles to go before I sleep.
|
data/spec/fixtures/en.txt
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
Stopping by Woods on a Snowy Evening
|
|
2
|
+
|
|
3
|
+
By Robert Frost
|
|
4
|
+
|
|
5
|
+
Whose woods these are I think I know.
|
|
6
|
+
His house is in the village though;
|
|
7
|
+
He will not see me stopping here
|
|
8
|
+
To watch his woods fill up with snow.
|
|
9
|
+
|
|
10
|
+
My little horse must think it queer
|
|
11
|
+
To stop without a farmhouse near
|
|
12
|
+
Between the woods and frozen lake
|
|
13
|
+
The darkest evening of the year.
|
|
14
|
+
|
|
15
|
+
He gives his harness bells a shake
|
|
16
|
+
To ask if there is some mistake.
|
|
17
|
+
The only other sound’s the sweep
|
|
18
|
+
Of easy wind and downy flake.
|
|
19
|
+
|
|
20
|
+
The woods are lovely, dark and deep,
|
|
21
|
+
But I have promises to keep,
|
|
22
|
+
And miles to go before I sleep,
|
|
23
|
+
And miles to go before I sleep.
|
data/spec/fixtures/es.txt
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
Un alto en el bosque mientras nieva
|
|
2
|
+
|
|
3
|
+
De quién es este bosque, saber creo
|
|
4
|
+
-en el poblado su morada veo-
|
|
5
|
+
no habrá de sorprenderme contemplando
|
|
6
|
+
cubrir su bosque el invernal blanqueo.
|
|
7
|
+
|
|
8
|
+
Mi caballito se dirá extrañado
|
|
9
|
+
que, sin granja cercana, hemos parado
|
|
10
|
+
de este año en la tarde más oscura,
|
|
11
|
+
entre el bosque y el lago congelado.
|
|
12
|
+
|
|
13
|
+
Sacudiéndose, agita su cencerro
|
|
14
|
+
preguntando quizá: -¿será algún yerro?
|
|
15
|
+
Sólo el cierzo y los copos rumorean
|
|
16
|
+
blandamente del bosque en el encierro.
|
|
17
|
+
|
|
18
|
+
Yo, el bosque hondo y fusco veo risueño...
|
|
19
|
+
Mas, en cumplir promesas tengo empeño,
|
|
20
|
+
y millas debo andar antes del sueño,
|
|
21
|
+
un largo andar para llegar al sueño.
|
data/spec/fixtures/fr.txt
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
|
-
En
|
|
1
|
+
En s'arrêtant par les bois un soir de neige
|
|
2
|
+
|
|
3
|
+
Auteur: Robert Frost
|
|
4
|
+
|
|
5
|
+
À qui sont ces bois, je crois que je sais.
|
|
6
|
+
Sa maison est au village pourtant ;
|
|
7
|
+
Il ne me verra pas m'arrêter ici
|
|
8
|
+
À regarder ses bois recouverts de neige.
|
|
9
|
+
|
|
10
|
+
Mon petit cheval doit trouver cela étrange
|
|
11
|
+
De s'arrêter loin de toute ferme aux alentours
|
|
12
|
+
Entre ces bois et ce lac gelé
|
|
13
|
+
Au soir le plus sombre de l'année.
|
|
14
|
+
|
|
15
|
+
Il fait tinter les clochettes de son harnais en tirant dessus
|
|
16
|
+
Comme pour demander s'il n'y a pas là quelque erreur.
|
|
17
|
+
Les seuls autres bruits le souffle
|
|
18
|
+
D'une brise légère et le son duveteux des flocons.
|
|
19
|
+
|
|
20
|
+
Les bois sont beaux, sombres et profonds,
|
|
21
|
+
Mais j'ai des promesses à tenir
|
|
22
|
+
Et un long chemin à parcourir avant de dormir,
|
|
23
|
+
Et un long chemin à parcourir avant de dormir.
|
|
Binary file
|
data/spec/fixtures/ru.txt
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
Остановившись у леса снежным вечером
|
|
2
|
+
|
|
3
|
+
Чей лес, мне кажется, я знаю:
|
|
4
|
+
в селе живет его хозяин.
|
|
5
|
+
Он не увидит, как на снежный
|
|
6
|
+
я лес его стою взираю.
|
|
7
|
+
|
|
8
|
+
В недоуменье конь, конечно,
|
|
9
|
+
зачем в ночи за год темнейшей
|
|
10
|
+
мы стали там, где нет жилья,
|
|
11
|
+
у леса с озером замерзшим.
|
|
12
|
+
|
|
13
|
+
Он, бубенцом слегка звеня,
|
|
14
|
+
как будто бы корит меня,
|
|
15
|
+
да веет слабый ветерок,
|
|
16
|
+
пушистым снегом шелестя.
|
|
17
|
+
|
|
18
|
+
Лес сладок, темен и глубок,
|
|
19
|
+
но в путь пора мне — долг есть долг.
|
|
20
|
+
И ехать долго — сон далек,
|
|
21
|
+
и ехать долго — сон далек.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hello
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
require 'rika/cli/args_parser'
|
|
6
|
+
|
|
7
|
+
describe ArgsParser do
|
|
8
|
+
let(:versions_regex) { /Versions:.*Rika: (\d+\.\d+\.\d+(-\w+)?).*Tika: (\d+\.\d+\.\d+(-\w+)?)/ }
|
|
9
|
+
|
|
10
|
+
specify 'returns a hash of options, a target array, and help text' do
|
|
11
|
+
options, targets, help_text = described_class.call([])
|
|
12
|
+
expect(options).to be_a(Hash)
|
|
13
|
+
expect(targets).to be_an(Array)
|
|
14
|
+
expect(help_text).to be_a(String)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context 'when parsing options' do
|
|
18
|
+
RSpec.shared_examples 'sets_options_correctly' do |args, option_key, expected_value|
|
|
19
|
+
specify "correctly sets #{option_key} to #{expected_value} when args are #{args}" do
|
|
20
|
+
options, _, _ = described_class.call(args)
|
|
21
|
+
expect(options[option_key]).to eq(expected_value)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Test default option values:
|
|
26
|
+
include_examples('sets_options_correctly', [], :as_array, false)
|
|
27
|
+
include_examples('sets_options_correctly', [], :text, true)
|
|
28
|
+
include_examples('sets_options_correctly', [], :metadata, true)
|
|
29
|
+
include_examples('sets_options_correctly', [], :format, 'at')
|
|
30
|
+
include_examples('sets_options_correctly', [], :key_sort, true)
|
|
31
|
+
include_examples('sets_options_correctly', [], :source, true)
|
|
32
|
+
|
|
33
|
+
# Test -a as_array option:
|
|
34
|
+
include_examples('sets_options_correctly', %w[-a], :as_array, true)
|
|
35
|
+
include_examples('sets_options_correctly', %w[--as_array], :as_array, true)
|
|
36
|
+
include_examples('sets_options_correctly', %w[-a -a-], :as_array, false)
|
|
37
|
+
include_examples('sets_options_correctly', %w[--no-as_array], :as_array, false)
|
|
38
|
+
|
|
39
|
+
# Test -f format option:
|
|
40
|
+
include_examples('sets_options_correctly', %w[-fyy], :format, 'yy')
|
|
41
|
+
include_examples('sets_options_correctly', %w[--format yy], :format, 'yy')
|
|
42
|
+
include_examples('sets_options_correctly', %w[-f yy], :format, 'yy')
|
|
43
|
+
include_examples('sets_options_correctly', %w[-f y], :format, 'yy')
|
|
44
|
+
include_examples('sets_options_correctly', %w[-f yj], :format, 'yj')
|
|
45
|
+
include_examples('sets_options_correctly', %w[-f yjJ], :format, 'yj') # Test extra characters after valid format
|
|
46
|
+
|
|
47
|
+
# Test -m metadata option:
|
|
48
|
+
include_examples('sets_options_correctly', %w[-m- -m], :metadata, true)
|
|
49
|
+
include_examples('sets_options_correctly', %w[-m- -m+], :metadata, true)
|
|
50
|
+
include_examples('sets_options_correctly', %w[--metadata false --metadata], :metadata, true)
|
|
51
|
+
include_examples('sets_options_correctly', %w[-m -m-], :metadata, false)
|
|
52
|
+
include_examples('sets_options_correctly', %w[-m yes], :metadata, true)
|
|
53
|
+
include_examples('sets_options_correctly', %w[-m no], :metadata, false)
|
|
54
|
+
include_examples('sets_options_correctly', %w[-m true], :metadata, true)
|
|
55
|
+
include_examples('sets_options_correctly', %w[-m false], :metadata, false)
|
|
56
|
+
include_examples('sets_options_correctly', %w[--metadata false], :metadata, false)
|
|
57
|
+
include_examples('sets_options_correctly', %w[--no-metadata], :metadata, false)
|
|
58
|
+
|
|
59
|
+
# Test -t text option:
|
|
60
|
+
include_examples('sets_options_correctly', %w[-t], :text, true)
|
|
61
|
+
include_examples('sets_options_correctly', %w[-t -t-], :text, false)
|
|
62
|
+
include_examples('sets_options_correctly', %w[-t yes], :text, true)
|
|
63
|
+
include_examples('sets_options_correctly', %w[-t no], :text, false)
|
|
64
|
+
include_examples('sets_options_correctly', %w[-t true], :text, true)
|
|
65
|
+
include_examples('sets_options_correctly', %w[-t false], :text, false)
|
|
66
|
+
include_examples('sets_options_correctly', %w[--text false], :text, false)
|
|
67
|
+
include_examples('sets_options_correctly', %w[--text false --text], :text, true)
|
|
68
|
+
|
|
69
|
+
# Test -k key sort option:
|
|
70
|
+
include_examples('sets_options_correctly', %w[-k-], :key_sort, false)
|
|
71
|
+
|
|
72
|
+
# Test -s source option:
|
|
73
|
+
include_examples('sets_options_correctly', %w[-s-], :source, false)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe '#versions_string' do
|
|
77
|
+
specify 'returns a Rika version and a Tika version' do
|
|
78
|
+
expect(described_class.new.send(:versions_string)).to match(versions_regex)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context 'when processing environment variables' do
|
|
83
|
+
it 'adds arguments from the environment to the args list' do
|
|
84
|
+
args_parser = described_class.new
|
|
85
|
+
allow(args_parser).to receive(:environment_options).and_return('-t-')
|
|
86
|
+
options, _, _ = args_parser.call([])
|
|
87
|
+
expect(options[:text]).to be(false)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'overrides environment variable options with command line options' do
|
|
91
|
+
env_format_arg = '-fyy'
|
|
92
|
+
cmd_line_format = 'JJ'
|
|
93
|
+
cmd_line_args = ["-f#{cmd_line_format}"]
|
|
94
|
+
args_parser = described_class.new
|
|
95
|
+
allow(args_parser).to receive(:environment_options).and_return(env_format_arg)
|
|
96
|
+
options, _, _ = args_parser.call(cmd_line_args)
|
|
97
|
+
expect(options[:format]).to eq(cmd_line_format)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe 'DEFAULT_OPTIONS hash' do
|
|
102
|
+
specify 'has the correct default values' do
|
|
103
|
+
expect(described_class::DEFAULT_OPTIONS).to eq(
|
|
104
|
+
as_array: false,
|
|
105
|
+
text: true,
|
|
106
|
+
metadata: true,
|
|
107
|
+
format: 'at',
|
|
108
|
+
key_sort: true,
|
|
109
|
+
source: true
|
|
110
|
+
)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
specify 'is frozen' do
|
|
114
|
+
expect(described_class::DEFAULT_OPTIONS).to be_frozen
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'rika/cli/rika_command'
|
|
5
|
+
|
|
6
|
+
RF = Rika::Formatters
|
|
7
|
+
|
|
8
|
+
describe RikaCommand do
|
|
9
|
+
let(:versions_regex) { /Versions:.*Rika: (\d+\.\d+\.\d+(-\w+)?).*Tika: (\d+\.\d+\.\d+(-\w+)?)/ }
|
|
10
|
+
|
|
11
|
+
before do
|
|
12
|
+
@original_stdout = $stdout
|
|
13
|
+
@original_stderr = $stderr
|
|
14
|
+
$stdout = StringIO.new
|
|
15
|
+
$stderr = StringIO.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
after do
|
|
19
|
+
$stdout = @original_stdout
|
|
20
|
+
$stderr = @original_stderr
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe '#call' do
|
|
24
|
+
specify 'call should run the command without error' do
|
|
25
|
+
expect { described_class.new([fixture_path('tiny.txt')]).call }.not_to raise_error
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
specify 'prints version and exits when -v or --version is specified' do
|
|
29
|
+
expect { described_class.new(%w[-v]).call }.to output(versions_regex).to_stdout.and raise_error(SystemExit)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
specify 'prints help and exits when -h or --help is specified' do
|
|
33
|
+
regex = /Usage: rika \[options\] <file or url> /m
|
|
34
|
+
expect { described_class.new(%w[-h]).call }.to output(regex).to_stdout.and raise_error(SystemExit)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
specify 'when run in array mode, outputs the string representation of an array of parse results' do
|
|
38
|
+
original_stdout = $stdout
|
|
39
|
+
$stdout = StringIO.new
|
|
40
|
+
begin
|
|
41
|
+
tiny_filespec = fixture_path('tiny.txt')
|
|
42
|
+
args = ['-a', '-fJ', tiny_filespec, tiny_filespec]
|
|
43
|
+
described_class.new(args).call
|
|
44
|
+
output = $stdout.string
|
|
45
|
+
object = JSON.parse(output)
|
|
46
|
+
expect(object).to be_an(Array)
|
|
47
|
+
expect(object.size).to eq(2)
|
|
48
|
+
expect(object.map(&:class)).to eq([Hash, Hash])
|
|
49
|
+
ensure
|
|
50
|
+
$stdout = original_stdout
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe '#single_document_output' do
|
|
56
|
+
RSpec.shared_examples 'verify_result_is_hash' do |format_chars, parser|
|
|
57
|
+
specify "correctly uses result hash for JSON and YAML when options are #{format_chars}" do
|
|
58
|
+
original_stdout = $stdout
|
|
59
|
+
$stdout = StringIO.new
|
|
60
|
+
begin
|
|
61
|
+
rika_command = described_class.new(["-f#{format_chars}", fixture_path('tiny.txt')])
|
|
62
|
+
rika_command.call
|
|
63
|
+
output = $stdout.string
|
|
64
|
+
warn output
|
|
65
|
+
result_hash = parser.call(output)
|
|
66
|
+
expect(result_hash).to be_a(Hash)
|
|
67
|
+
expect(result_hash['metadata']).to be_a(Hash)
|
|
68
|
+
expect(result_hash['text']).to be_a(String)
|
|
69
|
+
ensure
|
|
70
|
+
$stdout = original_stdout
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
include_examples('verify_result_is_hash', 'JJ', ->(s) { JSON.parse(s) })
|
|
76
|
+
include_examples('verify_result_is_hash', 'jj', ->(s) { JSON.parse(s) })
|
|
77
|
+
include_examples('verify_result_is_hash', 'yy', ->(s) { YAML.safe_load(s) })
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe '#set_output_formats' do
|
|
81
|
+
RSpec.shared_examples 'verify_correct_output_formats_selected' \
|
|
82
|
+
do |format_chars, expected_m_formatter, expected_t_formatter|
|
|
83
|
+
specify "correctly sets output formats when options are #{format_chars}" do
|
|
84
|
+
rika_command = described_class.new(["-f#{format_chars}"])
|
|
85
|
+
rika_command.send(:prepare)
|
|
86
|
+
expect(rika_command.send(:metadata_formatter)).to eq(expected_m_formatter)
|
|
87
|
+
expect(rika_command.send(:text_formatter)).to eq(expected_t_formatter)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
include_examples('verify_correct_output_formats_selected', 'aj', RF::AWESOME_PRINT_FORMATTER, RF::JSON_FORMATTER)
|
|
92
|
+
include_examples('verify_correct_output_formats_selected', 'Jy', RF::PRETTY_JSON_FORMATTER, RF::YAML_FORMATTER)
|
|
93
|
+
include_examples('verify_correct_output_formats_selected', 'ti', RF::TO_S_FORMATTER, RF::INSPECT_FORMATTER)
|
|
94
|
+
|
|
95
|
+
RSpec.shared_examples 'verify_bad_output_format_exits' do |format_chars|
|
|
96
|
+
specify "exits when a bad output format is specified with #{format_chars}" do
|
|
97
|
+
expect { described_class.new(["-f#{format_chars}"]).call }.to raise_error(SystemExit)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
include_examples 'verify_bad_output_format_exits', 'ax'
|
|
102
|
+
include_examples 'verify_bad_output_format_exits', 'xa'
|
|
103
|
+
include_examples 'verify_bad_output_format_exits', 'x'
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
describe '#warn_if_no_targets_specified' do
|
|
107
|
+
it 'prints a warning if no targets are specified' do
|
|
108
|
+
rika_command = described_class.new([])
|
|
109
|
+
allow(rika_command).to receive_messages(
|
|
110
|
+
targets: [],
|
|
111
|
+
help_text: 'sample help text'
|
|
112
|
+
)
|
|
113
|
+
expect { rika_command.send(:report_and_exit_if_no_targets_specified) }.to raise_error(SystemExit)
|
|
114
|
+
expect(rika_command).to have_received(:help_text).once
|
|
115
|
+
output = $stderr.string
|
|
116
|
+
expect(output).to match(/No targets specified/)
|
|
117
|
+
expect(output).to include('sample help text')
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'rika/formatters'
|
|
5
|
+
|
|
6
|
+
describe Rika::Formatters do
|
|
7
|
+
describe '.get' do
|
|
8
|
+
let(:rf) { described_class }
|
|
9
|
+
|
|
10
|
+
it 'returns the correct formatter for each option character' do
|
|
11
|
+
expect(rf.get('a')).to eq(rf::AWESOME_PRINT_FORMATTER)
|
|
12
|
+
expect(rf.get('i')).to eq(rf::INSPECT_FORMATTER)
|
|
13
|
+
expect(rf.get('j')).to eq(rf::JSON_FORMATTER)
|
|
14
|
+
expect(rf.get('J')).to eq(rf::PRETTY_JSON_FORMATTER)
|
|
15
|
+
expect(rf.get('t')).to eq(rf::TO_S_FORMATTER)
|
|
16
|
+
expect(rf.get('y')).to eq(rf::YAML_FORMATTER)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'raises an error if the option character is invalid' do
|
|
20
|
+
expect { rf.get('x') }.to raise_error(KeyError)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'rika/parse_result'
|
|
5
|
+
|
|
6
|
+
describe Rika::ParseResult do
|
|
7
|
+
context 'when initialized' do
|
|
8
|
+
specify 'contains the necessary fields' do
|
|
9
|
+
expect(described_class.new).to respond_to(
|
|
10
|
+
:content,
|
|
11
|
+
:text, # alias for content
|
|
12
|
+
:metadata,
|
|
13
|
+
:metadata_java,
|
|
14
|
+
:content_type,
|
|
15
|
+
:language,
|
|
16
|
+
:input_type,
|
|
17
|
+
:data_source,
|
|
18
|
+
:max_content_length
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe '#file?' do
|
|
24
|
+
specify 'returns true if input_type is :file' do
|
|
25
|
+
expect(described_class.new(input_type: :file).file?).to be true
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
specify 'returns false if input_type is not :file' do
|
|
29
|
+
expect(described_class.new.file?).to be false
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe '#http?' do
|
|
34
|
+
specify 'returns true if input_type is :http' do
|
|
35
|
+
expect(described_class.new(input_type: :http).http?).to be true
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
specify 'returns false if input_type is not :http' do
|
|
39
|
+
expect(described_class.new.http?).to be false
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|