solid_assert 0.5.0 → 0.6.0
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.
- data/README.md +35 -3
- data/VERSION +1 -1
- data/solid_assert.gemspec +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
# solid_assert
|
2
2
|
|
3
|
-
solid_assert is a simple implementation of an `assert` utility in Ruby.
|
3
|
+
*solid_assert* is a simple implementation of an `assert` utility in Ruby. It let you code tests for your assumptions inside your code itself.
|
4
4
|
|
5
|
-
|
5
|
+
Notice that assertions shouldn't be used for handling error situations. Use Ruby built-in exception handling for that. Assertions are meant to test conditions about the integrity of your code. You should use them for testing assumptions like the following:
|
6
|
+
|
7
|
+
- If it reaches here, then this variable has to have this value.
|
8
|
+
- This line of code should never be executed.
|
9
|
+
- At this point, this list should contain one entry for all the keys in this hash.
|
6
10
|
|
7
11
|
The practice of using assertions makes your code more solid, since it is the computer who systematically verifies your code integrity.
|
8
12
|
|
13
|
+
Assertions should be used in development mode. You can disable them in production for performance reasons.
|
14
|
+
|
9
15
|
# Installation
|
10
16
|
|
11
17
|
In your `Gemfile`
|
@@ -14,11 +20,37 @@ In your `Gemfile`
|
|
14
20
|
|
15
21
|
# Usage
|
16
22
|
|
23
|
+
You can enable assertions with
|
24
|
+
|
25
|
+
SolidAssert.enable_assertions
|
26
|
+
|
27
|
+
You can disabled assertions with
|
28
|
+
|
29
|
+
SolidAssert.disable_assertions
|
30
|
+
|
31
|
+
Use `assert` for testing conditions. You can optionally provide a message
|
32
|
+
|
33
|
+
assert some_string != "some value"
|
34
|
+
assert clients.list?, "Isn't the clients list empty?"
|
35
|
+
|
36
|
+
Use `invariant` for testing blocks of code. This comes handy when testing your assumptions requires several lines of code. You can provide an optional message if you want
|
37
|
+
|
38
|
+
invariant do
|
39
|
+
one_variable = calculate_some_value
|
40
|
+
other_variable = calculate_some_other_value
|
41
|
+
one_variable > other_variable
|
42
|
+
end
|
43
|
+
|
44
|
+
invariant "Have the lists had different sizes?" do
|
45
|
+
one_variable = calculate_some_value
|
46
|
+
other_variable = calculate_some_other_value
|
47
|
+
one_variable > other_variable
|
48
|
+
end
|
17
49
|
|
18
50
|
## References
|
19
51
|
|
20
52
|
- [Programming with assertions](http://download.oracle.com/javase/1.4.2/docs/guide/lang/assert.html). A great article on assertions. It is about the Java language, but the concepts it explains apply to any programming language.
|
21
|
-
- [Writing Solid Code](http://www.amazon.com/Writing-Solid-Code-Microsoft-Programming/dp/1556155514).
|
53
|
+
- [Writing Solid Code](http://www.amazon.com/Writing-Solid-Code-Microsoft-Programming/dp/1556155514). A great book on good coding design practices. Again, it is related to C, but the practices it talks about apply to coding in any programming language.
|
22
54
|
|
23
55
|
|
24
56
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/solid_assert.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solid_assert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 6
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jorge Manrubia
|