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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +63 -1
  3. data/Gemfile +9 -1
  4. data/README.md +499 -225
  5. data/Rakefile +12 -3
  6. data/copyright.md +17 -29
  7. data/examples/basics.rb +55 -45
  8. data/examples/translate.rb +161 -86
  9. data/examples/uri.rb +50 -78
  10. data/html/CHANGELOG.html +80 -21
  11. data/html/COPYING_md.html +13 -24
  12. data/html/Gemfile.html +12 -21
  13. data/html/Object.html +810 -45
  14. data/html/README_md.html +309 -161
  15. data/html/Rakefile.html +15 -24
  16. data/html/WWWJDic.html +41 -81
  17. data/html/WWWJDic/ParsableDuckType.html +15 -34
  18. data/html/WWWJDic/Parser.html +25 -64
  19. data/html/WWWJDic/Parsers.html +8 -13
  20. data/html/WWWJDic/Parsers/Dict.html +29 -54
  21. data/html/WWWJDic/Parsers/Display.html +24 -47
  22. data/html/WWWJDic/Parsers/Key.html +25 -48
  23. data/html/WWWJDic/Parsers/Search.html +19 -38
  24. data/html/WWWJDic/Parsers/Server.html +24 -47
  25. data/html/WWWJDic/Splitter.html +49 -142
  26. data/html/WWWJDic/Utils.html +9 -14
  27. data/html/WWWJDic/Utils/Downloader.html +8 -13
  28. data/html/WWWJDic/Utils/Downloader/Downloader.html +29 -63
  29. data/html/WWWJDic/Utils/Raisers.html +21 -72
  30. data/html/WWWJDic/WWWJDic.html +131 -312
  31. data/html/copyright_md.html +206 -225
  32. data/html/created.rid +33 -58
  33. data/html/css/rdoc.css +35 -6
  34. data/html/index.html +301 -169
  35. data/html/js/darkfish.js +22 -99
  36. data/html/js/navigation.js +4 -40
  37. data/html/js/navigation.js.gz +0 -0
  38. data/html/js/search.js +32 -31
  39. data/html/js/search_index.js +1 -1
  40. data/html/js/search_index.js.gz +0 -0
  41. data/html/js/searcher.js +6 -6
  42. data/html/js/searcher.js.gz +0 -0
  43. data/html/table_of_contents.html +160 -197
  44. data/lib/wwwjdic.rb +16 -15
  45. data/lib/wwwjdic/application.rb +69 -36
  46. data/lib/wwwjdic/constants.rb +48 -10
  47. data/lib/wwwjdic/locales/de.yml +9 -4
  48. data/lib/wwwjdic/locales/en.yml +9 -4
  49. data/lib/wwwjdic/locales/es.yml +9 -4
  50. data/lib/wwwjdic/locales/fr.yml +9 -4
  51. data/lib/wwwjdic/locales/hu.yml +9 -4
  52. data/lib/wwwjdic/locales/it.yml +9 -4
  53. data/lib/wwwjdic/locales/ja.yml +11 -5
  54. data/lib/wwwjdic/locales/nl.yml +9 -4
  55. data/lib/wwwjdic/locales/ru.yml +9 -4
  56. data/lib/wwwjdic/locales/sl.yml +9 -4
  57. data/lib/wwwjdic/locales/sv.yml +9 -4
  58. data/lib/wwwjdic/parser.rb +15 -8
  59. data/lib/wwwjdic/parsers/dict.rb +13 -8
  60. data/lib/wwwjdic/parsers/display.rb +10 -3
  61. data/lib/wwwjdic/parsers/key.rb +11 -3
  62. data/lib/wwwjdic/parsers/search.rb +12 -3
  63. data/lib/wwwjdic/parsers/server.rb +10 -3
  64. data/lib/wwwjdic/utils/downloader.rb +27 -30
  65. data/lib/wwwjdic/utils/raisers.rb +14 -15
  66. data/lib/wwwjdic/utils/splitter.rb +33 -18
  67. data/lib/wwwjdic/version.rb +28 -20
  68. data/test/test_helper.rb +12 -1
  69. data/test/test_wwwjdic.rb +12 -4
  70. data/test/wwwjdic/locales/de.yml +9 -1
  71. data/test/wwwjdic/locales/en.yml +9 -1
  72. data/test/wwwjdic/locales/es.yml +9 -1
  73. data/test/wwwjdic/locales/fr.yml +9 -1
  74. data/test/wwwjdic/locales/hu.yml +9 -1
  75. data/test/wwwjdic/locales/it.yml +10 -1
  76. data/test/wwwjdic/locales/ja.yml +11 -2
  77. data/test/wwwjdic/locales/nl.yml +9 -1
  78. data/test/wwwjdic/locales/ru.yml +9 -1
  79. data/test/wwwjdic/locales/sl.yml +9 -1
  80. data/test/wwwjdic/locales/sv.yml +9 -1
  81. data/test/wwwjdic/locales/test_locales.rb +43 -24
  82. data/test/wwwjdic/parsers/test_dict.rb +67 -37
  83. data/test/wwwjdic/parsers/test_display.rb +13 -5
  84. data/test/wwwjdic/parsers/test_key.rb +12 -4
  85. data/test/wwwjdic/parsers/test_server.rb +13 -5
  86. data/test/wwwjdic/test_application.rb +201 -149
  87. data/test/wwwjdic/test_parsable_duck_type.rb +11 -6
  88. data/test/wwwjdic/utils/test_downloader.rb +9 -1
  89. data/test/wwwjdic/utils/test_raisers.rb +48 -29
  90. data/wwwjdic.gemspec +46 -26
  91. metadata +55 -43
  92. data/acknowledgements.md +0 -55
  93. data/authors.md +0 -67
  94. data/html/acknowledgements_md.html +0 -149
  95. data/html/authors_md.html +0 -181
  96. data/html/js/jquery.js +0 -4
  97. data/html/wwwjdic_gemspec.html +0 -161
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # wwwjdic
3
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
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__), '/../../../lib/wwwjdic/locales/', '*.yml')]
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
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
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__), '/../../../lib/wwwjdic/locales/', '*.yml')]
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
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
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__), '/../../../lib/wwwjdic/locales/', '*.yml')]
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
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
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
- describe WWWJDic::WWWJDic do
24
- describe 'when created' do
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
- subject {WWWJDic::WWWJDic.new(WWWJDic::parser)}
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
- # Basic checks for instance and default results
29
- it 'shall return a valid object' do
30
- subject.wont_be_nil
31
- subject.must_be_instance_of WWWJDic::WWWJDic
32
- end
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
- it 'shall return the URI with basic language' do
35
- subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
36
- end
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
- # Tests for server selection
39
- describe 'when selecting a server' do
40
- describe 'when an invalid server is selected' do
41
- ['', nil, :invalid].each do |a_server|
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
- it 'shall return the reference URI' do
49
- subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
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
- WWWJDic::URIS.each do |name, uri|
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
- # Tests for dictionary selection
66
- describe 'when selecting a dictionary' do
67
- ['', nil].each do |a_dict|
68
- describe "when an invalid dictionary '#{a_dict}' is selected" do
69
- it 'shall raise an error' do
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.dictionary = a_dict
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
- WWWJDic::DICTIONARY_CODES.each do |dict_number|
82
- describe "when dictionary '#{dict_number}' is selected" do
83
- it "shall return the proper number '#{dict_number}'" do
84
- subject.dictionary = dict_number
85
- subject.dictionary.must_equal WWWJDic::DICTS_BY_CODES[dict_number]
86
- subject.to_s.must_equal WWWJDic::URI_DEFAULT + dict_number + WWWJDic::DISPLAY[:regular]
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
- it 'shall return the URI with basic dictionary when reset' do
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
- WWWJDic::DICTIONARY_NAMES.each do |dict_name|
99
- describe "when dictionary '#{dict_name}' is selected" do
100
- it "shall return the proper name '#{dict_name}'" do
101
- subject.dictionary = dict_name
102
- subject.dictionary.must_equal dict_name
103
- subject.to_s.must_equal WWWJDic::URI_DEFAULT + WWWJDic::DICTS_BY_NAMES[dict_name] + WWWJDic::DISPLAY[:regular]
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
- # Tests for translations
117
- describe 'when asking for a translation' do
118
- I18n.load_path = Dir[File.join(File.dirname(__FILE__), '/../../lib/wwwjdic/locales/', '*.yml')]
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
- # Tests for translation URIs
121
- describe 'when asking for URI' do
122
- ['', nil].each do |a_word|
123
- describe "when providing an invalid parameter '#{a_word}'" do
124
- [:uri, :raw_uri, :json_uri].each do |a_method|
125
- it "shall raise an error for #{a_method} request" do
126
- assert_raises ArgumentError do
127
- subject.send a_method
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
- describe 'when considering multiple languages' do
135
- WWWJDic::AVAIL_LANGS.each_pair do |dict, number|
136
- I18n.locale = dict.to_s
137
- a_word = I18n.t('test.kotoba')
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
- [:uri, :raw_uri, :json_uri].each do |a_method|
140
- it "shall return URI containing '#{number}' for a '#{dict}' word for '#{a_method}' request" do
141
- subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict]).must_include number
142
- end
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
- it "shall return URI containing '#{a_word}' for a '#{dict}' word for '#{a_method}' request" do
145
- subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict]).must_include CGI::escape(a_word).to_s
146
- end
147
- end
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
- it 'shall override user-custom display parameter for raw display' do
150
- subject.raw_uri(a_word, display: :regular, dict: WWWJDic::AVAIL_LANGS[dict]).must_include WWWJDic::DISPLAY[:raw]
151
- end
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
- it "shall return correct JSON data containing '#{a_word}' and the proper URI" do
154
- json = subject.json_uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
155
- an_uri = subject.uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
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
- JSON.parse(json).keys.must_include a_word
158
- JSON.parse(json)[a_word].must_equal an_uri
159
- end
160
- end
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
- # Tests for translation URIs
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
- it "shall raise ArgumentError when an invalid word '#{a_word}' is proposed, for raw display" do
177
- assert_raises ArgumentError do
178
- subject.send(a_method, a_word)
179
- end
180
- end
181
- end
168
+ test_return_json(a_word, dict)
169
+ end
170
+ end
171
+ end
182
172
 
183
- describe 'when considering multiple languages' do
184
- I18n.load_path = Dir[File.join(File.dirname(__FILE__), '/../../lib/wwwjdic/locales/', '*.yml')]
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
- WWWJDic::AVAIL_LANGS.each_pair do |dict, number|
187
- I18n.locale = dict.to_s
188
- a_word = I18n.t('test.kotoba')
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
- it 'shall create a saved file with the proper filename' do
191
- filename = "File_#{a_word}"
192
- subject.send(a_method, a_word, nil, filename)
193
- File.exist?(filename).must_equal true
194
- File.delete filename
195
- end
192
+ test_return_test_reference
193
+ end
194
+ end
195
+ end
196
196
 
197
- it "shall return the translated word '#{a_word}'" do
198
- translation = subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict])
199
- translation.wont_be_nil
200
- translation.wont_be_empty
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
- if a_method == :json_translate
203
- JSON.parse(translation).wont_include '<TITLE>'
204
- JSON.parse(translation).wont_include '<pre>'
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
- an_uri = subject.raw_uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
208
- an_uri.must_include number
213
+ test_server
214
+ end
215
+ end
209
216
 
210
- JSON.parse(translation)[a_word].must_equal an_uri
211
- end
212
- end
213
- end
214
- end
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