solid_assert 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +35 -3
  2. data/VERSION +1 -1
  3. data/solid_assert.gemspec +1 -1
  4. 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
- It let you code in your assumptions when coding. Sometimes, when you are coding, you have this thinking of "I it reaches here, then this variable has to be this value", or "This line should never be executed", or "At this point, this list should contain an entry for all the keys in this hash". These are the kind of scenarios when assertions comes handy.
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.5.0
1
+ 0.6.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{solid_assert}
8
- s.version = "0.5.0"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Jorge Manrubia}]
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: 11
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
8
+ - 6
9
9
  - 0
10
- version: 0.5.0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jorge Manrubia