#-- # gravaty # Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 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 'cgi' require_relative '../../test_helper' describe Gravaty::Gravaty do describe 'when using a parser' do include Gravaty::ParsableDuckType before do I18n.load_path = Dir[File.join( File.dirname(__FILE__), '/../../../lib/gravaty/locales/', '*.yml')] @parser = subject end subject { Gravaty::Parsers::Default.new } Gravaty::DEFAULT_OPTIONS.each do |value| [[nil, ''], ['', ''], %W(#{value} d=#{value})].each do |pair| it "shall return '#{pair[1]}' when parameter is '#{pair[0]}'" do _(subject.parse(pair[0])).must_equal pair[1] end end end Gravaty::IMAGES_FORMATS.each do |extension| value = "http://www.example.com/images/example.#{extension}" escaped = "d=#{CGI::escape(value)}" it "shall return '#{escaped}' when parameter is '#{value}'" do _(subject.parse(value)).must_equal escaped end end describe 'with invalid default URI image URI' do it 'shall raise exception' do begin subject.parse('http://www.example.com/images/example.svg') .must_raise ArgumentError rescue ArgumentError => aErr _(aErr).wont_be_nil _(aErr.message).wont_be_nil _(aErr.message).wont_be_empty end end it 'shall raise exception' do begin subject.parse('svg').must_raise ArgumentError rescue ArgumentError => aErr _(aErr).wont_be_nil _(aErr.message).wont_be_nil _(aErr.message).wont_be_empty end end end end end