code-assertions 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/code-assertions.rb +34 -10
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b0b9be63fb9ea6439a11ca769e4a5f8469209c3c263ae5883a21398b2653fdb
4
- data.tar.gz: 78d4a0d0ff834162b40f0cd7688aa86d4036eae032b7217b4757f67d319f6f3a
3
+ metadata.gz: 3f2ed9e2a5c10e98db6193d54592ac0d9571ef1174cd2a308a861f4448847886
4
+ data.tar.gz: 50ba48e37a720d6ced4d49659c65af3d1e02fa57229c70b51b10a42e8538dc16
5
5
  SHA512:
6
- metadata.gz: 3180d98fdc3c47cf30c29a1de6b95b8280273166ac33781ebc880229774035d8b9f54f6548a4f86fe7b30ff48714411bad92fc7b617778b4ee9a03b164aca2fb
7
- data.tar.gz: 426a2aeb02e58a2a84198ca610e2ccd71a9853f8e7c67fe7bb885457349236f9bbcfa6073e685a91987b2302c29b0c7e6788dcc0711945a5385bc3b7e2a6a25a
6
+ metadata.gz: 97d87675fd0f9b8d6ff44d83728ac7a2dd1c3f30122d35c5269517742897f974d8db6428d4e296b22f5d57b1fa8a59403d05d3a0b2c1e8d08bc49543ced36a79
7
+ data.tar.gz: ad6860f2ad59be7e156a78b934402bafc75e0cbe59709dc6d357c8b9d9aa68486a363095eff680a4a6858613e6c25e3c5615b5f3d20ec2cd680f23e75f3cfbde
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-assertions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simone Scalabrino