class Object
Constants
- RELATIVE_PATH
Public Instance Methods
load_yaml_file(locale)
click to toggle source
# File test/wwwjdic/locales/test_locales.rb 65 def load_yaml_file(locale) 66 filename = File.join(File.dirname(__FILE__), RELATIVE_PATH, "#{locale}.yml") 67 filename = File.expand_path filename 68 YAML.safe_load(File.open(filename.to_s)) 69 end
test_ask_translation()
click to toggle source
# File test/wwwjdic/test_application.rb 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
test_ask_uri()
click to toggle source
# File test/wwwjdic/test_application.rb 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
test_dictionary_code()
click to toggle source
# File test/wwwjdic/parsers/test_dict.rb 63 def test_dictionary_code 64 describe 'when using the dictionary code/number' do 65 WWWJDic::DICTIONARY_CODES.each do |value| 66 it "shall return '#{value}' when parameter is '#{value}'" do 67 _(subject.parse(value)).must_equal value 68 end 69 end 70 end 71 end
test_dictionary_name()
click to toggle source
# File test/wwwjdic/parsers/test_dict.rb 73 def test_dictionary_name 74 describe 'when using the dictionary name' do 75 WWWJDic::DICTIONARY_NAMES.each do |value| 76 translated = WWWJDic::DICTS_BY_NAMES[value] 77 it "shall return '#{translated}' when parameter is '#{value}'" do 78 _(subject.parse(value)).must_equal translated 79 end 80 end 81 end 82 end
test_en_it()
click to toggle source
# File test/wwwjdic/locales/test_locales.rb 38 def test_en_it 39 it 'shall contain at least English and Italiano' do 40 _(subject).must_include :en 41 _(subject).must_include :it 42 end 43 end
test_get_dictionary()
click to toggle source
# File test/wwwjdic/test_application.rb 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 89 end 90 end 91 92 test_return_test_reference 93 end 94 end 95 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] 102 end 103 end 104 end 105 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 112 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] 121 end 122 end 123 end 124 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
test_get_translation()
click to toggle source
# File test/wwwjdic/test_application.rb 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 assert_raises ArgumentError do 71 subject.send(a_method, a_word) 72 end 73 end 74 end 75 76 test_multilanguage(a_method) 77 end 78 end 79 end 80 end
test_invalid_param()
click to toggle source
# File test/wwwjdic/parsers/test_dict.rb 53 def test_invalid_param 54 describe 'when provided and invalid parameter' do 55 [nil, '', 42].each(&method(:test_raise_error_param)) 56 57 test_wrong_name 58 59 test_wrong_code 60 end 61 end
test_invalid_parameter(a_word)
click to toggle source
# File test/wwwjdic/test_application.rb 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 221 end 222 end 223 end 224 end 225 end
test_invalid_server()
click to toggle source
# File test/wwwjdic/test_application.rb 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 190 test_return_test_reference 191 end 192 end 193 end
test_multilanguage(a_method)
click to toggle source
# File test/wwwjdic/test_application.rb 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')] 32 33 WWWJDic::AVAIL_LANGS.each_pair do |dict, number| 34 I18n.locale = dict.to_s 35 a_word = I18n.t('test.kotoba') 36 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 43 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 48 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 53 54 an_uri = subject.raw_uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict]) 55 _(an_uri).must_include number 56 57 _(JSON.parse(translation)[a_word]).must_equal an_uri 58 end 59 end 60 end 61 end 62 end
test_multiple_languages()
click to toggle source
# File test/wwwjdic/test_application.rb 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 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 end 162 end 163 164 test_override_custom_params(a_word, dict) 165 166 test_return_json(a_word, dict) 167 end 168 end 169 end
test_no_raise()
click to toggle source
# File test/wwwjdic/utils/test_raisers.rb 29 def test_no_raise 30 it 'does not raise an ArgumentError when value is nil or in the array' do 31 all_methods = { raiser_downcase: [[nil, nil], ['value', ['value']]], 32 raiser_to_i: [[nil, nil], ['42', [42]]] } 33 34 all_methods.each_key do |method_name| 35 a_method = method method_name 36 all_methods[method_name.to_sym].each do |params| 37 a_method.call 'error.value', params[0], params[1] 38 end 39 end 40 end 41 end
test_one_locale()
click to toggle source
# File test/wwwjdic/locales/test_locales.rb 31 def test_one_locale 32 it 'shall return at least one available locale' do 33 _(subject).wont_be_nil 34 _(subject).wont_be_empty 35 end 36 end
test_override_custom_params(a_word, dict)
click to toggle source
# File test/wwwjdic/test_application.rb 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
test_raise()
click to toggle source
# File test/wwwjdic/utils/test_raisers.rb 43 def test_raise 44 it 'raises ArgumentError when value is not nil and not in the array' do 45 all_methods = { raiser_downcase: ['value', ['no value']], 46 raiser_to_i: ['42', [47]] } 47 48 all_methods.each_key do |method_name| 49 a_method = method method_name 50 assert_raises ArgumentError do 51 a_method.call 'error.value', all_methods[method_name.to_sym][0], all_methods[method_name.to_sym][1] 52 end 53 end 54 end 55 end
test_raise_error_param(param)
click to toggle source
# File test/wwwjdic/parsers/test_dict.rb 29 def test_raise_error_param(param) 30 it "shall raise and error for parameter '#{param}'" do 31 assert_raises ArgumentError do 32 subject.parse param 33 end 34 end 35 end
test_raise_invalid_server_error(a_server)
click to toggle source
# File test/wwwjdic/test_application.rb 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
test_raiser()
click to toggle source
# File test/wwwjdic/utils/test_raisers.rb 57 def test_raiser 58 describe 'when running any raiser method' do 59 test_no_raise 60 61 test_raise 62 end 63 end
test_return_json(a_word, dict)
click to toggle source
# File test/wwwjdic/test_application.rb 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]) 138 139 _(JSON.parse(json).keys).must_include a_word 140 _(JSON.parse(json)[a_word]).must_equal an_uri 141 end 142 end
test_return_test_reference()
click to toggle source
# File test/wwwjdic/test_application.rb 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
test_select_server()
click to toggle source
# File test/wwwjdic/test_application.rb 207 def test_select_server 208 describe 'when selecting a server' do 209 test_invalid_server 210 211 test_server 212 end 213 end
test_server()
click to toggle source
# File test/wwwjdic/test_application.rb 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
test_translation(locale, translation)
click to toggle source
# File test/wwwjdic/locales/test_locales.rb 45 def test_translation(locale, translation) 46 a_string = I18n.t('test.test') 47 _(a_string).wont_be_nil 48 _(a_string).wont_be_empty 49 _(a_string).wont_include 'translation missing' 50 _(a_string).must_equal translation[locale.to_s]['test']['test'] 51 end
test_wrong_code()
click to toggle source
# File test/wwwjdic/parsers/test_dict.rb 45 def test_wrong_code 46 it 'shall raise an error when wrong dictionary code' do 47 assert_raises ArgumentError do 48 subject.parse 'Z' 49 end 50 end 51 end
test_wrong_name()
click to toggle source
# File test/wwwjdic/parsers/test_dict.rb 37 def test_wrong_name 38 it 'shall raise an error when wrong dictionary name' do 39 assert_raises ArgumentError do 40 subject.parse 'test' 41 end 42 end 43 end