gravaty 10.0.0 → 11.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -0
- data/Gemfile +5 -1
- data/README.md +219 -212
- data/Rakefile +9 -3
- data/copyright.md +33 -136
- data/examples/avatar.rb +70 -43
- data/examples/basics.rb +30 -20
- data/examples/profile.rb +77 -50
- data/examples/xmlrpc.rb +24 -10
- data/gravaty.gemspec +46 -25
- data/html/CHANGELOG.html +13 -20
- data/html/COPYING_md.html +8 -24
- data/html/Gemfile.html +7 -21
- data/html/Gravaty.html +49 -113
- data/html/Gravaty/Gravaty.html +138 -343
- data/html/Gravaty/ParsableDuckType.html +14 -33
- data/html/Gravaty/Parser.html +27 -66
- data/html/Gravaty/Parsers.html +3 -11
- data/html/Gravaty/Parsers/Avatar.html +19 -36
- data/html/Gravaty/Parsers/Callback.html +21 -37
- data/html/Gravaty/Parsers/Default.html +28 -45
- data/html/Gravaty/Parsers/Force.html +21 -37
- data/html/Gravaty/Parsers/Format.html +22 -42
- data/html/Gravaty/Parsers/Pixelsize.html +22 -42
- data/html/Gravaty/Parsers/Rating.html +22 -42
- data/html/Gravaty/Parsers/Secure.html +19 -36
- data/html/Gravaty/Parsers/Type.html +22 -42
- data/html/Gravaty/Utils.html +11 -13
- data/html/Gravaty/Utils/Downloader.html +3 -11
- data/html/Gravaty/Utils/Downloader/Downloader.html +25 -59
- data/html/Gravaty/Utils/Raisers.html +24 -55
- data/html/Gravaty/Utils/Rfc5322.html +12 -19
- data/html/Gravaty/Utils/RpcConnector.html +11 -13
- data/html/Gravaty/Utils/RpcConnector/RpcConnector.html +33 -73
- data/html/Object.html +728 -57
- data/html/README_md.html +105 -100
- data/html/Rakefile.html +9 -23
- data/html/copyright_md.html +17 -119
- data/html/created.rid +48 -55
- data/html/css/rdoc.css +1 -1
- data/html/index.html +97 -114
- data/html/js/navigation.js.gz +0 -0
- data/html/js/search_index.js +1 -1
- data/html/js/search_index.js.gz +0 -0
- data/html/js/searcher.js.gz +0 -0
- data/html/table_of_contents.html +219 -651
- data/lib/gravaty.rb +22 -15
- data/lib/gravaty/application.rb +40 -25
- data/lib/gravaty/constants.rb +20 -11
- data/lib/gravaty/locales/en.yml +9 -3
- data/lib/gravaty/locales/it.yml +9 -3
- data/lib/gravaty/locales/ja.yml +7 -4
- data/lib/gravaty/parser.rb +16 -10
- data/lib/gravaty/parsers/avatar.rb +11 -3
- data/lib/gravaty/parsers/callback.rb +13 -4
- data/lib/gravaty/parsers/default.rb +24 -16
- data/lib/gravaty/parsers/force.rb +12 -2
- data/lib/gravaty/parsers/format.rb +11 -2
- data/lib/gravaty/parsers/pixelsize.rb +12 -3
- data/lib/gravaty/parsers/rating.rb +12 -3
- data/lib/gravaty/parsers/secure.rb +11 -2
- data/lib/gravaty/parsers/type.rb +11 -2
- data/lib/gravaty/utils/downloader.rb +98 -96
- data/lib/gravaty/utils/raisers.rb +19 -12
- data/lib/gravaty/utils/rfc5322.rb +54 -41
- data/lib/gravaty/utils/rpc_connector.rb +19 -11
- data/lib/gravaty/version.rb +10 -2
- data/test/gravaty/locales/en.yml +29 -0
- data/test/gravaty/locales/it.yml +29 -0
- data/test/gravaty/locales/ja.yml +27 -0
- data/test/gravaty/locales/test_locales.rb +17 -13
- data/test/gravaty/parsers/test_avatar.rb +9 -1
- data/test/gravaty/parsers/test_callback.rb +12 -4
- data/test/gravaty/parsers/test_default.rb +25 -21
- data/test/gravaty/parsers/test_force.rb +9 -1
- data/test/gravaty/parsers/test_format.rb +18 -11
- data/test/gravaty/parsers/test_pixelsize.rb +19 -12
- data/test/gravaty/parsers/test_rating.rb +18 -11
- data/test/gravaty/parsers/test_secure.rb +9 -1
- data/test/gravaty/parsers/test_type.rb +14 -5
- data/test/gravaty/test_application.rb +14 -6
- data/test/gravaty/test_avatar.rb +94 -59
- data/test/gravaty/test_parser.rb +11 -5
- data/test/gravaty/test_profile.rb +47 -25
- data/test/gravaty/utils/test_downloader.rb +43 -28
- data/test/gravaty/utils/test_raisers.rb +42 -26
- data/test/gravaty/utils/test_rfc5322.rb +35 -13
- data/test/gravaty/utils/test_rpc_connector.rb +83 -39
- data/test/test_gravaty.rb +12 -4
- data/test/test_helper.rb +15 -9
- metadata +54 -40
- data/ISSUES.md +0 -62
- data/acknowledgements.md +0 -66
- data/authors.md +0 -63
- data/examples/cacert.pem +0 -3466
- data/html/ISSUES_md.html +0 -166
- data/html/acknowledgements_md.html +0 -161
- data/html/authors_md.html +0 -174
- data/html/examples/cacert_pem.html +0 -1078
data/test/gravaty/test_avatar.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2013 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,93 +20,124 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2013 Marco Bresciani
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
27
|
#++
|
20
28
|
|
21
29
|
require_relative '../test_helper'
|
22
30
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
Gravaty::AVATAR_FORMATS.each do |avatar|
|
30
|
-
describe "when asked for '#{avatar}' image" do
|
31
|
-
it "shall provide an URI with specified '#{avatar}' image" do
|
32
|
-
_(subject.avatar(type: avatar)).must_include(".#{avatar}")
|
33
|
-
end
|
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}")
|
34
36
|
end
|
35
37
|
end
|
38
|
+
end
|
39
|
+
end
|
36
40
|
|
37
|
-
|
38
|
-
|
39
|
-
|
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}$/)
|
40
46
|
end
|
41
47
|
end
|
48
|
+
end
|
49
|
+
end
|
42
50
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
48
56
|
end
|
49
57
|
end
|
58
|
+
end
|
59
|
+
end
|
50
60
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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}")
|
56
66
|
end
|
57
67
|
end
|
68
|
+
end
|
69
|
+
end
|
58
70
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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}")
|
64
76
|
end
|
65
77
|
end
|
78
|
+
end
|
79
|
+
end
|
66
80
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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)
|
71
86
|
end
|
87
|
+
end
|
88
|
+
end
|
72
89
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
77
98
|
end
|
99
|
+
end
|
100
|
+
end
|
78
101
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
84
|
-
end
|
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
|
85
106
|
end
|
107
|
+
end
|
86
108
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
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
|
94
115
|
|
95
|
-
|
96
|
-
|
97
|
-
|
116
|
+
describe Gravaty::Gravaty do
|
117
|
+
describe 'when created with a valid email address ' do
|
118
|
+
subject do
|
119
|
+
Gravaty::Gravaty.new(Gravaty::TEST_MY_ADDRESS,
|
120
|
+
Gravaty.parser)
|
121
|
+
end
|
98
122
|
|
99
|
-
|
100
|
-
|
101
|
-
|
123
|
+
test_avatar_formats
|
124
|
+
|
125
|
+
test_allowed_sizes
|
126
|
+
|
127
|
+
test_unallowed_sizes
|
128
|
+
|
129
|
+
test_rating_options
|
130
|
+
|
131
|
+
test_unknown_parameters
|
102
132
|
|
103
|
-
|
104
|
-
|
133
|
+
describe 'when asked for forcing default image' do
|
134
|
+
it 'shall provide a forced URI' do
|
135
|
+
_(subject.avatar(force: true)).must_include Gravaty::TEST_FORCED
|
105
136
|
end
|
106
137
|
end
|
138
|
+
|
139
|
+
test_default_options
|
140
|
+
|
141
|
+
test_own_default_image
|
107
142
|
end
|
108
143
|
end
|
data/test/gravaty/test_parser.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2013 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,14 +20,17 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2013 Marco Bresciani
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
27
|
#++
|
20
28
|
|
21
29
|
require_relative '../test_helper'
|
22
30
|
|
23
31
|
describe Gravaty::Gravaty do
|
24
32
|
describe 'when using a parser ' do
|
25
|
-
|
26
|
-
subject { Gravaty::parser }
|
33
|
+
subject { Gravaty.parser }
|
27
34
|
|
28
35
|
it 'shall provide a list of parsers' do
|
29
36
|
_(subject.parsers).wont_be_empty
|
@@ -40,13 +47,12 @@ describe Gravaty::Gravaty do
|
|
40
47
|
Gravaty::ALLOWED_PARAMS.each do |param|
|
41
48
|
parsable_mocks[param] = MiniTest::Mock.new
|
42
49
|
parsable_mocks[param].expect(:parse, false, [nil])
|
43
|
-
parsable_mocks[param].expect(:nil?, false)
|
44
50
|
end
|
45
51
|
|
46
52
|
my_parser = Gravaty::Parser.new(parsable_mocks)
|
47
53
|
|
48
54
|
Gravaty::ALLOWED_PARAMS.each do |param|
|
49
|
-
my_parser.parse
|
55
|
+
my_parser.parse param
|
50
56
|
parsable_mocks[param].verify
|
51
57
|
end
|
52
58
|
end
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2013 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,14 +20,52 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2013 Marco Bresciani
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
27
|
#++
|
20
28
|
|
21
29
|
require_relative '../test_helper'
|
22
30
|
|
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
|
39
|
+
|
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
|
49
|
+
|
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
|
62
|
+
|
23
63
|
describe Gravaty::Gravaty do
|
24
64
|
describe 'when created with a valid email address ' do
|
25
|
-
subject
|
26
|
-
|
65
|
+
subject do
|
66
|
+
Gravaty::Gravaty.new(Gravaty::TEST_MY_ADDRESS,
|
67
|
+
Gravaty.parser)
|
68
|
+
end
|
27
69
|
|
28
70
|
Gravaty::PROFILE_FORMATS.each do |format|
|
29
71
|
describe "when asked for '#{format}' profile" do
|
@@ -39,28 +81,8 @@ describe Gravaty::Gravaty do
|
|
39
81
|
end
|
40
82
|
end
|
41
83
|
|
42
|
-
|
43
|
-
it 'shall provide an URI in JSON format' do
|
44
|
-
_(subject.json).must_match Gravaty::TEST_JSON_REGEXP
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'shall provide a JSON URI when callback is provided' do
|
48
|
-
_(subject.json).must_match Gravaty::TEST_JSON_REGEXP
|
49
|
-
_(subject.json(callback: Gravaty::TEST_CALLBACK)).must_match(/#{Gravaty::TEST_CALLBACK}$/)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe 'when asked for QR code format ' do
|
54
|
-
it 'shall provide an URI in QR code format' do
|
55
|
-
_(subject.qrcode).must_match Gravaty::TEST_QR_REGEXP
|
56
|
-
end
|
84
|
+
test_json
|
57
85
|
|
58
|
-
|
59
|
-
it "shall provide a '#{size}' pixels URI, when size '#{size}'" do
|
60
|
-
_(subject.qrcode).must_match Gravaty::TEST_QR_REGEXP
|
61
|
-
_(subject.qrcode(pixelsize: size)).must_match(/#{Gravaty::TEST_SIZE_REGEXP}$/)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
86
|
+
test_qrcode
|
65
87
|
end
|
66
88
|
end
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2013 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,6 +20,10 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2013 Marco Bresciani
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
27
|
#++
|
20
28
|
|
21
29
|
require_relative '../../test_helper'
|
@@ -23,53 +31,60 @@ require_relative '../../test_helper'
|
|
23
31
|
describe Gravaty::Utils::Downloader do
|
24
32
|
describe 'when passed a nil uri' do
|
25
33
|
it 'must raise a RuntimeError' do
|
26
|
-
_(
|
27
|
-
|
28
|
-
.
|
34
|
+
_(lambda {
|
35
|
+
Gravaty::Utils::Downloader::Downloader
|
36
|
+
.download_file nil, 'filename'
|
37
|
+
})
|
38
|
+
.must_raise RuntimeError
|
29
39
|
end
|
30
40
|
end
|
31
41
|
|
32
42
|
describe 'when passed an invalid uri' do
|
33
43
|
it 'must raise a InvalidURIError' do
|
34
|
-
_(
|
35
|
-
|
36
|
-
|
37
|
-
|
44
|
+
_(lambda {
|
45
|
+
Gravaty::Utils::Downloader::Downloader
|
46
|
+
.download_file 'http://example.com/%uABCD',
|
47
|
+
'filename'
|
48
|
+
})
|
49
|
+
.must_raise URI::InvalidURIError
|
38
50
|
end
|
39
51
|
end
|
40
52
|
|
41
53
|
describe 'when passed a nil filename' do
|
42
54
|
it 'must raise a TypeError' do
|
43
|
-
_(
|
44
|
-
|
45
|
-
|
55
|
+
_(lambda {
|
56
|
+
Gravaty::Utils::Downloader::Downloader
|
57
|
+
.download_file 'http://www.example.com',
|
58
|
+
nil
|
59
|
+
}).must_raise TypeError
|
46
60
|
end
|
47
61
|
end
|
48
62
|
|
63
|
+
http_file = 'wget-latest.tar.gz'
|
64
|
+
download_url = 'ftp.jaist.ac.jp/pub/GNU/wget/'
|
65
|
+
|
49
66
|
describe 'when passed a valid HTTP filename' do
|
50
67
|
it 'must download a proper file' do
|
51
|
-
DESTINATION_FILE = 'wget-latest.tar.gz'
|
52
68
|
Gravaty::Utils::Downloader::Downloader
|
53
|
-
|
54
|
-
|
55
|
-
_(File.exist?(
|
56
|
-
File.delete
|
57
|
-
_(File.exist?(
|
69
|
+
.download_file "http://#{download_url}",
|
70
|
+
http_file
|
71
|
+
_(File.exist?(http_file)).must_equal(true)
|
72
|
+
File.delete http_file
|
73
|
+
_(File.exist?(http_file)).must_equal(false)
|
58
74
|
end
|
59
75
|
end
|
60
76
|
|
61
77
|
describe 'when passed a valid HTTPS filename' do
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
ENV['SSL_CERT_FILE'] = OLD_CERT
|
78
|
+
if ENV['SSL_CERT_FILE']
|
79
|
+
it 'must download a proper file' do
|
80
|
+
# https_file = 'wget-latest.tar.gz'
|
81
|
+
Gravaty::Utils::Downloader::Downloader
|
82
|
+
.download_file "https://#{download_url}",
|
83
|
+
https_file
|
84
|
+
_(File.exist?(https_file)).must_equal(true)
|
85
|
+
File.delete https_file
|
86
|
+
_(File.exist?(https_file)).must_equal(false)
|
87
|
+
end
|
73
88
|
end
|
74
89
|
end
|
75
90
|
end
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
5
|
+
# rubocop:disable Style/AsciiComments
|
6
|
+
# © 2013 Marco Bresciani
|
7
|
+
# rubocop:enable Style/AsciiComments
|
4
8
|
#
|
5
9
|
# This file is part of gravaty.
|
6
10
|
#
|
@@ -16,10 +20,45 @@
|
|
16
20
|
#
|
17
21
|
# You should have received a copy of the GNU General Public License
|
18
22
|
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
# SPDX-FileCopyrightText: 2013 Marco Bresciani
|
25
|
+
#
|
26
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
27
|
#++
|
20
28
|
|
21
29
|
require_relative '../../test_helper'
|
22
30
|
|
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
|
47
|
+
|
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
|
61
|
+
|
23
62
|
describe Gravaty::Utils::Raisers do
|
24
63
|
include Gravaty::Utils::Raisers
|
25
64
|
|
@@ -31,31 +70,8 @@ describe Gravaty::Utils::Raisers do
|
|
31
70
|
end
|
32
71
|
|
33
72
|
describe 'when running any raiser method' do
|
34
|
-
|
35
|
-
all_methods = Hash.new
|
36
|
-
all_methods[:raiser_downcase] = [[nil, nil], ['value', ['value']]]
|
37
|
-
all_methods[:raiser_to_i] = [[nil, nil], ['42', [42]]]
|
38
|
-
|
39
|
-
all_methods.each_key do |method_name|
|
40
|
-
a_method = self.method method_name
|
41
|
-
all_methods[method_name.to_sym].each do |params|
|
42
|
-
a_method.call 'error.value', params[0], params[1]
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
73
|
+
test_no_arg_error
|
46
74
|
|
47
|
-
|
48
|
-
all_methods = Hash.new
|
49
|
-
all_methods[:raiser_downcase] = ['value', ['no value']]
|
50
|
-
all_methods[:raiser_to_i] = ['42', [47]]
|
51
|
-
|
52
|
-
all_methods.each_key do |method_name|
|
53
|
-
a_method = self.method method_name
|
54
|
-
_(-> { a_method.call 'error.value',
|
55
|
-
all_methods[method_name.to_sym][0],
|
56
|
-
all_methods[method_name.to_sym][1] })
|
57
|
-
.must_raise ArgumentError
|
58
|
-
end
|
59
|
-
end
|
75
|
+
test_arg_error
|
60
76
|
end
|
61
77
|
end
|