#-- # 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::Gravaty do describe 'when created with a valid email address' do subject {Gravaty::Gravaty.new(Gravaty::TEST_MY_ADDRESS, Gravaty::parser)} it 'shall return the email content on demand' do subject.email.must_equal Gravaty::TEST_MY_ADDRESS.downcase end it 'shall return the digest content on demand' do subject.digest.must_equal Gravaty::TEST_MY_MD5 end it 'shall return a valid string' do subject.to_s.wont_be_nil end it 'shall return a valid JSON' do subject.to_json.wont_be_nil JSON.parse(subject.to_json).wont_be_nil end [:avatar, :profile].each do |method| describe "when asked for '#{method}'" do describe 'when no parameters are provided' do it 'shall provide an URI' do subject.send(method) .must_match Gravaty::TEST_SIMPLE_URI_REGEXP end it "shall provide a '#{method}' URI" do subject.send(method) .must_include Gravaty::TEST_STRING[method] end it "shall provide a '#{method}' with a secure URI" do subject.send(method) .must_match Gravaty::TEST_SECURE_URI_REGEXP subject.send(method) .wont_match Gravaty::TEST_UNSECURE_URI_REGEXP end end describe 'when nil is provided' do it 'shall provide an URI' do subject.send(method, nil) .must_match Gravaty::TEST_SIMPLE_URI_REGEXP end it "shall provide a '#{method}' URI" do subject.send(method, nil) .must_include Gravaty::TEST_STRING[method] end it "shall provide a '#{method}' with a secure URI" do subject.send(method, nil) .must_match Gravaty::TEST_SECURE_URI_REGEXP subject.send(method, nil) .wont_match Gravaty::TEST_UNSECURE_URI_REGEXP end end describe 'when secure:false is provided' do it "shall provide a '#{method}' with an unsecure URI" do subject.send(method, secure: false) .wont_match Gravaty::TEST_SECURE_URI_REGEXP subject.send(method, secure: false) .must_match Gravaty::TEST_UNSECURE_URI_REGEXP end end end end it 'shall provide the XML-RPC API interface' do subject.must_respond_to :xmlrpc end describe 'when asked for nil method' do it 'must raise an ArgumentError' do assert_raises ArgumentError do subject.xmlrpc(nil) end end end describe 'when asked for an unsupported method' do it 'must raise an ArgumentError' do assert_raises ArgumentError do subject.xmlrpc('my_method', 'my_password') end end end describe 'when asked for a valid method with a nil password' do it 'must raise an ArgumentError' do assert_raises ArgumentError do subject.xmlrpc('my_method') end end end end end