test/wwwjdic/test_application.rb in wwwjdic-13.0.1 vs test/wwwjdic/test_application.rb in wwwjdic-14.0.0
- old
+ new
@@ -1,8 +1,8 @@
#--
# wwwjdic
-# Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
+# Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
#
# This file is part of wwwjdic.
#
# wwwjdic is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
@@ -21,20 +21,20 @@
require_relative '../test_helper'
describe WWWJDic::WWWJDic do
describe 'when created' do
- subject {WWWJDic::WWWJDic.new(WWWJDic::parser)}
+ subject { WWWJDic::WWWJDic.new(WWWJDic::parser) }
# Basic checks for instance and default results
it 'shall return a valid object' do
- subject.wont_be_nil
- subject.must_be_instance_of WWWJDic::WWWJDic
+ _(subject).wont_be_nil
+ _(subject).must_be_instance_of WWWJDic::WWWJDic
end
it 'shall return the URI with basic language' do
- subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
+ _(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
end
# Tests for server selection
describe 'when selecting a server' do
describe 'when an invalid server is selected' do
@@ -44,21 +44,21 @@
subject.server = a_server
end
end
it 'shall return the reference URI' do
- subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
+ _(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
end
end
end
WWWJDic::URIS.each do |name, uri|
describe "when server '#{name}' is selected" do
it "shall return the proper '#{uri}'" do
subject.server = name
- subject.server.must_equal uri
- subject.to_s.must_include uri
+ _(subject.server).must_equal uri
+ _(subject.to_s).must_include uri
end
end
end
end
@@ -71,47 +71,47 @@
subject.dictionary = a_dict
end
end
it 'shall return the reference URI' do
- subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
+ _(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
end
end
end
WWWJDic::DICTIONARY_CODES.each do |dict_number|
describe "when dictionary '#{dict_number}' is selected" do
it "shall return the proper number '#{dict_number}'" do
subject.dictionary = dict_number
- subject.dictionary.must_equal WWWJDic::DICTS_BY_CODES[dict_number]
- subject.to_s.must_equal WWWJDic::URI_DEFAULT + dict_number + WWWJDic::DISPLAY[:regular]
+ _(subject.dictionary).must_equal WWWJDic::DICTS_BY_CODES[dict_number]
+ _(subject.to_s).must_equal WWWJDic::URI_DEFAULT + dict_number + WWWJDic::DISPLAY[:regular]
end
end
end
it 'shall return the URI with basic dictionary when reset' do
subject.dictionary = 'R'
subject.reset
- subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
- subject.dictionary.must_equal WWWJDic::DICTIONARY_NAMES[0]
+ _(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
+ _(subject.dictionary).must_equal WWWJDic::DICTIONARY_NAMES[0]
end
WWWJDic::DICTIONARY_NAMES.each do |dict_name|
describe "when dictionary '#{dict_name}' is selected" do
it "shall return the proper name '#{dict_name}'" do
subject.dictionary = dict_name
- subject.dictionary.must_equal dict_name
- subject.to_s.must_equal WWWJDic::URI_DEFAULT + WWWJDic::DICTS_BY_NAMES[dict_name] + WWWJDic::DISPLAY[:regular]
+ _(subject.dictionary).must_equal dict_name
+ _(subject.to_s).must_equal WWWJDic::URI_DEFAULT + WWWJDic::DICTS_BY_NAMES[dict_name] + WWWJDic::DISPLAY[:regular]
end
end
end
it 'shall return the URI with basic dictionary when reset' do
subject.dictionary = 'Japanese-Italian'
subject.reset
- subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
- subject.dictionary.must_equal WWWJDic::DICTIONARY_NAMES[0]
+ _(subject.to_s).must_equal WWWJDic::TEST_REFERENCE_URI
+ _(subject.dictionary).must_equal WWWJDic::DICTIONARY_NAMES[0]
end
end
# Tests for translations
describe 'when asking for a translation' do
@@ -136,28 +136,28 @@
I18n.locale = dict.to_s
a_word = I18n.t('test.kotoba')
[:uri, :raw_uri, :json_uri].each do |a_method|
it "shall return URI containing '#{number}' for a '#{dict}' word for '#{a_method}' request" do
- subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict]).must_include number
+ _(subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict])).must_include number
end
it "shall return URI containing '#{a_word}' for a '#{dict}' word for '#{a_method}' request" do
- subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict]).must_include CGI::escape(a_word).to_s
+ _(subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict])).must_include CGI::escape(a_word).to_s
end
end
it 'shall override user-custom display parameter for raw display' do
- subject.raw_uri(a_word, display: :regular, dict: WWWJDic::AVAIL_LANGS[dict]).must_include WWWJDic::DISPLAY[:raw]
+ _(subject.raw_uri(a_word, display: :regular, dict: WWWJDic::AVAIL_LANGS[dict])).must_include WWWJDic::DISPLAY[:raw]
end
it "shall return correct JSON data containing '#{a_word}' and the proper URI" do
json = subject.json_uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
an_uri = subject.uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
- JSON.parse(json).keys.must_include a_word
- JSON.parse(json)[a_word].must_equal an_uri
+ _(JSON.parse(json).keys).must_include a_word
+ _(JSON.parse(json)[a_word]).must_equal an_uri
end
end
end
end
end
@@ -188,27 +188,27 @@
a_word = I18n.t('test.kotoba')
it 'shall create a saved file with the proper filename' do
filename = "File_#{a_word}"
subject.send(a_method, a_word, nil, filename)
- File.exist?(filename).must_equal true
+ _(File.exist?(filename)).must_equal true
File.delete filename
end
it "shall return the translated word '#{a_word}'" do
translation = subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict])
- translation.wont_be_nil
- translation.wont_be_empty
+ _(translation).wont_be_nil
+ _(translation).wont_be_empty
if a_method == :json_translate
- JSON.parse(translation).wont_include '<TITLE>'
- JSON.parse(translation).wont_include '<pre>'
- JSON.parse(translation).keys.must_include a_word
+ _(JSON.parse(translation)).wont_include '<TITLE>'
+ _(JSON.parse(translation)).wont_include '<pre>'
+ _(JSON.parse(translation).keys).must_include a_word
an_uri = subject.raw_uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
- an_uri.must_include number
+ _(an_uri).must_include number
- JSON.parse(translation)[a_word].must_equal an_uri
+ _(JSON.parse(translation)[a_word]).must_equal an_uri
end
end
end
end
end