code-assertions 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/code-assertions.rb +34 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f2ed9e2a5c10e98db6193d54592ac0d9571ef1174cd2a308a861f4448847886
|
4
|
+
data.tar.gz: 50ba48e37a720d6ced4d49659c65af3d1e02fa57229c70b51b10a42e8538dc16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97d87675fd0f9b8d6ff44d83728ac7a2dd1c3f30122d35c5269517742897f974d8db6428d4e296b22f5d57b1fa8a59403d05d3a0b2c1e8d08bc49543ced36a79
|
7
|
+
data.tar.gz: ad6860f2ad59be7e156a78b934402bafc75e0cbe59709dc6d357c8b9d9aa68486a363095eff680a4a6858613e6c25e3c5615b5f3d20ec2cd680f23e75f3cfbde
|
data/lib/code-assertions.rb
CHANGED
@@ -20,16 +20,6 @@ module CodeAssertions
|
|
20
20
|
raise CodeAssertionFailed, message unless block.call
|
21
21
|
end
|
22
22
|
|
23
|
-
def assert_not_nil(object)
|
24
|
-
assert("The result cannot be `nil` or `false`. #{object} given") { object }
|
25
|
-
end
|
26
|
-
alias :assert_nn :assert_not_nil
|
27
|
-
|
28
|
-
def assert_type(type, object)
|
29
|
-
assert("`type` should be an instance of `Class`") { type.is_a?(Class) }
|
30
|
-
assert("Wrong type: expected #{type.name}, given #{object.class.name}") { object.is_a?(type) }
|
31
|
-
end
|
32
|
-
|
33
23
|
def soft_assert(message=nil, &block)
|
34
24
|
return unless @@assertions_check
|
35
25
|
unless block
|
@@ -41,4 +31,38 @@ module CodeAssertions
|
|
41
31
|
end
|
42
32
|
end
|
43
33
|
|
34
|
+
class Object
|
35
|
+
def assert_not_nil!
|
36
|
+
assert("The result cannot be `nil` or `false`.") { self }
|
37
|
+
end
|
38
|
+
alias :assert_nn! :assert_not_nil!
|
39
|
+
|
40
|
+
def assert_type!(type)
|
41
|
+
assert("`type` should be an instance of `Class`") { type.is_a?(Class) }
|
42
|
+
assert("Wrong type: expected #{type.name}, given #{self.class.name}") { self.is_a?(type) }
|
43
|
+
end
|
44
|
+
|
45
|
+
alias :at! :assert_type!
|
46
|
+
end
|
47
|
+
|
48
|
+
class File
|
49
|
+
def assert_exist!
|
50
|
+
assert("The specified file should exist: `#{self.path}`.") { FileTest.exist?(self.path) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def assert_not_exist!(filename)
|
54
|
+
assert("The specified file should not exist: `#{self.path}`.") { !FileTest.exist?(self.path) }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class String
|
59
|
+
def assert_empty!
|
60
|
+
assert("Expected empty string, `#{self}` instead") { self.size == 0 }
|
61
|
+
end
|
62
|
+
|
63
|
+
def assert_not_empty!
|
64
|
+
assert("Expected empty string, `#{self}` instead") { self.size > 0 }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
44
68
|
include CodeAssertions
|