simplecheck 1.0 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/LICENSE +22 -0
- data/README.md +34 -32
- data/Rakefile +8 -0
- data/examples/argument_example.rb +4 -4
- data/examples/block_example.rb +4 -4
- data/examples/case_equality_check.rb +5 -5
- data/examples/person_example.rb +18 -24
- data/lib/simplecheck.rb +22 -22
- data/lib/simplecheck/check_failed.rb +1 -1
- data/lib/simplecheck/version.rb +1 -1
- data/simplecheck.gemspec +11 -11
- data/test/simplecheck_test.rb +53 -14
- metadata +12 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b05cb2a1bd9000b3dc9519a7dff8980a8938614
|
4
|
+
data.tar.gz: 9a35961dc01ebb3d95620f2ed58bdfe352a5bf33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e1b11ae24ff312d64482ee9b47f82ec06a548afddec64f791149d5bc58ea6e346a282b141bdde1d99d265c2778c66066f9c46758b6c514ecf15082f95e8457c
|
7
|
+
data.tar.gz: d5cd76cbfa5e7b90ac354ba3c2b248dcaa3acd8b397c285b7187df97d641851bcdc6628a1295685e3f60bbb74dc3b11c878fee99ce7d5d476c9247c5d8a60829
|
data/CHANGELOG.md
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright 2013 AIMRED CC. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions are met:
|
5
|
+
|
6
|
+
* Redistributions of source code must retain the above copyright notice, this
|
7
|
+
list of conditions and the following disclaimer.
|
8
|
+
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
14
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
15
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
17
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
18
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
19
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
20
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
21
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
22
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# Simplecheck
|
2
2
|
|
3
|
-
Simplecheck is a lightweight property checking API for Ruby designed to quickly check arguments. Once included into a class it provides the `check` instance method which takes arguments and a condition to check them against.
|
3
|
+
Simplecheck is a lightweight property checking API for Ruby designed to quickly check arguments in under 50 lines of Ruby. Once included into a class it provides the `check` instance method which takes arguments and a condition to check them against.
|
4
4
|
|
5
5
|
If a check fails a `Simplecheck::CheckFailed` exception is raised.
|
6
6
|
|
7
|
+
Simplecheck is compatiable with Ruby 2.0.0 and above only.
|
8
|
+
|
7
9
|
## Installation
|
8
10
|
|
9
11
|
Simplecheck is available as a Rubygem installable via [gem install simplecheck](http://rubygems.org/gems/simplecheck).
|
@@ -20,16 +22,26 @@ A git repository is also available at [http://github.com/farrel/simplecheck](htt
|
|
20
22
|
attr_accessor( :name, :age )
|
21
23
|
|
22
24
|
def initialize( name, age )
|
23
|
-
check(
|
24
|
-
check(
|
25
|
+
check(name, String, error_message: 'name must be a String') # Check name is String with custom error message
|
26
|
+
check(age, 18..75) # Check age is within Range
|
25
27
|
|
26
28
|
@name, @age = name, age
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
Customer.new(
|
31
|
-
|
32
|
-
|
32
|
+
Customer.new("Joe", 25) # No error
|
33
|
+
|
34
|
+
begin
|
35
|
+
Customer.new(nil, 25)
|
36
|
+
rescue Simplecheck::CheckFailed => exception
|
37
|
+
puts exception.message # => 'name must be a String'
|
38
|
+
ebd
|
39
|
+
|
40
|
+
begin
|
41
|
+
Customer.new("Joe", 15)
|
42
|
+
rescue Simplecheck::CheckFailed => exception
|
43
|
+
puts exception.message # => '15 does not satisfy 18..75'
|
44
|
+
ebd
|
33
45
|
|
34
46
|
## Check Methods
|
35
47
|
|
@@ -39,12 +51,18 @@ Simplecheck currently supports three different check methods:
|
|
39
51
|
* Case Equality (===) Check
|
40
52
|
* Block Check
|
41
53
|
|
54
|
+
### Custom Error Message
|
55
|
+
|
56
|
+
All check methods may take an optional named parameter `error_message` to override the default error message.
|
57
|
+
|
58
|
+
check(age, Integer, error_message: 'Age must be an whole number')
|
59
|
+
|
42
60
|
### Expression Check
|
43
61
|
|
44
62
|
In the simplest case `check` takes an expression as an argument. If the expression evaluates to `nil` or `false` it will fail.
|
45
63
|
|
46
64
|
def calculate_percentage( score, total )
|
47
|
-
check(
|
65
|
+
check(total > 0)
|
48
66
|
100.0 * score / total
|
49
67
|
end
|
50
68
|
|
@@ -52,37 +70,36 @@ In the simplest case `check` takes an expression as an argument. If the expressi
|
|
52
70
|
|
53
71
|
If two or more arguments are given without a block, then the last argument becomes the condition against which the previous arguments are checked. To accomplish this the condition argument should implement the case equality operator (`===` or threequal) in a logical manner.
|
54
72
|
|
55
|
-
def greatest_common_divisor(
|
56
|
-
check(
|
73
|
+
def greatest_common_divisor(a, b)
|
74
|
+
check(a, b, Integer)
|
57
75
|
# GCD Algorithm...
|
58
76
|
end
|
59
77
|
|
60
78
|
If a class does not alias or implement it's own version of `===` it has the same functionality as `==`. The following Ruby Core classes already alias `===` to various instance methods.
|
61
79
|
|
62
|
-
|
63
80
|
#### Class
|
64
81
|
|
65
82
|
`===` is aliased to `kind_of?`:
|
66
83
|
|
67
|
-
check(
|
84
|
+
check(age, Numeric)
|
68
85
|
|
69
86
|
#### Range
|
70
87
|
|
71
88
|
`===` is aliased to `include?`:
|
72
89
|
|
73
|
-
check(
|
90
|
+
check(age, 18..75)
|
74
91
|
|
75
92
|
#### Regexp
|
76
93
|
|
77
|
-
`===` is aliased to
|
94
|
+
`===` is aliased to `=~`:
|
78
95
|
|
79
|
-
check(
|
96
|
+
check(phone_number, /^\d\d\d-\d\d\d\d$/)
|
80
97
|
|
81
98
|
#### Proc
|
82
99
|
|
83
100
|
`===` is aliased to `call`:
|
84
101
|
|
85
|
-
check(
|
102
|
+
check(password, password_confirmation , ->(p) { !Dict.lookup(p) })
|
86
103
|
|
87
104
|
#### Custom Check Object
|
88
105
|
|
@@ -90,13 +107,13 @@ The default behaviour of `Object#===` is the same as `Object#==`. To customise t
|
|
90
107
|
|
91
108
|
For example to check whether a set of points is inside a given polygon we would implement `Polygon#===` as a [point-in-polygon algorithm](https://en.wikipedia.org/wiki/Point_in_polygon), allowing us to carry out the check using a Polygon instance:
|
92
109
|
|
93
|
-
check(
|
110
|
+
check(point_1, point_2, polygon)
|
94
111
|
|
95
112
|
### Block Check
|
96
113
|
|
97
114
|
A block can be passed to `check`, with the arguments passed to `check` then passed individually to the block:
|
98
115
|
|
99
|
-
check(
|
116
|
+
check(a, b, c) do |n|
|
100
117
|
n.odd?
|
101
118
|
end
|
102
119
|
|
@@ -115,18 +132,3 @@ Case Equality and Block checks can be called with multiple arguments, with each
|
|
115
132
|
|
116
133
|
* Git repository - [http://github.com/farrel/simplecheck](http://github.com/farrel/simplecheck)
|
117
134
|
* Rubygem page - [http://rubygems.org/gems/simplecheck](http://rubygems.org/gems/simplecheck)
|
118
|
-
|
119
|
-
## License
|
120
|
-
Simplecheck is released under the BSD License.
|
121
|
-
|
122
|
-
Copyright 2013 AIMRED CC. All rights reserved.
|
123
|
-
|
124
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
125
|
-
|
126
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
127
|
-
|
128
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
129
|
-
|
130
|
-
THIS SOFTWARE IS PROVIDED BY AIMRED CC "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AIMRED CC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
131
|
-
|
132
|
-
The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of AIMRED CC.
|
data/Rakefile
ADDED
data/examples/block_example.rb
CHANGED
@@ -3,10 +3,10 @@ require 'simplecheck'
|
|
3
3
|
include Simplecheck
|
4
4
|
|
5
5
|
# Block passed implicitly to check
|
6
|
-
check(
|
6
|
+
check(2, 4) { |x| x.even? }
|
7
7
|
|
8
8
|
# Block passed explicity to check
|
9
|
-
is_even =
|
10
|
-
check(
|
9
|
+
is_even = ->(x) { x.even? }
|
10
|
+
check(2, 4, &is_even)
|
11
11
|
|
12
|
-
puts
|
12
|
+
puts 'All passed'
|
@@ -3,15 +3,15 @@ require 'simplecheck'
|
|
3
3
|
include Simplecheck
|
4
4
|
|
5
5
|
# Class#=== -> Class#kind_of?
|
6
|
-
check(
|
6
|
+
check(1, Integer)
|
7
7
|
|
8
8
|
# Regexp#=== -> Regexp#match
|
9
|
-
check(
|
9
|
+
check('aaabbb', /^aaa/)
|
10
10
|
|
11
11
|
# Range#=== -> Range#include?
|
12
|
-
check(
|
12
|
+
check(1, 1..10)
|
13
13
|
|
14
14
|
# Proc#=== -> Proc#call
|
15
|
-
check(
|
15
|
+
check(1, ->(n) { n.odd? })
|
16
16
|
|
17
|
-
puts
|
17
|
+
puts 'All passed'
|
data/examples/person_example.rb
CHANGED
@@ -5,51 +5,45 @@ class Person
|
|
5
5
|
include Simplecheck
|
6
6
|
include Comparable
|
7
7
|
|
8
|
-
attr_accessor
|
8
|
+
attr_accessor :name, :surname, :date_of_birth
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
check
|
12
|
-
check
|
10
|
+
def initialize(name, surname, date_of_birth)
|
11
|
+
check name, surname, String
|
12
|
+
check date_of_birth, Date
|
13
13
|
|
14
14
|
@name = name
|
15
15
|
@surname = surname
|
16
16
|
@date_of_birth = date_of_birth
|
17
17
|
end
|
18
18
|
|
19
|
-
def <=>(
|
20
|
-
check
|
21
|
-
check
|
19
|
+
def <=>(other)
|
20
|
+
check other, Person
|
21
|
+
check other.date_of_birth
|
22
22
|
|
23
|
-
|
23
|
+
date_of_birth <=> other.date_of_birth
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def try
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
puts "Check Failed: #{ exception.message }"
|
32
|
-
rescue => exception
|
33
|
-
puts "EXCEPTION: #{ exception.message }"
|
34
|
-
end
|
28
|
+
yield
|
29
|
+
rescue Simplecheck::CheckFailed => exception
|
30
|
+
puts "Simplecheck::CheckFailed: #{ exception.message }"
|
35
31
|
end
|
36
32
|
|
37
33
|
# date_of_birth is not a Date
|
38
|
-
try{ Person.new(
|
34
|
+
try { Person.new('Bob', 'Roberts', '1980-01-01') }
|
39
35
|
|
40
|
-
bob = Person.new(
|
41
|
-
joe = Person.new(
|
36
|
+
bob = Person.new('Bob', 'Roberts', Date.civil(1970, 1, 1))
|
37
|
+
joe = Person.new('Joe', 'Josephs', Date.civil(1980, 1, 1))
|
42
38
|
|
43
39
|
# 1 is not a Person
|
44
|
-
try{ bob > 1 }
|
40
|
+
try { bob > 1 }
|
45
41
|
|
46
|
-
if joe > bob
|
47
|
-
puts "Joe > Bob"
|
48
|
-
end
|
42
|
+
puts 'Joe > Bob' if joe > bob
|
49
43
|
|
50
44
|
bob.date_of_birth = nil
|
51
45
|
|
52
46
|
# date_of_birth is not present
|
53
|
-
try{ joe > bob }
|
47
|
+
try { joe > bob }
|
54
48
|
|
55
|
-
puts
|
49
|
+
puts 'Finished'
|
data/lib/simplecheck.rb
CHANGED
@@ -2,42 +2,42 @@ require 'simplecheck/version'
|
|
2
2
|
require 'simplecheck/check_failed'
|
3
3
|
|
4
4
|
module Simplecheck
|
5
|
-
def check(
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
def check(*arguments, error_message: nil, &block)
|
6
|
+
default_error_message = if block_given?
|
7
|
+
Simplecheck.check_arguments_with_block(arguments, block)
|
8
|
+
else
|
9
|
+
Simplecheck.check_arguments(arguments)
|
10
|
+
end
|
11
|
+
|
12
|
+
default_error_message ? Simplecheck.handle_failure(error_message || default_error_message) : true
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def self.check_arguments(arguments)
|
16
16
|
case arguments.size
|
17
17
|
when 1
|
18
|
-
|
18
|
+
check_expression(arguments[0])
|
19
19
|
else
|
20
|
-
|
20
|
+
check_case_equality(*arguments)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
|
24
|
+
def self.check_arguments_with_block(arguments, block)
|
25
|
+
check_arguments(arguments + [block])
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
|
30
|
-
'Condition is not satisfied'
|
31
|
-
end
|
28
|
+
def self.check_expression(expression_satisfied)
|
29
|
+
'Condition is not satisfied' unless expression_satisfied
|
32
30
|
end
|
33
31
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
32
|
+
def self.check_case_equality(*arguments, check_argument)
|
33
|
+
invalid_argument_index = arguments.index{ |argument| !(check_argument === argument) }
|
34
|
+
|
35
|
+
if invalid_argument_index
|
36
|
+
"#{ arguments[invalid_argument_index] } does not satisfy #{ check_argument }"
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
41
|
-
|
40
|
+
def self.handle_failure(message)
|
41
|
+
fail(Simplecheck::CheckFailed, message)
|
42
42
|
end
|
43
43
|
end
|
data/lib/simplecheck/version.rb
CHANGED
data/simplecheck.gemspec
CHANGED
@@ -3,17 +3,17 @@ $:.unshift File.expand_path('../lib', __FILE__)
|
|
3
3
|
require 'simplecheck/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
|
-
s.name
|
7
|
-
s.version
|
8
|
-
s.platform
|
9
|
-
s.authors
|
10
|
-
s.email
|
11
|
-
s.homepage
|
12
|
-
s.summary
|
13
|
-
s.description
|
14
|
-
|
15
|
-
s.
|
16
|
-
|
6
|
+
s.name = 'simplecheck'
|
7
|
+
s.version = Simplecheck::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Farrel Lifson']
|
10
|
+
s.email = ['farrel.lifson@aimred.com']
|
11
|
+
s.homepage = 'http://github.com/farrel/simplecheck'
|
12
|
+
s.summary = 'Simple property checking for Ruby'
|
13
|
+
s.description = 'Simple property checking for Ruby'
|
14
|
+
s.license = 'BSD 2-Clause'
|
15
|
+
s.required_ruby_version = '>= 2.0.0'
|
16
|
+
|
17
17
|
s.files = `git ls-files`.split("\n")
|
18
18
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
19
19
|
s.require_paths = ['lib']
|
data/test/simplecheck_test.rb
CHANGED
@@ -4,58 +4,97 @@ class TestSimplecheck < MiniTest::Test
|
|
4
4
|
include Simplecheck
|
5
5
|
|
6
6
|
def test_expression_check_true
|
7
|
-
assert(
|
7
|
+
assert(check(1))
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_expression_check_raises_exception
|
11
|
-
assert_raises(
|
11
|
+
assert_raises(Simplecheck::CheckFailed) { check(nil) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_expression_check_raises_exception_with_error_message
|
15
|
+
exception = assert_raises(Simplecheck::CheckFailed) { check(nil, error_message: 'Nil object') }
|
16
|
+
assert_equal(exception.message, 'Nil object')
|
12
17
|
end
|
13
18
|
|
14
19
|
def test_case_equality_check_true
|
15
|
-
assert(
|
20
|
+
assert(check(1, Integer))
|
16
21
|
end
|
17
22
|
|
18
23
|
def test_case_equality_check_raises_exception
|
19
|
-
assert_raises(
|
24
|
+
assert_raises(Simplecheck::CheckFailed) { check('1', Integer) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_case_equality_check_raises_exception_with_error_message
|
28
|
+
exception = assert_raises(Simplecheck::CheckFailed) { check('1', Integer, error_message: 'Not Integer') }
|
29
|
+
assert_equal(exception.message, 'Not Integer')
|
20
30
|
end
|
21
31
|
|
22
32
|
def test_case_equality_check_multiple_arguments
|
23
|
-
assert(
|
33
|
+
assert(check(1, 2, Integer))
|
24
34
|
end
|
25
35
|
|
26
36
|
def test_case_equality_check_multiple_arguments_raises_exception
|
27
|
-
assert_raises(
|
37
|
+
assert_raises(Simplecheck::CheckFailed) { check(1, '2', Integer) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_case_equality_check_multiple_arguments_raises_exception_with_error_message
|
41
|
+
exception = assert_raises(Simplecheck::CheckFailed) { check(1, '2', Integer, error_message: 'Not Integer') }
|
42
|
+
assert_equal(exception.message, 'Not Integer')
|
28
43
|
end
|
29
44
|
|
30
45
|
def test_block_check_true
|
31
|
-
assert(
|
46
|
+
assert(check(1) { |n| n.odd? })
|
32
47
|
end
|
33
48
|
|
34
49
|
def test_block_check_raises_exception
|
35
|
-
assert_raises(
|
50
|
+
assert_raises(Simplecheck::CheckFailed) { check(1) { |n| n.even? } }
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_block_check_raises_exception_with_error_message
|
54
|
+
exception = assert_raises(Simplecheck::CheckFailed) { check(1, error_message: 'Not Even') { |n| n.even? } }
|
55
|
+
assert_equal(exception.message, 'Not Even')
|
36
56
|
end
|
37
57
|
|
38
58
|
def test_block_check_multiple_arguments_true
|
39
|
-
assert(
|
59
|
+
assert(check(1, 1, 1) { |n| n.odd? })
|
40
60
|
end
|
41
61
|
|
42
62
|
def test_block_check_multiple_arguments_exception
|
43
|
-
assert_raises(
|
63
|
+
assert_raises(Simplecheck::CheckFailed) { check(1, 1, 2) { |n| n.odd? } }
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_block_check_multiple_arguments_exception_with_error_message
|
67
|
+
exception = assert_raises(Simplecheck::CheckFailed) { check(1, 1, 2, error_message: 'Not Odd') { |n| n.odd? } }
|
68
|
+
assert_equal(exception.message, 'Not Odd')
|
44
69
|
end
|
45
70
|
|
46
71
|
def test_lambda_argument_check_true
|
47
|
-
assert(
|
72
|
+
assert(check(1, ->(n) { n.odd? }))
|
48
73
|
end
|
49
74
|
|
50
75
|
def test_lambda_argument_check_raises_exception
|
51
|
-
assert_raises(
|
76
|
+
assert_raises(Simplecheck::CheckFailed) { check(1, ->(n) { n.even? }) }
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_lambda_argument_check_raises_exception_with_error_message
|
80
|
+
exception = assert_raises(Simplecheck::CheckFailed) { check(1, ->(n) { n.even? }, error_message: 'Not Even') }
|
81
|
+
assert_equal(exception.message, 'Not Even')
|
52
82
|
end
|
53
83
|
|
54
84
|
def test_lambda_block_check_true
|
55
|
-
assert(
|
85
|
+
assert(check(1, &->(n){ n.odd? }))
|
56
86
|
end
|
57
87
|
|
58
88
|
def test_lambda_block_check_raises_exception
|
59
|
-
assert_raises(
|
89
|
+
assert_raises(Simplecheck::CheckFailed) { check(1, &->(n){ n.even? }) }
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_lambda_block_check_raises_exception_with_error_message
|
93
|
+
exception = assert_raises(Simplecheck::CheckFailed) { check(1, error_message: 'Not Even', &->(n){ n.even? }) }
|
94
|
+
assert_equal(exception.message, 'Not Even')
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_nil_check
|
98
|
+
assert_raises(Simplecheck::CheckFailed) { check(nil, String) }
|
60
99
|
end
|
61
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplecheck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '2.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Farrel Lifson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Simple property checking for Ruby
|
14
14
|
email:
|
@@ -19,10 +19,12 @@ extra_rdoc_files:
|
|
19
19
|
- README.md
|
20
20
|
- CHANGELOG.md
|
21
21
|
files:
|
22
|
-
- .gitignore
|
22
|
+
- ".gitignore"
|
23
23
|
- CHANGELOG.md
|
24
24
|
- Guardfile
|
25
|
+
- LICENSE
|
25
26
|
- README.md
|
27
|
+
- Rakefile
|
26
28
|
- examples/argument_example.rb
|
27
29
|
- examples/block_example.rb
|
28
30
|
- examples/case_equality_check.rb
|
@@ -34,7 +36,8 @@ files:
|
|
34
36
|
- test/simplecheck_test.rb
|
35
37
|
- test/test_helper.rb
|
36
38
|
homepage: http://github.com/farrel/simplecheck
|
37
|
-
licenses:
|
39
|
+
licenses:
|
40
|
+
- BSD 2-Clause
|
38
41
|
metadata: {}
|
39
42
|
post_install_message:
|
40
43
|
rdoc_options: []
|
@@ -42,17 +45,17 @@ require_paths:
|
|
42
45
|
- lib
|
43
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
44
47
|
requirements:
|
45
|
-
- -
|
48
|
+
- - ">="
|
46
49
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
50
|
+
version: 2.0.0
|
48
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
52
|
requirements:
|
50
|
-
- -
|
53
|
+
- - ">="
|
51
54
|
- !ruby/object:Gem::Version
|
52
55
|
version: '0'
|
53
56
|
requirements: []
|
54
|
-
rubyforge_project:
|
55
|
-
rubygems_version: 2.0
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.2.0
|
56
59
|
signing_key:
|
57
60
|
specification_version: 4
|
58
61
|
summary: Simple property checking for Ruby
|