solid_assert 0.7.0 → 0.7.1
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 +6 -6
- data/VERSION +1 -1
- data/solid_assert.gemspec +1 -1
- data/spec/solid_assert/assert_spec.rb +6 -6
- data/spec/solid_assert/solid_assert_spec.rb +9 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
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
|
+
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
|
-
- If
|
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
9
|
- At this point, this list should contain one entry for all the keys 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
|
|
13
|
-
Assertions
|
13
|
+
Assertions are typically used in development mode. You might want to disable them in production for performance reasons.
|
14
14
|
|
15
15
|
# Installation
|
16
16
|
|
@@ -29,7 +29,7 @@ Assertions are disabled by default.
|
|
29
29
|
Use `assert` for testing conditions. You can optionally provide a message
|
30
30
|
|
31
31
|
assert some_string != "some value"
|
32
|
-
assert
|
32
|
+
assert clients_list.empty?, "Isn't the clients list empty?"
|
33
33
|
|
34
34
|
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
35
|
|
@@ -48,7 +48,7 @@ Use `invariant` for testing blocks of code. This comes handy when testing your a
|
|
48
48
|
## References
|
49
49
|
|
50
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
|
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.
|
52
52
|
|
53
53
|
|
54
54
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.1
|
data/solid_assert.gemspec
CHANGED
@@ -6,29 +6,29 @@ describe SolidAssert::Assert do
|
|
6
6
|
describe "#assert" do
|
7
7
|
describe "without assertion message" do
|
8
8
|
it "should fail when condition is false" do
|
9
|
-
|
9
|
+
expect { assert false }.to raise_error SolidAssert::AssertionFailedError
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should fail when condition evaluates to false" do
|
13
|
-
|
13
|
+
expect { assert nil }.to raise_error SolidAssert::AssertionFailedError
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should not fail when condition is true" do
|
17
|
-
|
17
|
+
expect { assert true }.to_not raise_error SolidAssert::AssertionFailedError
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should not fail when condition evaluates to true" do
|
21
|
-
|
21
|
+
expect { assert "This evaluates to true" }.to_not raise_error SolidAssert::AssertionFailedError
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "with assertion message" do
|
26
26
|
it "should raise error with specified message when condition evaluates to false" do
|
27
|
-
|
27
|
+
expect { assert nil, "The error message" }.to raise_error(SolidAssert::AssertionFailedError, "The error message")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should not raise any error when condition doesn't evaluate to false'" do
|
31
|
-
|
31
|
+
expect { assert 'This evaluates to true', "The error message" }.to_not raise_error(SolidAssert::AssertionFailedError)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -1,6 +1,14 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe SolidAssert::Assert do
|
4
|
+
it "should enable the empty assert method by default" do
|
5
|
+
assert false
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should enable the empty invariant method by default" do
|
9
|
+
invariant{false}
|
10
|
+
end
|
11
|
+
|
4
12
|
describe ".enable_assertions" do
|
5
13
|
it "should make the Object class to include the Assertions module" do
|
6
14
|
Object.should_receive(:include).with(SolidAssert::Assert)
|
@@ -9,7 +17,7 @@ describe SolidAssert::Assert do
|
|
9
17
|
|
10
18
|
it "should turn on the assertions" do
|
11
19
|
SolidAssert.enable_assertions
|
12
|
-
|
20
|
+
expect {assert false}.to raise_error(SolidAssert::AssertionFailedError)
|
13
21
|
end
|
14
22
|
end
|
15
23
|
|
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: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 1
|
10
|
+
version: 0.7.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jorge Manrubia
|