solid_assert 0.8.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -6
- data/lib/solid_assert/assert.rb +7 -19
- data/lib/solid_assert/version.rb +1 -1
- metadata +2 -3
- data/bin/console +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e4e886c38ff86c869a75fce0ac8da897a043abe
|
4
|
+
data.tar.gz: 26f7826d31e506cd3bf45c51a88c42a01463a155
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3100ef42a3d7b364cc5d063438d670f524191e5db21689bf25737477838978e86bf54f0c42da5bef5536c959ea6abea4e1335a02e6ff4cdd089ea2a2e862ae9c
|
7
|
+
data.tar.gz: 03063ace5b4b1ea666538d4bb3323b6134504ac5031046e136c16d11dbf1186751f1d749128a25e6541ef270b9fa5fdaf5dfc89d02c3877f4ce283ba3b49b5a4
|
data/README.md
CHANGED
@@ -33,18 +33,16 @@ SolidAssert.disable_assertions
|
|
33
33
|
|
34
34
|
Assertions are disabled by default.
|
35
35
|
|
36
|
-
Use `assert` for testing conditions. You can optionally provide an error message
|
37
|
-
exception class or exception object.
|
36
|
+
Use `assert` for testing conditions. You can optionally provide an error message.
|
38
37
|
|
39
38
|
```ruby
|
40
39
|
assert some_string != "some value"
|
41
40
|
assert clients.empty?, "The list must not be empty!"
|
42
|
-
assert xyz, StandardError.new("This is a custom exception object")
|
43
|
-
assert abc, CustomErrorClass
|
44
41
|
```
|
45
42
|
|
46
|
-
Use `invariant` for testing blocks of code. This comes handy
|
47
|
-
|
43
|
+
Use `invariant` for testing blocks of code. This comes handy
|
44
|
+
when testing your assumptions requires several lines of code.
|
45
|
+
You can provide an optional message too.
|
48
46
|
|
49
47
|
```ruby
|
50
48
|
invariant do
|
data/lib/solid_assert/assert.rb
CHANGED
@@ -12,20 +12,12 @@ module SolidAssert
|
|
12
12
|
# Usage:
|
13
13
|
# assert expr # raise SolidAssert::AssertionFailedError if expr is falsy
|
14
14
|
# assert !list.empty?, "The list should not be empty" # optional error message
|
15
|
-
# assert false, StandardError.new("Not XYZ!") # raise custom exception object
|
16
|
-
# assert false, CustomError # raise custom exception class
|
17
15
|
#
|
18
16
|
# @param condition A condition to assert
|
19
|
-
# @param
|
17
|
+
# @param message An optional error message
|
20
18
|
# @raise {AssertionFailedError} when the condition is not satisfied
|
21
|
-
def assert(condition,
|
22
|
-
if !condition
|
23
|
-
if exception.kind_of?(Exception) or exception.class.eql?(Class)
|
24
|
-
raise exception
|
25
|
-
else
|
26
|
-
raise SolidAssert::AssertionFailedError.new(exception)
|
27
|
-
end
|
28
|
-
end
|
19
|
+
def assert(condition, message = nil)
|
20
|
+
fail SolidAssert::AssertionFailedError.new(message) if !condition
|
29
21
|
end
|
30
22
|
|
31
23
|
# Let you {#assert} a block of code.
|
@@ -45,15 +37,11 @@ module SolidAssert
|
|
45
37
|
# some_number == other_number
|
46
38
|
# end
|
47
39
|
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# some_number == other_number
|
51
|
-
# end
|
52
|
-
#
|
53
|
-
# @param exception An optional error message (or exception)
|
40
|
+
# @param message An optional error message
|
41
|
+
# @raise {AssertionFailedError} when the condition is not satisfied
|
54
42
|
# @yield A block of code
|
55
|
-
def invariant(
|
56
|
-
assert yield,
|
43
|
+
def invariant(message = nil)
|
44
|
+
assert yield, message
|
57
45
|
end
|
58
46
|
end
|
59
47
|
end
|
data/lib/solid_assert/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solid_assert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jorge Manrubia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,7 +68,6 @@ files:
|
|
68
68
|
- LICENSE.txt
|
69
69
|
- README.md
|
70
70
|
- Rakefile
|
71
|
-
- bin/console
|
72
71
|
- lib/solid_assert.rb
|
73
72
|
- lib/solid_assert/assert.rb
|
74
73
|
- lib/solid_assert/assertion_failed_error.rb
|