wwwjdic 13.0.1 → 16.1.0
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 +4 -4
- data/CHANGELOG +60 -1
- data/Gemfile +7 -1
- data/README.md +500 -225
- data/Rakefile +10 -3
- data/copyright.md +17 -29
- data/examples/basics.rb +53 -45
- data/examples/translate.rb +159 -86
- data/examples/uri.rb +46 -78
- data/html/CHANGELOG.html +90 -35
- data/html/COPYING_md.html +26 -38
- data/html/Gemfile.html +25 -35
- data/html/Object.html +838 -74
- data/html/README_md.html +322 -175
- data/html/Rakefile.html +28 -38
- data/html/WWWJDic.html +63 -104
- data/html/WWWJDic/ParsableDuckType.html +38 -58
- data/html/WWWJDic/Parser.html +52 -92
- data/html/WWWJDic/Parsers.html +29 -35
- data/html/WWWJDic/Parsers/Dict.html +50 -76
- data/html/WWWJDic/Parsers/Display.html +45 -69
- data/html/WWWJDic/Parsers/Key.html +46 -70
- data/html/WWWJDic/Parsers/Search.html +41 -61
- data/html/WWWJDic/Parsers/Server.html +45 -69
- data/html/WWWJDic/Splitter.html +81 -175
- data/html/WWWJDic/Utils.html +30 -36
- data/html/WWWJDic/Utils/Downloader.html +41 -41
- data/html/WWWJDic/Utils/Downloader/Downloader.html +65 -92
- data/html/WWWJDic/Utils/Raisers.html +46 -98
- data/html/WWWJDic/WWWJDic.html +166 -348
- data/html/copyright_md.html +219 -239
- data/html/created.rid +33 -58
- data/html/css/rdoc.css +638 -590
- data/html/index.html +313 -182
- data/html/js/darkfish.js +84 -161
- data/html/js/navigation.js +4 -40
- data/html/js/navigation.js.gz +0 -0
- data/html/js/search.js +109 -109
- data/html/js/search_index.js +1 -1
- data/html/js/search_index.js.gz +0 -0
- data/html/js/searcher.js +228 -229
- data/html/js/searcher.js.gz +0 -0
- data/html/table_of_contents.html +161 -200
- data/lib/wwwjdic.rb +14 -15
- data/lib/wwwjdic/application.rb +68 -36
- data/lib/wwwjdic/constants.rb +56 -12
- data/lib/wwwjdic/locales/de.yml +9 -4
- data/lib/wwwjdic/locales/en.yml +9 -4
- data/lib/wwwjdic/locales/es.yml +9 -4
- data/lib/wwwjdic/locales/fr.yml +9 -4
- data/lib/wwwjdic/locales/hu.yml +9 -4
- data/lib/wwwjdic/locales/it.yml +9 -4
- data/lib/wwwjdic/locales/ja.yml +11 -5
- data/lib/wwwjdic/locales/nl.yml +9 -4
- data/lib/wwwjdic/locales/ru.yml +9 -4
- data/lib/wwwjdic/locales/sl.yml +9 -4
- data/lib/wwwjdic/locales/sv.yml +9 -4
- data/lib/wwwjdic/parser.rb +13 -8
- data/lib/wwwjdic/parsers/dict.rb +11 -8
- data/lib/wwwjdic/parsers/display.rb +8 -3
- data/lib/wwwjdic/parsers/key.rb +9 -3
- data/lib/wwwjdic/parsers/search.rb +10 -3
- data/lib/wwwjdic/parsers/server.rb +8 -3
- data/lib/wwwjdic/utils/downloader.rb +37 -34
- data/lib/wwwjdic/utils/raisers.rb +12 -15
- data/lib/wwwjdic/utils/splitter.rb +32 -18
- data/lib/wwwjdic/version.rb +22 -8
- data/test/test_helper.rb +10 -1
- data/test/test_wwwjdic.rb +10 -4
- data/test/wwwjdic/locales/de.yml +9 -1
- data/test/wwwjdic/locales/en.yml +9 -1
- data/test/wwwjdic/locales/es.yml +9 -1
- data/test/wwwjdic/locales/fr.yml +9 -1
- data/test/wwwjdic/locales/hu.yml +9 -1
- data/test/wwwjdic/locales/it.yml +10 -1
- data/test/wwwjdic/locales/ja.yml +11 -2
- data/test/wwwjdic/locales/nl.yml +9 -1
- data/test/wwwjdic/locales/ru.yml +9 -1
- data/test/wwwjdic/locales/sl.yml +9 -1
- data/test/wwwjdic/locales/sv.yml +9 -1
- data/test/wwwjdic/locales/test_locales.rb +41 -24
- data/test/wwwjdic/parsers/test_dict.rb +65 -37
- data/test/wwwjdic/parsers/test_display.rb +11 -5
- data/test/wwwjdic/parsers/test_key.rb +10 -4
- data/test/wwwjdic/parsers/test_server.rb +11 -5
- data/test/wwwjdic/test_application.rb +199 -149
- data/test/wwwjdic/test_parsable_duck_type.rb +9 -5
- data/test/wwwjdic/utils/test_downloader.rb +7 -1
- data/test/wwwjdic/utils/test_raisers.rb +46 -29
- data/wwwjdic.gemspec +44 -26
- metadata +55 -43
- data/acknowledgements.md +0 -55
- data/authors.md +0 -67
- data/html/acknowledgements_md.html +0 -149
- data/html/authors_md.html +0 -181
- data/html/js/jquery.js +0 -4
- data/html/wwwjdic_gemspec.html +0 -161
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# wwwjdic
|
3
|
-
#
|
5
|
+
# © 2014-2021 Marco Bresciani
|
4
6
|
#
|
5
7
|
# This file is part of wwwjdic.
|
6
8
|
#
|
@@ -16,6 +18,10 @@
|
|
16
18
|
#
|
17
19
|
# You should have received a copy of the GNU General Public License
|
18
20
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
#
|
22
|
+
# SPDX-FileCopyrightText: 2014-2021 Marco Bresciani
|
23
|
+
#
|
24
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
25
|
#++
|
20
26
|
|
21
27
|
require_relative '../../test_helper'
|
@@ -26,16 +32,16 @@ describe WWWJDic::WWWJDic do
|
|
26
32
|
|
27
33
|
before do
|
28
34
|
@parser = subject
|
29
|
-
I18n.load_path = Dir[File.join(File.dirname(__FILE__), '
|
35
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__), '../locales/', '*.yml')]
|
30
36
|
end
|
31
37
|
|
32
|
-
subject {WWWJDic::Parsers::Display.new}
|
38
|
+
subject { WWWJDic::Parsers::Display.new }
|
33
39
|
|
34
40
|
describe 'when a valid display mode is selected' do
|
35
41
|
WWWJDic::DISPLAY.each do |key, value|
|
36
42
|
it "shall return '#{value}' when parameter is '#{key}'" do
|
37
|
-
subject.parse(key).must_equal key
|
38
|
-
WWWJDic::DISPLAY[subject.parse(key)].must_equal value
|
43
|
+
_(subject.parse(key)).must_equal key
|
44
|
+
_(WWWJDic::DISPLAY[subject.parse(key)]).must_equal value
|
39
45
|
end
|
40
46
|
end
|
41
47
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# wwwjdic
|
3
|
-
#
|
5
|
+
# © 2014-2021 Marco Bresciani
|
4
6
|
#
|
5
7
|
# This file is part of wwwjdic.
|
6
8
|
#
|
@@ -16,6 +18,10 @@
|
|
16
18
|
#
|
17
19
|
# You should have received a copy of the GNU General Public License
|
18
20
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
#
|
22
|
+
# SPDX-FileCopyrightText: 2014-2021 Marco Bresciani
|
23
|
+
#
|
24
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
25
|
#++
|
20
26
|
|
21
27
|
require_relative '../../test_helper'
|
@@ -26,10 +32,10 @@ describe WWWJDic::WWWJDic do
|
|
26
32
|
|
27
33
|
before do
|
28
34
|
@parser = subject
|
29
|
-
I18n.load_path = Dir[File.join(File.dirname(__FILE__), '
|
35
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__), '../locales/', '*.yml')]
|
30
36
|
end
|
31
37
|
|
32
|
-
subject {WWWJDic::Parsers::Key.new}
|
38
|
+
subject { WWWJDic::Parsers::Key.new }
|
33
39
|
|
34
40
|
describe 'when provided and invalid parameter' do
|
35
41
|
[nil, '', 42].each do |param|
|
@@ -44,7 +50,7 @@ describe WWWJDic::WWWJDic do
|
|
44
50
|
describe 'when provided a key' do
|
45
51
|
WWWJDic::KEYS.each do |key, value|
|
46
52
|
it "shall return #{value} when parameter is #{key}" do
|
47
|
-
WWWJDic::KEYS[subject.parse(key)].must_equal value
|
53
|
+
_(WWWJDic::KEYS[subject.parse(key)]).must_equal value
|
48
54
|
end
|
49
55
|
end
|
50
56
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# wwwjdic
|
3
|
-
#
|
5
|
+
# © 2014-2021 Marco Bresciani
|
4
6
|
#
|
5
7
|
# This file is part of wwwjdic.
|
6
8
|
#
|
@@ -16,6 +18,10 @@
|
|
16
18
|
#
|
17
19
|
# You should have received a copy of the GNU General Public License
|
18
20
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
#
|
22
|
+
# SPDX-FileCopyrightText: 2014-2021 Marco Bresciani
|
23
|
+
#
|
24
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
25
|
#++
|
20
26
|
|
21
27
|
require_relative '../../test_helper'
|
@@ -26,16 +32,16 @@ describe WWWJDic::WWWJDic do
|
|
26
32
|
|
27
33
|
before do
|
28
34
|
@parser = subject
|
29
|
-
I18n.load_path = Dir[File.join(File.dirname(__FILE__), '
|
35
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__), '../locales/', '*.yml')]
|
30
36
|
end
|
31
37
|
|
32
|
-
subject {WWWJDic::Parsers::Server.new}
|
38
|
+
subject { WWWJDic::Parsers::Server.new }
|
33
39
|
|
34
40
|
describe 'when a valid server is selected' do
|
35
41
|
WWWJDic::URIS.each do |key, value|
|
36
42
|
it "shall return '#{value}' when parameter is '#{key}'" do
|
37
|
-
subject.parse(key).must_equal key
|
38
|
-
WWWJDic::URIS[subject.parse(key)].must_equal value
|
43
|
+
_(subject.parse(key)).must_equal key
|
44
|
+
_(WWWJDic::URIS[subject.parse(key)]).must_equal value
|
39
45
|
end
|
40
46
|
end
|
41
47
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# wwwjdic
|
3
|
-
#
|
5
|
+
# © 2014-2021 Marco Bresciani
|
4
6
|
#
|
5
7
|
# This file is part of wwwjdic.
|
6
8
|
#
|
@@ -16,204 +18,252 @@
|
|
16
18
|
#
|
17
19
|
# You should have received a copy of the GNU General Public License
|
18
20
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
#
|
22
|
+
# SPDX-FileCopyrightText: 2014-2021 Marco Bresciani
|
23
|
+
#
|
24
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
25
|
#++
|
20
26
|
|
21
27
|
require_relative '../test_helper'
|
22
28
|
|
23
|
-
|
24
|
-
describe 'when
|
29
|
+
def test_multilanguage(a_method)
|
30
|
+
describe 'when considering multiple languages' do
|
31
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__), 'locales/', '*.yml')]
|
25
32
|
|
26
|
-
|
33
|
+
WWWJDic::AVAIL_LANGS.each_pair do |dict, number|
|
34
|
+
I18n.locale = dict.to_s
|
35
|
+
a_word = I18n.t('test.kotoba')
|
27
36
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
37
|
+
it 'shall create a saved file with the proper filename' do
|
38
|
+
filename = "File_#{a_word}"
|
39
|
+
subject.send(a_method, a_word, nil, filename)
|
40
|
+
_(File.exist?(filename)).must_equal true
|
41
|
+
File.delete filename
|
42
|
+
end
|
33
43
|
|
34
|
-
|
35
|
-
|
36
|
-
|
44
|
+
it "shall return the translated word '#{a_word}'" do
|
45
|
+
translation = subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict])
|
46
|
+
_(translation).wont_be_nil
|
47
|
+
_(translation).wont_be_empty
|
37
48
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
it 'shall raise an error' do
|
43
|
-
assert_raises ArgumentError do
|
44
|
-
subject.server = a_server
|
45
|
-
end
|
46
|
-
end
|
49
|
+
if a_method == :json_translate
|
50
|
+
_(JSON.parse(translation)).wont_include '<TITLE>'
|
51
|
+
_(JSON.parse(translation)).wont_include '<pre>'
|
52
|
+
_(JSON.parse(translation).keys).must_include a_word
|
47
53
|
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
54
|
+
an_uri = subject.raw_uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
|
55
|
+
_(an_uri).must_include number
|
53
56
|
|
54
|
-
|
55
|
-
describe "when server '#{name}' is selected" do
|
56
|
-
it "shall return the proper '#{uri}'" do
|
57
|
-
subject.server = name
|
58
|
-
subject.server.must_equal uri
|
59
|
-
subject.to_s.must_include uri
|
60
|
-
end
|
57
|
+
_(JSON.parse(translation)[a_word]).must_equal an_uri
|
61
58
|
end
|
62
59
|
end
|
63
60
|
end
|
61
|
+
end
|
62
|
+
end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
def test_get_translation
|
65
|
+
describe 'when asking to retrieve a translation' do
|
66
|
+
%i[translate json_translate].each do |a_method|
|
67
|
+
describe "when the translation is '#{a_method}'" do
|
68
|
+
['', nil].each do |a_word|
|
69
|
+
it "shall raise ArgumentError when an invalid word '#{a_word}' is proposed" do
|
70
70
|
assert_raises ArgumentError do
|
71
|
-
subject.
|
71
|
+
subject.send(a_method, a_word)
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
75
|
-
it 'shall return the reference URI' do
|
76
|
-
subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
|
77
|
-
end
|
78
74
|
end
|
75
|
+
|
76
|
+
test_multilanguage(a_method)
|
79
77
|
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
80
81
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
82
|
+
def test_get_dictionary
|
83
|
+
describe 'when selecting a dictionary' do
|
84
|
+
['', nil].each do |a_dict|
|
85
|
+
describe "when an invalid dictionary '#{a_dict}' is selected" do
|
86
|
+
it 'shall raise an error' do
|
87
|
+
assert_raises ArgumentError do
|
88
|
+
subject.dictionary = a_dict
|
87
89
|
end
|
88
90
|
end
|
89
|
-
end
|
90
91
|
|
91
|
-
|
92
|
-
subject.dictionary = 'R'
|
93
|
-
subject.reset
|
94
|
-
subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
|
95
|
-
subject.dictionary.must_equal WWWJDic::DICTIONARY_NAMES[0]
|
92
|
+
test_return_test_reference
|
96
93
|
end
|
94
|
+
end
|
97
95
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
96
|
+
WWWJDic::DICTIONARY_CODES.each do |dict_number|
|
97
|
+
describe "when dictionary '#{dict_number}' is selected" do
|
98
|
+
it "shall return the proper number '#{dict_number}'" do
|
99
|
+
subject.dictionary = dict_number
|
100
|
+
_(subject.dictionary).must_equal WWWJDic::DICTS_BY_CODES[dict_number]
|
101
|
+
_(subject.to_s).must_equal WWWJDic::URI_DEFAULT + dict_number + WWWJDic::DISPLAY[:regular]
|
105
102
|
end
|
106
103
|
end
|
107
|
-
|
108
|
-
it 'shall return the URI with basic dictionary when reset' do
|
109
|
-
subject.dictionary = 'Japanese-Italian'
|
110
|
-
subject.reset
|
111
|
-
subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
|
112
|
-
subject.dictionary.must_equal WWWJDic::DICTIONARY_NAMES[0]
|
113
|
-
end
|
114
104
|
end
|
115
105
|
|
116
|
-
|
117
|
-
|
118
|
-
|
106
|
+
it 'shall return the URI with basic dictionary when reset' do
|
107
|
+
subject.dictionary = 'R'
|
108
|
+
subject.reset
|
109
|
+
_(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
|
110
|
+
_(subject.dictionary).must_equal WWWJDic::DICTIONARY_NAMES[0]
|
111
|
+
end
|
119
112
|
|
120
|
-
|
121
|
-
describe
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
113
|
+
WWWJDic::DICTIONARY_NAMES.each do |dict_name|
|
114
|
+
describe "when dictionary '#{dict_name}' is selected" do
|
115
|
+
it "shall return the proper name '#{dict_name}'" do
|
116
|
+
subject.dictionary = dict_name
|
117
|
+
_(subject.dictionary).must_equal dict_name
|
118
|
+
_(subject.to_s).must_equal WWWJDic::URI_DEFAULT +
|
119
|
+
WWWJDic::DICTS_BY_NAMES[dict_name] +
|
120
|
+
WWWJDic::DISPLAY[:regular]
|
132
121
|
end
|
122
|
+
end
|
123
|
+
end
|
133
124
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
125
|
+
it 'shall return the URI with basic dictionary when reset' do
|
126
|
+
subject.dictionary = 'Japanese-Italian'
|
127
|
+
subject.reset
|
128
|
+
_(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
|
129
|
+
_(subject.dictionary).must_equal WWWJDic::DICTIONARY_NAMES[0]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
138
133
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
134
|
+
def test_return_json(a_word, dict)
|
135
|
+
it "shall return correct JSON data containing '#{a_word}' and the proper URI" do
|
136
|
+
json = subject.json_uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
|
137
|
+
an_uri = subject.uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
|
143
138
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
139
|
+
_(JSON.parse(json).keys).must_include a_word
|
140
|
+
_(JSON.parse(json)[a_word]).must_equal an_uri
|
141
|
+
end
|
142
|
+
end
|
148
143
|
|
149
|
-
|
150
|
-
|
151
|
-
|
144
|
+
def test_override_custom_params(a_word, dict)
|
145
|
+
it 'shall override user-custom display parameter for raw display' do
|
146
|
+
_(subject.raw_uri(a_word, display: :regular,
|
147
|
+
dict: WWWJDic::AVAIL_LANGS[dict])).must_include WWWJDic::DISPLAY[:raw]
|
148
|
+
end
|
149
|
+
end
|
152
150
|
|
153
|
-
|
154
|
-
|
155
|
-
|
151
|
+
def test_multiple_languages
|
152
|
+
describe 'when considering multiple languages' do
|
153
|
+
WWWJDic::AVAIL_LANGS.each_pair do |dict, number|
|
154
|
+
I18n.locale = dict.to_s
|
155
|
+
a_word = I18n.t('test.kotoba')
|
156
156
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
157
|
+
%i[uri raw_uri json_uri].each do |a_method|
|
158
|
+
it "shall return URI containing '#{number}' for a '#{dict}' word for '#{a_method}' request" do
|
159
|
+
_(subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict])).must_include number
|
160
|
+
_(subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict])).must_include CGI.escape(a_word).to_s
|
161
161
|
end
|
162
162
|
end
|
163
|
-
end
|
164
163
|
|
165
|
-
|
166
|
-
describe 'when asking to retrieve a translation' do
|
167
|
-
[:translate, :json_translate].each do |a_method|
|
168
|
-
describe "when the translation is '#{a_method}'" do
|
169
|
-
['', nil].each do |a_word|
|
170
|
-
it "shall raise ArgumentError when an invalid word '#{a_word}' is proposed" do
|
171
|
-
assert_raises ArgumentError do
|
172
|
-
subject.send(a_method, a_word)
|
173
|
-
end
|
174
|
-
end
|
164
|
+
test_override_custom_params(a_word, dict)
|
175
165
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
end
|
181
|
-
end
|
166
|
+
test_return_json(a_word, dict)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
182
170
|
|
183
|
-
|
184
|
-
|
171
|
+
def test_raise_invalid_server_error(a_server)
|
172
|
+
it 'shall raise an error' do
|
173
|
+
assert_raises ArgumentError do
|
174
|
+
subject.server = a_server
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_return_test_reference
|
180
|
+
it 'shall return the reference URI' do
|
181
|
+
_(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
|
182
|
+
end
|
183
|
+
end
|
185
184
|
|
186
|
-
|
187
|
-
|
188
|
-
|
185
|
+
def test_invalid_server
|
186
|
+
describe 'when an invalid server is selected' do
|
187
|
+
['', nil, :invalid].each do |a_server|
|
188
|
+
test_raise_invalid_server_error(a_server)
|
189
189
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
File.delete filename
|
195
|
-
end
|
190
|
+
test_return_test_reference
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
196
194
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
195
|
+
def test_server
|
196
|
+
WWWJDic::URIS.each do |name, uri|
|
197
|
+
describe "when server '#{name}' is selected" do
|
198
|
+
it "shall return the proper '#{uri}'" do
|
199
|
+
subject.server = name
|
200
|
+
_(subject.server).must_equal uri
|
201
|
+
_(subject.to_s).must_include uri
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
201
206
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
JSON.parse(translation).keys.must_include a_word
|
207
|
+
def test_select_server
|
208
|
+
describe 'when selecting a server' do
|
209
|
+
test_invalid_server
|
206
210
|
|
207
|
-
|
208
|
-
|
211
|
+
test_server
|
212
|
+
end
|
213
|
+
end
|
209
214
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
+
def test_invalid_parameter(a_word)
|
216
|
+
describe "when providing an invalid parameter '#{a_word}'" do
|
217
|
+
%i[uri raw_uri json_uri].each do |a_method|
|
218
|
+
it "shall raise an error for #{a_method} request" do
|
219
|
+
assert_raises ArgumentError do
|
220
|
+
subject.send a_method
|
215
221
|
end
|
216
222
|
end
|
217
223
|
end
|
218
224
|
end
|
219
225
|
end
|
226
|
+
|
227
|
+
def test_ask_uri
|
228
|
+
describe 'when asking for URI' do
|
229
|
+
['', nil].each(&method(:test_invalid_parameter))
|
230
|
+
|
231
|
+
test_multiple_languages
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_ask_translation
|
236
|
+
describe 'when asking for a translation' do
|
237
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__), './locales/', '*.yml')]
|
238
|
+
|
239
|
+
# Tests for translation URIs
|
240
|
+
test_ask_uri
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe WWWJDic::WWWJDic do
|
245
|
+
describe 'when created' do
|
246
|
+
subject { WWWJDic::WWWJDic.new(WWWJDic.parser) }
|
247
|
+
|
248
|
+
# Basic checks for instance and default results
|
249
|
+
it 'shall return a valid object' do
|
250
|
+
_(subject).wont_be_nil
|
251
|
+
_(subject).must_be_instance_of WWWJDic::WWWJDic
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'shall return the URI with basic language' do
|
255
|
+
_(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
|
256
|
+
end
|
257
|
+
|
258
|
+
# Tests for server selection
|
259
|
+
test_select_server
|
260
|
+
|
261
|
+
# Tests for dictionary selection
|
262
|
+
test_get_dictionary
|
263
|
+
|
264
|
+
# Tests for translations
|
265
|
+
test_ask_translation
|
266
|
+
|
267
|
+
test_get_translation
|
268
|
+
end
|
269
|
+
end
|