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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +60 -1
  3. data/Gemfile +7 -1
  4. data/README.md +500 -225
  5. data/Rakefile +10 -3
  6. data/copyright.md +17 -29
  7. data/examples/basics.rb +53 -45
  8. data/examples/translate.rb +159 -86
  9. data/examples/uri.rb +46 -78
  10. data/html/CHANGELOG.html +90 -35
  11. data/html/COPYING_md.html +26 -38
  12. data/html/Gemfile.html +25 -35
  13. data/html/Object.html +838 -74
  14. data/html/README_md.html +322 -175
  15. data/html/Rakefile.html +28 -38
  16. data/html/WWWJDic.html +63 -104
  17. data/html/WWWJDic/ParsableDuckType.html +38 -58
  18. data/html/WWWJDic/Parser.html +52 -92
  19. data/html/WWWJDic/Parsers.html +29 -35
  20. data/html/WWWJDic/Parsers/Dict.html +50 -76
  21. data/html/WWWJDic/Parsers/Display.html +45 -69
  22. data/html/WWWJDic/Parsers/Key.html +46 -70
  23. data/html/WWWJDic/Parsers/Search.html +41 -61
  24. data/html/WWWJDic/Parsers/Server.html +45 -69
  25. data/html/WWWJDic/Splitter.html +81 -175
  26. data/html/WWWJDic/Utils.html +30 -36
  27. data/html/WWWJDic/Utils/Downloader.html +41 -41
  28. data/html/WWWJDic/Utils/Downloader/Downloader.html +65 -92
  29. data/html/WWWJDic/Utils/Raisers.html +46 -98
  30. data/html/WWWJDic/WWWJDic.html +166 -348
  31. data/html/copyright_md.html +219 -239
  32. data/html/created.rid +33 -58
  33. data/html/css/rdoc.css +638 -590
  34. data/html/index.html +313 -182
  35. data/html/js/darkfish.js +84 -161
  36. data/html/js/navigation.js +4 -40
  37. data/html/js/navigation.js.gz +0 -0
  38. data/html/js/search.js +109 -109
  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 +228 -229
  42. data/html/js/searcher.js.gz +0 -0
  43. data/html/table_of_contents.html +161 -200
  44. data/lib/wwwjdic.rb +14 -15
  45. data/lib/wwwjdic/application.rb +68 -36
  46. data/lib/wwwjdic/constants.rb +56 -12
  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 +13 -8
  59. data/lib/wwwjdic/parsers/dict.rb +11 -8
  60. data/lib/wwwjdic/parsers/display.rb +8 -3
  61. data/lib/wwwjdic/parsers/key.rb +9 -3
  62. data/lib/wwwjdic/parsers/search.rb +10 -3
  63. data/lib/wwwjdic/parsers/server.rb +8 -3
  64. data/lib/wwwjdic/utils/downloader.rb +37 -34
  65. data/lib/wwwjdic/utils/raisers.rb +12 -15
  66. data/lib/wwwjdic/utils/splitter.rb +32 -18
  67. data/lib/wwwjdic/version.rb +22 -8
  68. data/test/test_helper.rb +10 -1
  69. data/test/test_wwwjdic.rb +10 -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 +41 -24
  82. data/test/wwwjdic/parsers/test_dict.rb +65 -37
  83. data/test/wwwjdic/parsers/test_display.rb +11 -5
  84. data/test/wwwjdic/parsers/test_key.rb +10 -4
  85. data/test/wwwjdic/parsers/test_server.rb +11 -5
  86. data/test/wwwjdic/test_application.rb +199 -149
  87. data/test/wwwjdic/test_parsable_duck_type.rb +9 -5
  88. data/test/wwwjdic/utils/test_downloader.rb +7 -1
  89. data/test/wwwjdic/utils/test_raisers.rb +46 -29
  90. data/wwwjdic.gemspec +44 -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,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # wwwjdic
3
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
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__), '/../../../lib/wwwjdic/locales/', '*.yml')]
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
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
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__), '/../../../lib/wwwjdic/locales/', '*.yml')]
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
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
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__), '/../../../lib/wwwjdic/locales/', '*.yml')]
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
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
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
- describe WWWJDic::WWWJDic do
24
- describe 'when created' do
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
- subject {WWWJDic::WWWJDic.new(WWWJDic::parser)}
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
- # 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
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
- it 'shall return the URI with basic language' do
35
- subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
36
- end
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
- # 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
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
- it 'shall return the reference URI' do
49
- subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
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
- 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
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
- # 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
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.dictionary = a_dict
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
- 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]
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
- 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]
92
+ test_return_test_reference
96
93
  end
94
+ end
97
95
 
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
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
- # 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')]
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
- # 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
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
- 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')
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
- [: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
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
- 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
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
- 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
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
- 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])
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
- JSON.parse(json).keys.must_include a_word
158
- JSON.parse(json)[a_word].must_equal an_uri
159
- end
160
- end
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
- # 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
164
+ test_override_custom_params(a_word, dict)
175
165
 
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
166
+ test_return_json(a_word, dict)
167
+ end
168
+ end
169
+ end
182
170
 
183
- describe 'when considering multiple languages' do
184
- I18n.load_path = Dir[File.join(File.dirname(__FILE__), '/../../lib/wwwjdic/locales/', '*.yml')]
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
- WWWJDic::AVAIL_LANGS.each_pair do |dict, number|
187
- I18n.locale = dict.to_s
188
- a_word = I18n.t('test.kotoba')
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
- 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
190
+ test_return_test_reference
191
+ end
192
+ end
193
+ end
196
194
 
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
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
- 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
207
+ def test_select_server
208
+ describe 'when selecting a server' do
209
+ test_invalid_server
206
210
 
207
- an_uri = subject.raw_uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
208
- an_uri.must_include number
211
+ test_server
212
+ end
213
+ end
209
214
 
210
- JSON.parse(translation)[a_word].must_equal an_uri
211
- end
212
- end
213
- end
214
- end
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