#-- # gravaty # Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani # # This file is part of gravaty. # # gravaty is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation, either version 3 of the License, or (at your # option) any later version. # # gravaty is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License # along with gravaty. If not, see . #++ require_relative '../../test_helper' describe Gravaty::Utils::Raisers do include Gravaty::Utils::Raisers before do I18n.load_path = Dir[File.join(File.dirname(__FILE__), '/../../../lib/gravaty/locales/', '*.yml')] I18n.locale = 'it' end describe 'when running any raiser method' do it 'do not raise an ArgumentError when value is nil or in array' do all_methods = Hash.new all_methods[:raiser_downcase] = [[nil, nil], ['value', ['value']]] all_methods[:raiser_to_i] = [[nil, nil], ['42', [42]]] all_methods.each_key do |method_name| a_method = self.method method_name all_methods[method_name.to_sym].each do |params| a_method.call 'error.value', params[0], params[1] end end end it 'raises ArgumentError when value is not nil and not in array' do all_methods = Hash.new all_methods[:raiser_downcase] = ['value', ['no value']] all_methods[:raiser_to_i] = ['42', [47]] all_methods.each_key do |method_name| a_method = self.method method_name assert_raises ArgumentError do a_method.call 'error.value', all_methods[method_name.to_sym][0], all_methods[method_name.to_sym][1] end end end end end