class Object

Constants

TEST_ADDRESSES

Public Instance Methods

internet_connection?() click to toggle source
   # File examples/avatar.rb
34 def internet_connection?
35   true if URI.open('http://secure.gravatar.com')
36 rescue StandardError
37   false
38 end
load_yaml_file(locale) click to toggle source
   # File test/gravaty/locales/test_locales.rb
52 def load_yaml_file(locale)
53   filename = File.join(File.dirname(__FILE__),
54                        '.', "#{locale}.yml")
55   filename = File.expand_path filename
56   YAML.safe_load(File.open(filename.to_s))
57 end
test_allowed_sizes() click to toggle source
   # File test/gravaty/test_avatar.rb
41 def test_allowed_sizes
42   Gravaty::ALLOWED_SIZES.each do |size|
43     describe "when asked for a size of '#{size}' pixels" do
44       it "shall provide an URI with specified '#{size}' image" do
45         _(subject.avatar(pixelsize: size)).must_match(/#{Gravaty::TEST_SIZE_REGEXP}$/)
46       end
47     end
48   end
49 end
test_arg_error() click to toggle source
   # File test/gravaty/utils/test_raisers.rb
31 def test_arg_error
32   it 'raises ArgumentError when value is not nil and not in array' do
33     all_methods = { raiser_downcase: ['value', ['no value']],
34                     raiser_to_i: ['42', [47]] }
35 
36     all_methods.each_key do |method_name|
37       a_method = method method_name
38       _(lambda {
39         a_method.call 'error.value',
40                       all_methods[method_name.to_sym][0],
41                       all_methods[method_name.to_sym][1]
42       })
43         .must_raise ArgumentError
44     end
45   end
46 end
test_avatar_formats() click to toggle source
   # File test/gravaty/test_avatar.rb
31 def test_avatar_formats
32   Gravaty::AVATAR_FORMATS.each do |avatar|
33     describe "when asked for '#{avatar}' image" do
34       it "shall provide an URI with specified '#{avatar}' image" do
35         _(subject.avatar(type: avatar)).must_include(".#{avatar}")
36       end
37     end
38   end
39 end
test_default_options() click to toggle source
   # File test/gravaty/test_avatar.rb
71 def test_default_options
72   Gravaty::DEFAULT_OPTIONS.each do |options|
73     describe "when asked for a specific image options '#{options}'" do
74       it "shall provide an URI with option '#{options}'" do
75         _(subject.avatar(default: options)).must_include("d=#{options}")
76       end
77     end
78   end
79 end
test_digest(param, password) click to toggle source
   # File test/gravaty/utils/test_rpc_connector.rb
31 def test_digest(param, password)
32   it "shall raise an ArgumentError when digest is '#{param}'" do
33     _(lambda {
34       Gravaty::Utils::RpcConnector::RpcConnector
35         .new param, password
36     }).must_raise ArgumentError
37   end
38 end
test_info_exist(digest) click to toggle source
   # File test/gravaty/utils/test_rpc_connector.rb
81 def test_info_exist(digest)
82   it 'shall provide information through exists method' do
83     skip 'This test shall be configured with own Gravatar email and password.'
84     result = subject.call('grav.exists', hashes: [digest])
85 
86     result.wont_be_nil
87     result.wont_be_empty
88     result[digest].wont_be_nil
89   end
90 end
test_info_test() click to toggle source
   # File test/gravaty/utils/test_rpc_connector.rb
70 def test_info_test
71   it 'shall provide information through test method' do
72     skip 'This test shall be configured with own Gravatar email and password.'
73     result = subject.call(Gravaty::RPC_TEST_METHOD)
74 
75     result.wont_be_nil
76     result.wont_be_empty
77     result['response'].wont_be_nil
78   end
79 end
test_invalid() click to toggle source
   # File test/gravaty/utils/test_rfc5322.rb
39 def test_invalid
40   describe 'when passed an invalid email address, according to RF5322' do
41     # This test does not pass with 'Joe Q. Public
42     # <john.q.public@example.com>' email: see
43     # <https://tools.ietf.org/html/rfc5322#appendix-A.1.2> that is: it
44     # matches the address even if it has no double-quotes as specified
45     # in RFC 5322.
46     #
47     # Note that the display names for Joe Q. Public and Giant; "Big" Box
48     # needed to be enclosed in double-quotes because the former contains
49     # the period and the latter contains both semicolon and double-quote
50     # characters (the double-quote characters appearing as quoted-pair
51     # constructs).
52     ['-.', 'Joe Q. Public <john.q.public@example.com>']
53       .each do |invalid_address|
54       it "must return nil for '#{invalid_address}' invalid address" do
55         skip 'This test does not pass.'
56         _(Gravaty::Utils::Rfc5322::EMAIL.match invalid_address).must_be_nil
57       end
58     end
59   end
60 end
test_invalid_parameter(digest, password) click to toggle source
   # File test/gravaty/utils/test_rpc_connector.rb
58 def test_invalid_parameter(digest, password)
59   describe 'when receiving an invalid parameter' do
60     [nil, ''].each do |param|
61       test_digest(param, password)
62 
63       test_password(digest, param)
64 
65       test_parameters(param)
66     end
67   end
68 end
test_json() click to toggle source
   # File test/gravaty/test_profile.rb
50 def test_json
51   describe 'when asked for JSON format ' do
52     it 'shall provide an URI in JSON format' do
53       _(subject.json).must_match Gravaty::TEST_JSON_REGEXP
54     end
55 
56     it 'shall provide a JSON URI when callback is provided' do
57       _(subject.json).must_match Gravaty::TEST_JSON_REGEXP
58       _(subject.json(callback: Gravaty::TEST_CALLBACK)).must_match(/#{Gravaty::TEST_CALLBACK}$/)
59     end
60   end
61 end
test_nil() click to toggle source
   # File test/gravaty/utils/test_rfc5322.rb
31 def test_nil
32   describe 'when passed a nil email address' do
33     it 'must return nil' do
34       _(Gravaty::Utils::Rfc5322::EMAIL.match(nil)).must_be_nil
35     end
36   end
37 end
test_no_arg_error() click to toggle source
   # File test/gravaty/utils/test_raisers.rb
48 def test_no_arg_error
49   it 'do not raise an ArgumentError when value is nil or in array' do
50     all_methods = { raiser_downcase: [[nil, nil], ['value', ['value']]],
51                     raiser_to_i: [[nil, nil], ['42', [42]]] }
52 
53     all_methods.each_key do |method_name|
54       a_method = method method_name
55       all_methods[method_name.to_sym].each do |params|
56         a_method.call 'error.value', params[0], params[1]
57       end
58     end
59   end
60 end
test_own_default_image() click to toggle source
    # File test/gravaty/test_avatar.rb
 90 def test_own_default_image
 91   describe 'when provided with a own default image' do
 92     test_own_https_image
 93 
 94     it 'must raise an ArgumentError when default parameter is not correct' do
 95       _(-> { subject.avatar default: 'ftp://www.example.com/example.jpg' }).must_raise ArgumentError
 96       _(-> { subject.avatar default: 'http://www.example.com/example.svg' }).must_raise ArgumentError
 97       _(-> { subject.avatar default: 'http://www.example.com?image=example.jpg' }).must_raise ArgumentError
 98     end
 99   end
100 end
test_own_https_image() click to toggle source
   # File test/gravaty/test_avatar.rb
81 def test_own_https_image
82   it 'shall provide a HTTP(S) URI' do
83     ['', 's'].each do |type|
84       an_uri = "http#{type}://www.example.com/example.jpg"
85       _(subject.avatar(default: an_uri)).must_include CGI.escape(an_uri)
86     end
87   end
88 end
test_parameters(param) click to toggle source
   # File test/gravaty/utils/test_rpc_connector.rb
49 def test_parameters(param)
50   it "shall raise an ArgumentError when parameters are '#{param}'" do
51     _(lambda {
52       Gravaty::Utils::RpcConnector::RpcConnector
53         .new param, param
54     }).must_raise ArgumentError
55   end
56 end
test_password(digest, param) click to toggle source
   # File test/gravaty/utils/test_rpc_connector.rb
40 def test_password(digest, param)
41   it "shall raise an ArgumentError when password is '#{param}'" do
42     _(lambda {
43       Gravaty::Utils::RpcConnector::RpcConnector
44         .new digest, param
45     }).must_raise ArgumentError
46   end
47 end
test_qrcode() click to toggle source
   # File test/gravaty/test_profile.rb
40 def test_qrcode
41   describe 'when asked for QR code format ' do
42     it 'shall provide an URI in QR code format' do
43       _(subject.qrcode).must_match Gravaty::TEST_QR_REGEXP
44     end
45 
46     test_qrcode_sizes
47   end
48 end
test_qrcode_sizes() click to toggle source
   # File test/gravaty/test_profile.rb
31 def test_qrcode_sizes
32   Gravaty::ALLOWED_SIZES.each do |size|
33     it "shall provide a '#{size}' pixels URI, when size '#{size}'" do
34       _(subject.qrcode).must_match Gravaty::TEST_QR_REGEXP
35       _(subject.qrcode(pixelsize: size)).must_match(/#{Gravaty::TEST_SIZE_REGEXP}$/)
36     end
37   end
38 end
test_rating_options() click to toggle source
   # File test/gravaty/test_avatar.rb
61 def test_rating_options
62   Gravaty::RATING_OPTIONS.each do |rating|
63     describe "when asked for a specific image rating '#{rating}'" do
64       it "shall provide an URI with specified '#{rating}'" do
65         _(subject.avatar(rating: rating)).must_include("rating=#{rating}")
66       end
67     end
68   end
69 end
test_unallowed_sizes() click to toggle source
   # File test/gravaty/test_avatar.rb
51 def test_unallowed_sizes
52   [-1, 0, Gravaty::ALLOWED_SIZES.max + 1].each do |size|
53     describe "when asked for an invalid size of '#{size}' pixels" do
54       it 'must raise an argument error' do
55         _(-> { subject.avatar(pixelsize: size) }).must_raise ArgumentError
56       end
57     end
58   end
59 end
test_unknown_parameters() click to toggle source
    # File test/gravaty/test_avatar.rb
102 def test_unknown_parameters
103   describe 'when asked for unknown image' do
104     it 'must raise an ArgumentError' do
105       _(-> { subject.avatar type: 'unknown' }).must_raise ArgumentError
106     end
107   end
108 
109   describe 'when asked for unknown rating' do
110     it 'must raise an ArgumentError' do
111       _(-> { subject.avatar rating: 'unknown' }).must_raise ArgumentError
112     end
113   end
114 end
test_valid() click to toggle source
   # File test/gravaty/utils/test_rfc5322.rb
72 def test_valid
73   describe 'when passed a valid email address, according to RF5322' do
74     # This test shall pass... see
75     # <https://tools.ietf.org/html/rfc5322#appendix-A.5>
76     #
77     # The above example is aesthetically displeasing, but perfectly
78     # legal. Note particularly (1) the comments in the "From:" field
79     # (including one that has a ")" character appearing as part of a
80     # quoted-pair); (2) the white space absent after the ":" in the
81     # "To:" field as well as the comment and folding white space after
82     # the group name, the special character (".") in the comment in
83     # Chris Jones's address, and the folding white space before and
84     # after "joe@example.org,"; (3) the multiple and nested comments in
85     # the "Cc:" field as well as the comment immediately following the
86     # ":" after "Cc"; (4) the folding white space (but no comments
87     # except at the end) and the missing seconds in the time of the date
88     # field; and (5) the white space before (but not within) the
89     # identifier in the "Message-ID:" field.
90     TEST_ADDRESSES.each do |address|
91       it "must match the valid '#{address}' email address" do
92         _(Gravaty::Utils::Rfc5322::EMAIL.match address).wont_be_nil
93       end
94     end
95   end
96 end
test_valid_parameter(digest) click to toggle source
    # File test/gravaty/utils/test_rpc_connector.rb
 92 def test_valid_parameter(digest)
 93   describe 'when created with valid parameters' do
 94     it 'shall provide an useable connector' do
 95       _(subject).wont_be_nil
 96     end
 97 
 98     test_info_test
 99 
100     test_info_exist(digest)
101   end
102 end