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