solid_assert 0.7.2 → 0.7.3

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 +39 -19
  2. data/VERSION +1 -1
  3. data/solid_assert.gemspec +2 -2
  4. metadata +4 -4
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # solid_assert
2
2
 
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.
3
+ *solid_assert* is a simple implementation of an `assert` utility in Ruby. It let you write tests for your assumptions while coding.
4
4
 
5
5
  Assertions are meant to test conditions about the integrity of your code. You should use them for testing assumptions like the following:
6
6
 
7
7
  - If the flow reaches here, then this variable has to have this value.
8
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.
9
+ - At this point, this list should contain one entry for each key in this hash.
10
10
 
11
11
  Notice that assertions shouldn't be used for handling error situations. Use Ruby built-in exception handling for that.
12
12
 
@@ -16,39 +16,59 @@ Assertions are typically used in development mode. You might want to disable the
16
16
 
17
17
  In your `Gemfile`
18
18
 
19
- gem "solid_assert"
19
+ ```ruby
20
+ gem "solid_assert"
21
+ ```
20
22
 
21
23
  # Usage
22
24
 
23
25
  You can enable assertions with
24
26
 
25
- SolidAssert.enable_assertions
27
+ ```ruby
28
+ SolidAssert.enable_assertions
29
+ ```
26
30
 
27
31
  Assertions are disabled by default.
28
32
 
29
33
  Use `assert` for testing conditions. You can optionally provide a message
30
34
 
31
- assert some_string != "some value"
32
- assert clients.empty?, "Isn't the clients list empty?"
33
-
35
+ ```ruby
36
+ assert some_string != "some value"
37
+ assert clients.empty?, "Isn't the clients list empty?"
38
+ ```
39
+
34
40
  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
35
41
 
36
- invariant do
37
- one_variable = calculate_some_value
38
- other_variable = calculate_some_other_value
39
- one_variable > other_variable
40
- end
42
+ ```ruby
43
+ invariant do
44
+ one_variable = calculate_some_value
45
+ other_variable = calculate_some_other_value
46
+ one_variable > other_variable
47
+ end
48
+ ```
49
+
50
+ ```ruby
51
+ invariant "Lists with different sizes?" do
52
+ one_variable = calculate_some_value
53
+ other_variable = calculate_some_other_value
54
+ one_variable > other_variable
55
+ end
56
+ ```
57
+
58
+ ## Rails
59
+
60
+ Create a file named `solid_assert.rb` in the `config/initializers` dir with the following content:
61
+
62
+ ```ruby
63
+ SolidAssert.enable_assertions if !Rails.env.production?
64
+ ```
41
65
 
42
- invariant "Have the lists had different sizes?" do
43
- one_variable = calculate_some_value
44
- other_variable = calculate_some_other_value
45
- one_variable > other_variable
46
- end
66
+ This way assertions will be disabled in production and enabled in the rest of environments
47
67
 
48
68
  ## References
49
69
 
50
- - [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.
51
- - [Writing Solid Code](http://www.amazon.com/Writing-Solid-Code-Microsoft-Programming/dp/1556155514). A great book on good coding design practices. Again, it based in C, but the practices it talks about apply to coding in any programming language.
70
+ - [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 apply to any programming language.
71
+ - There are good references to assertive programming in some classic books like [The Pragmatic Programmer From Journeyman to Master](http://www.amazon.com/exec/obidos/ASIN/020161622X/ref=nosim/jorgmanrpersp-20), [Code Complete](http://www.amazon.com/exec/obidos/ASIN/0735619670/ref=nosim/jorgmanrpersp-20) and [Writing solid code](http://www.amazon.com/exec/obidos/ASIN/1556155514/ref=nosim/jorgmanrpersp-20)
52
72
 
53
73
 
54
74
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.7.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{solid_assert}
8
- s.version = "0.7.2"
8
+ s.version = "0.7.3"
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}]
12
- s.date = %q{2011-09-19}
12
+ s.date = %q{2011-09-20}
13
13
  s.description = %q{Assert utility for ruby. It let you code your assumptions and code invariants, so they are checked automatically. It can be deactivated, so you it doesn't affect to your program performance (for example, in production)'}
14
14
  s.email = %q{jorge.manrubia@gmail.com}
15
15
  s.extra_rdoc_files = [
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: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 2
10
- version: 0.7.2
9
+ - 3
10
+ version: 0.7.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jorge Manrubia
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-19 00:00:00 Z
18
+ date: 2011-09-20 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :development