code-assertions 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/code-assertions.rb +27 -4
- metadata +13 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d46163d28b48428a1c68234df06918db3b24973accab67b80174c4abe40b46e9
|
4
|
+
data.tar.gz: 11fc426eae7f60d5006b4e11ddfb37774bfd36f11c7f7075aa80bd7ba2ce9920
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 011cc490f2289a610fd489e4b28e28701a311d09dc0aee0f1d2b8cc66591b8c4d073c302a479fd5840337389f3c8e49abeeb0f9b55aa8579da6ce5e0a6d7d5e6
|
7
|
+
data.tar.gz: f71a035f850488dc62e4728a79ead92d808e52578f4ca80aaa85c69c9dcf44b6543ad37161b4a16f1e9a486ce43880d61e0ec9d2c1297d17adfb2f54274b2781
|
data/lib/code-assertions.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "sourcify"
|
2
2
|
|
3
3
|
module CodeAssertions
|
4
|
-
|
4
|
+
CodeAssertionFailed = Class.new(Exception)
|
5
5
|
@@assertions_check = true
|
6
6
|
|
7
7
|
def assertions_off
|
@@ -16,7 +16,12 @@ module CodeAssertions
|
|
16
16
|
warn "Empty assertion passed."
|
17
17
|
return
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
|
+
begin
|
21
|
+
message = "Assertion failed: " + block.to_source[6...-1].strip unless message
|
22
|
+
rescue Exception
|
23
|
+
message = "Assertion failed: <no message provided>"
|
24
|
+
end
|
20
25
|
raise CodeAssertionFailed, message unless block.call
|
21
26
|
end
|
22
27
|
|
@@ -26,7 +31,12 @@ module CodeAssertions
|
|
26
31
|
warn "Empty assertion passed."
|
27
32
|
return
|
28
33
|
end
|
29
|
-
|
34
|
+
|
35
|
+
begin
|
36
|
+
message = "Assertion failed: " + block.to_source[6...-1].strip unless message
|
37
|
+
rescue Exception
|
38
|
+
message = "Assertion failed: <no message provided>"
|
39
|
+
end
|
30
40
|
warn message unless block.call
|
31
41
|
end
|
32
42
|
end
|
@@ -34,34 +44,47 @@ end
|
|
34
44
|
class Object
|
35
45
|
def assert_not_nil!
|
36
46
|
assert("The result cannot be `nil` or `false`.") { self }
|
47
|
+
|
48
|
+
self
|
37
49
|
end
|
38
50
|
alias :assert_nn! :assert_not_nil!
|
39
51
|
|
40
52
|
def assert_type!(type)
|
41
53
|
assert("`type` should be an instance of `Class`") { type.is_a?(Class) }
|
42
54
|
assert("Wrong type: expected #{type.name}, given #{self.class.name}") { self.is_a?(type) }
|
55
|
+
|
56
|
+
self
|
43
57
|
end
|
44
58
|
|
45
|
-
alias :at!
|
59
|
+
alias :at! :assert_type!
|
60
|
+
alias :is_a! :assert_type!
|
46
61
|
end
|
47
62
|
|
48
63
|
class File
|
49
64
|
def assert_exist!
|
50
65
|
assert("The specified file should exist: `#{self.path}`.") { FileTest.exist?(self.path) }
|
66
|
+
|
67
|
+
self
|
51
68
|
end
|
52
69
|
|
53
70
|
def assert_not_exist!(filename)
|
54
71
|
assert("The specified file should not exist: `#{self.path}`.") { !FileTest.exist?(self.path) }
|
72
|
+
|
73
|
+
self
|
55
74
|
end
|
56
75
|
end
|
57
76
|
|
58
77
|
class String
|
59
78
|
def assert_empty!
|
60
79
|
assert("Expected empty string, `#{self}` instead") { self.size == 0 }
|
80
|
+
|
81
|
+
self
|
61
82
|
end
|
62
83
|
|
63
84
|
def assert_not_empty!
|
64
85
|
assert("Expected empty string, `#{self}` instead") { self.size > 0 }
|
86
|
+
|
87
|
+
self
|
65
88
|
end
|
66
89
|
end
|
67
90
|
|
metadata
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code-assertions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simone Scalabrino
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sourcify
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.5.0
|
20
|
-
- - "
|
20
|
+
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 0.5.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - "
|
27
|
+
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 0.5.0
|
30
|
-
- - "
|
30
|
+
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 0.5.0
|
33
33
|
description: Provides and includes a module that helps to make solid scripts for data
|
@@ -38,10 +38,11 @@ extensions: []
|
|
38
38
|
extra_rdoc_files: []
|
39
39
|
files:
|
40
40
|
- lib/code-assertions.rb
|
41
|
-
homepage:
|
42
|
-
licenses:
|
41
|
+
homepage: https://github.com/intersimone999/code-assertions
|
42
|
+
licenses:
|
43
|
+
- GPL-3.0-only
|
43
44
|
metadata: {}
|
44
|
-
post_install_message:
|
45
|
+
post_install_message:
|
45
46
|
rdoc_options: []
|
46
47
|
require_paths:
|
47
48
|
- lib
|
@@ -56,8 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
57
|
- !ruby/object:Gem::Version
|
57
58
|
version: '0'
|
58
59
|
requirements: []
|
59
|
-
rubygems_version: 3.
|
60
|
-
signing_key:
|
60
|
+
rubygems_version: 3.1.4
|
61
|
+
signing_key:
|
61
62
|
specification_version: 4
|
62
63
|
summary: Simple code assertions toolkit for scripts
|
63
64
|
test_files: []
|