conditionz 0.0.7 → 0.0.8
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.
- checksums.yaml +8 -8
- data/.gitignore +25 -0
- data/Gemfile.lock +24 -0
- data/LICENSE +21 -0
- data/README.md +103 -0
- data/Rakefile +1 -0
- data/conditionz.gemspec +21 -0
- data/gemfile +3 -0
- data/lib/conditionz.rb +5 -1
- data/lib/conditionz/assert.rb +25 -0
- data/lib/conditionz/assertion_error.rb +13 -0
- data/lib/conditionz/condition_base.rb +31 -0
- data/lib/conditionz/post_condition.rb +25 -0
- data/lib/conditionz/post_condition_not_met_error.rb +13 -0
- data/lib/conditionz/pre_condition.rb +25 -0
- data/lib/conditionz/pre_condition_not_met_error.rb +11 -0
- data/lib/version.rb +3 -0
- data/spec/lib/assert_spec.rb +22 -0
- data/spec/lib/assertion_error_spec.rb +11 -0
- data/spec/lib/condition_base_spec.rb +93 -0
- data/spec/lib/post_condition_not_met_error_spec.rb +11 -0
- data/spec/lib/post_condition_spec.rb +22 -0
- data/spec/lib/pre_condition_not_met_error_spec.rb +11 -0
- data/spec/lib/pre_condition_spec.rb +22 -0
- metadata +60 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Y2VlM2U1MzljNzAzMDQxYmUxZjY0Nzg0YWY5ZTc5ZGJiYzYxM2VhNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzM2MzRlOTk1YmM4Mzg1NGE2ZTEzMTU3ZWQzNjE3Zjk4YzQzZGU1ZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTk2MjRiZTUzMjEwZjA4ZjliY2I5NzBjMTQxOTUwN2RiZGFjYmYwZWVjMzgy
|
10
|
+
MjdkOWY5MGQ4ZmJlNGQ5YTg4MDJiNDZiOTA2MTBhNWE2Zjg0OTNiZjkzZDNi
|
11
|
+
MzJlMzVkNDRiZTQ2ODMwMzdhMTFlMmExOWJkY2VkOTk3ZTEwNmI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZGFjMmU1Zjg3N2ExMjFhNDAyMmI4NTBjMGU4MTI3NmIyZDMwMDk2YmE2MjY0
|
14
|
+
ODFhNDBmZmI0N2Y4OTZkNDQyNDA0YjBhNzZiOTA1OTA0NTI3YzgzMjY3YmQ5
|
15
|
+
OWMwYTk5ODMyODI1MjJhODE0NTkyZmVmOTMxNDlhMTJmNDU1NjM=
|
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
*.rbc
|
2
|
+
capybara-*.html
|
3
|
+
.rspec
|
4
|
+
/log
|
5
|
+
/tmp
|
6
|
+
/db/*.sqlite3
|
7
|
+
/public/system
|
8
|
+
/coverage/
|
9
|
+
/spec/tmp
|
10
|
+
/pkg
|
11
|
+
**.orig
|
12
|
+
rerun.txt
|
13
|
+
pickle-email-*.html
|
14
|
+
config/initializers/secret_token.rb
|
15
|
+
config/secrets.yml
|
16
|
+
|
17
|
+
## Environment normalisation:
|
18
|
+
/.bundle
|
19
|
+
/vendor/bundle
|
20
|
+
|
21
|
+
# these should all be checked in to normalise the environment:
|
22
|
+
# Gemfile.lock, .ruby-version, .ruby-gemset
|
23
|
+
|
24
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
25
|
+
.rvmrc
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
conditionz (0.0.7)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.4)
|
10
|
+
rspec (2.13.0)
|
11
|
+
rspec-core (~> 2.13.0)
|
12
|
+
rspec-expectations (~> 2.13.0)
|
13
|
+
rspec-mocks (~> 2.13.0)
|
14
|
+
rspec-core (2.13.1)
|
15
|
+
rspec-expectations (2.13.0)
|
16
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
17
|
+
rspec-mocks (2.13.1)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
conditionz!
|
24
|
+
rspec (~> 2.6)
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 yaniv preiss
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
conditionz
|
2
|
+
===================
|
3
|
+
|
4
|
+
# Description
|
5
|
+
|
6
|
+
Semantic Design-By-Contract pre-conditions and post-conditions.
|
7
|
+
|
8
|
+
The purpose is to raise an error when a certain condition or more are not met.
|
9
|
+
|
10
|
+
See
|
11
|
+
|
12
|
+
http://en.wikipedia.org/wiki/Design_by_contract
|
13
|
+
|
14
|
+
http://en.wikipedia.org/wiki/Precondition
|
15
|
+
|
16
|
+
http://en.wikipedia.org/wiki/Postcondition
|
17
|
+
|
18
|
+
|
19
|
+
# Installation
|
20
|
+
|
21
|
+
Add to your Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'conditionz'
|
25
|
+
```
|
26
|
+
|
27
|
+
Then run:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
bundle install
|
31
|
+
```
|
32
|
+
|
33
|
+
# Usage
|
34
|
+
|
35
|
+
Suppose you have the following class:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class MyTime
|
39
|
+
attr_accessor :hour, :minute
|
40
|
+
|
41
|
+
def initialize(new_hour, new_minute)
|
42
|
+
hour = new_hour
|
43
|
+
minute = new_minute
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
Now you wish that initialize method parameters are within a certain range.
|
49
|
+
Include the pre condition, and add the precondition
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
include Conditionz
|
53
|
+
|
54
|
+
class MyTime
|
55
|
+
attr_accessor :hour, :minute
|
56
|
+
|
57
|
+
def initialize(new_hour, new_minute)
|
58
|
+
Precondition.require 0 <= new_hour && new_hour <= 23, "Hour must be between 0 and 23"
|
59
|
+
Precondition.require 0 <= new_minute && new_minute <= 59, "Minute must be between 0 and 59"
|
60
|
+
|
61
|
+
hour = new_hour
|
62
|
+
minute = new_minute
|
63
|
+
end
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
Notice the call to ```Precondition.require```, which receives a predicate (a boolean expression),
|
68
|
+
and an optional message ```string``` or ```proc```.
|
69
|
+
|
70
|
+
Here's an example with proc:
|
71
|
+
```ruby
|
72
|
+
Precondition.require 0 <= new_hour && new_hour <= 23, Proc.new { "Hour must be between 0 and 23 but got #{new_hour}" }
|
73
|
+
```
|
74
|
+
|
75
|
+
Analogously, you can ensure post conditions:
|
76
|
+
(In this example, instead of ```include```, the fully qualified name is used
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
class MyQueue
|
80
|
+
attr_accessor :size
|
81
|
+
|
82
|
+
def push(item)
|
83
|
+
# some implementation of pushing to queue...
|
84
|
+
|
85
|
+
Conditionz::PostCondition.ensure size > 0
|
86
|
+
end
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
|
91
|
+
Not directly related, and preferably unit tested, but could be useful - assert a predicate
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
def foo
|
95
|
+
first_result = first_calculation()
|
96
|
+
Assert.that first_result > 0, "result should have been positive"
|
97
|
+
second_result = sqrt first_result
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
# License
|
102
|
+
|
103
|
+
see MIT-LICENSE
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/conditionz.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'conditionz'
|
7
|
+
s.version = Conditionz::VERSION
|
8
|
+
s.date = '2014-04-01'
|
9
|
+
s.summary = "Semantic 'Design-By-Contract pre and post conditions'"
|
10
|
+
s.description = "Assert pre-conditions and post-conditions inside methods"
|
11
|
+
s.authors = ["Yaniv Preiss"]
|
12
|
+
s.email = 'yanivpr@gmail.com'
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = s.files.grep(%r{^(spec)/})
|
15
|
+
s.homepage = 'https://github.com/yanivpr/conditionz'
|
16
|
+
s.license = 'MIT'
|
17
|
+
|
18
|
+
s.add_development_dependency "rspec", "~> 2.6"
|
19
|
+
s.add_development_dependency "bundler", "~> 1.4"
|
20
|
+
s.add_development_dependency "rake"
|
21
|
+
end
|
data/gemfile
ADDED
data/lib/conditionz.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
require 'version'
|
1
2
|
require 'conditionz/condition_base'
|
2
3
|
require 'conditionz/pre_condition'
|
3
4
|
require 'conditionz/post_condition'
|
4
5
|
require 'conditionz/assert'
|
5
6
|
require 'conditionz/pre_condition_not_met_error'
|
6
7
|
require 'conditionz/post_condition_not_met_error'
|
7
|
-
require 'conditionz/assertion_error'
|
8
|
+
require 'conditionz/assertion_error'
|
9
|
+
|
10
|
+
module Conditionz
|
11
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'condition_base'
|
2
|
+
|
3
|
+
module Conditionz
|
4
|
+
|
5
|
+
# Raise assertion error when +predicate+ is false
|
6
|
+
class Assert
|
7
|
+
|
8
|
+
# Raise assertion error if predicate is false. Otherwise do nothing
|
9
|
+
#
|
10
|
+
# ==== Attributes
|
11
|
+
#
|
12
|
+
# * +predicate+ - a boolean expression to eval
|
13
|
+
# * +message+ - Error message to raise
|
14
|
+
#
|
15
|
+
# ==== Examples
|
16
|
+
#
|
17
|
+
# Assert.that age > 0, "Age should have been positive"
|
18
|
+
# Assert.that age > 0
|
19
|
+
#
|
20
|
+
def self.that predicate, message = 'Assertion failed'
|
21
|
+
ConditionBase.verify predicate, AssertionError, message
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'pre_condition_not_met_error'
|
2
|
+
require_relative 'post_condition_not_met_error'
|
3
|
+
|
4
|
+
module Conditionz
|
5
|
+
|
6
|
+
# Raise error when +predicate+ is false
|
7
|
+
class ConditionBase
|
8
|
+
|
9
|
+
# Raise error if predicate is false. Otherwise do nothing
|
10
|
+
#
|
11
|
+
# ==== Attributes
|
12
|
+
#
|
13
|
+
# * +predicate+ - a boolean expression to eval
|
14
|
+
# * +error_class+ - Class of the error to raise
|
15
|
+
# * +message+ - Error message to raise
|
16
|
+
#
|
17
|
+
# ==== Examples
|
18
|
+
#
|
19
|
+
# ConditionBase.verify age > 0, Conditionz::PreCondition, "Age must be positive"
|
20
|
+
# ConditionBase.verify age > 0, Conditionz::PreCondition
|
21
|
+
#
|
22
|
+
def self.verify predicate, error_class, message = 'Condition not met'
|
23
|
+
return if predicate
|
24
|
+
|
25
|
+
error_message = message.is_a?(String) ? message : message.call
|
26
|
+
raise error_class, error_message
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'condition_base'
|
2
|
+
|
3
|
+
module Conditionz
|
4
|
+
|
5
|
+
# Raise postcondition error when +predicate+ is false
|
6
|
+
class PostCondition
|
7
|
+
|
8
|
+
# Raise postcondition error if predicate is false. Otherwise do nothing
|
9
|
+
#
|
10
|
+
# ==== Attributes
|
11
|
+
#
|
12
|
+
# * +predicate+ - a boolean expression to eval
|
13
|
+
# * +message+ - Error message to raise
|
14
|
+
#
|
15
|
+
# ==== Examples
|
16
|
+
#
|
17
|
+
# PostCondition.ensure age > 0, "Age should have been positive"
|
18
|
+
# PostCondition.ensure age > 0
|
19
|
+
#
|
20
|
+
def self.ensure predicate, message = 'Postcondition not met'
|
21
|
+
ConditionBase.verify predicate, PostConditionNotMetError, message
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'condition_base'
|
2
|
+
|
3
|
+
module Conditionz
|
4
|
+
|
5
|
+
# Raise precondition error when +predicate+ is false
|
6
|
+
class PreCondition
|
7
|
+
|
8
|
+
# Raise precondition error if predicate is false. Otherwise do nothing
|
9
|
+
#
|
10
|
+
# ==== Attributes
|
11
|
+
#
|
12
|
+
# * +predicate+ - a boolean expression to eval
|
13
|
+
# * +message+ - Error message to raise
|
14
|
+
#
|
15
|
+
# ==== Examples
|
16
|
+
#
|
17
|
+
# PreCondition.require age > 0, "Age must be positive"
|
18
|
+
# PreCondition.require age > 0
|
19
|
+
#
|
20
|
+
def self.require predicate, message = 'Precondition not met'
|
21
|
+
ConditionBase.verify predicate, PreConditionNotMetError, message
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'conditionz/assert'
|
2
|
+
|
3
|
+
describe Conditionz::Assert do
|
4
|
+
|
5
|
+
let(:predicate) { true } #doesn't matter for these tests
|
6
|
+
|
7
|
+
it "should call the condition base with assert error and message" do
|
8
|
+
message = "some message"
|
9
|
+
Conditionz::ConditionBase.should_receive(:verify).
|
10
|
+
with(predicate, Conditionz::AssertionError, message)
|
11
|
+
|
12
|
+
Conditionz::Assert.that predicate, message
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should call the condition base with assert error and message_proc" do
|
16
|
+
message_proc = Proc.new { "some message" }
|
17
|
+
Conditionz::ConditionBase.should_receive(:verify).
|
18
|
+
with(predicate, Conditionz::AssertionError, message_proc)
|
19
|
+
|
20
|
+
Conditionz::Assert.that predicate, message_proc
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'conditionz/condition_base'
|
2
|
+
|
3
|
+
describe Conditionz::ConditionBase do
|
4
|
+
|
5
|
+
context "predicate is true" do
|
6
|
+
let(:true_predicate) { true }
|
7
|
+
|
8
|
+
it "should not raise precondition error" do
|
9
|
+
message = "custom pre condition message"
|
10
|
+
|
11
|
+
expect {
|
12
|
+
Conditionz::ConditionBase.verify true_predicate,
|
13
|
+
Conditionz::PreConditionNotMetError,
|
14
|
+
message
|
15
|
+
}.not_to raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should not raise postcondition error" do
|
19
|
+
message = "custom post condition message"
|
20
|
+
|
21
|
+
expect {
|
22
|
+
Conditionz::ConditionBase.verify true_predicate,
|
23
|
+
Conditionz::PostConditionNotMetError,
|
24
|
+
message
|
25
|
+
}.to_not raise_error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "predicate is false" do
|
30
|
+
let(:false_predicate) { false }
|
31
|
+
|
32
|
+
context "precondition" do
|
33
|
+
it "should raise error with given message" do
|
34
|
+
message = "custom pre condition message"
|
35
|
+
|
36
|
+
expect {
|
37
|
+
Conditionz::ConditionBase.verify false_predicate,
|
38
|
+
Conditionz::PreConditionNotMetError,
|
39
|
+
message
|
40
|
+
}.to raise_error Conditionz::PreConditionNotMetError, message
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should raise error with given message proc" do
|
44
|
+
message = "custom pre condition message"
|
45
|
+
message_proc = Proc.new { message }
|
46
|
+
|
47
|
+
expect {
|
48
|
+
Conditionz::ConditionBase.verify false_predicate,
|
49
|
+
Conditionz::PreConditionNotMetError,
|
50
|
+
message_proc
|
51
|
+
}.to raise_error Conditionz::PreConditionNotMetError, message
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should raise error with default message" do
|
55
|
+
expect {
|
56
|
+
Conditionz::ConditionBase.verify false_predicate,
|
57
|
+
Conditionz::PreConditionNotMetError
|
58
|
+
}.to raise_error Conditionz::PreConditionNotMetError, 'Condition not met'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "postcondition" do
|
63
|
+
it "should raise error with given message" do
|
64
|
+
message = "custom post condition message"
|
65
|
+
|
66
|
+
expect {
|
67
|
+
Conditionz::ConditionBase.verify false_predicate,
|
68
|
+
Conditionz::PostConditionNotMetError,
|
69
|
+
message
|
70
|
+
}.to raise_error Conditionz::PostConditionNotMetError, message
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should raise error with given message proc" do
|
74
|
+
message = "custom post condition message"
|
75
|
+
message_proc = Proc.new { message }
|
76
|
+
|
77
|
+
expect {
|
78
|
+
Conditionz::ConditionBase.verify false_predicate,
|
79
|
+
Conditionz::PostConditionNotMetError,
|
80
|
+
message_proc
|
81
|
+
}.to raise_error Conditionz::PostConditionNotMetError, message
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should raise error with default message" do
|
85
|
+
expect {
|
86
|
+
Conditionz::ConditionBase.verify false_predicate,
|
87
|
+
Conditionz::PostConditionNotMetError
|
88
|
+
}.to raise_error Conditionz::PostConditionNotMetError, 'Condition not met'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'conditionz/post_condition_not_met_error'
|
2
|
+
|
3
|
+
describe Conditionz::PostConditionNotMetError do
|
4
|
+
|
5
|
+
it "should have correct message" do
|
6
|
+
message = "some message"
|
7
|
+
error = Conditionz::PostConditionNotMetError.new(message)
|
8
|
+
|
9
|
+
error.message.should == message
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'conditionz/post_condition'
|
2
|
+
|
3
|
+
describe Conditionz::PostCondition do
|
4
|
+
|
5
|
+
let(:predicate) { true } #doesn't matter for these tests
|
6
|
+
|
7
|
+
it "should call the condition base with pre condition error and message" do
|
8
|
+
message = "some message"
|
9
|
+
Conditionz::ConditionBase.should_receive(:verify).
|
10
|
+
with(predicate, Conditionz::PostConditionNotMetError, message)
|
11
|
+
|
12
|
+
Conditionz::PostCondition.ensure predicate, message
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should call the condition base with pre condition error and message_proc" do
|
16
|
+
message_proc = Proc.new { "some message" }
|
17
|
+
Conditionz::ConditionBase.should_receive(:verify).
|
18
|
+
with(predicate, Conditionz::PostConditionNotMetError, message_proc)
|
19
|
+
|
20
|
+
Conditionz::PostCondition.ensure predicate, message_proc
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'conditionz/pre_condition_not_met_error'
|
2
|
+
|
3
|
+
describe Conditionz::PreConditionNotMetError do
|
4
|
+
|
5
|
+
it "should have correct message" do
|
6
|
+
message = "some message"
|
7
|
+
error = Conditionz::PreConditionNotMetError.new(message)
|
8
|
+
|
9
|
+
error.message.should == message
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'conditionz/pre_condition'
|
2
|
+
|
3
|
+
describe Conditionz::PreCondition do
|
4
|
+
|
5
|
+
let(:predicate) { true } #doesn't matter for these tests
|
6
|
+
|
7
|
+
it "should call the condition base with pre condition error and message" do
|
8
|
+
message = "some message"
|
9
|
+
Conditionz::ConditionBase.should_receive(:verify).
|
10
|
+
with(predicate, Conditionz::PreConditionNotMetError, message)
|
11
|
+
|
12
|
+
Conditionz::PreCondition.require predicate, message
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should call the condition base with pre condition error and message_proc" do
|
16
|
+
message_proc = Proc.new { "some message" }
|
17
|
+
Conditionz::ConditionBase.should_receive(:verify).
|
18
|
+
with(predicate, Conditionz::PreConditionNotMetError, message_proc)
|
19
|
+
|
20
|
+
Conditionz::PreCondition.require predicate, message_proc
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conditionz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaniv Preiss
|
@@ -24,14 +24,64 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
description: Assert pre-conditions and post-conditions inside methods
|
28
56
|
email: yanivpr@gmail.com
|
29
57
|
executables: []
|
30
58
|
extensions: []
|
31
59
|
extra_rdoc_files: []
|
32
60
|
files:
|
61
|
+
- .gitignore
|
62
|
+
- Gemfile.lock
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- conditionz.gemspec
|
67
|
+
- gemfile
|
33
68
|
- lib/conditionz.rb
|
34
|
-
|
69
|
+
- lib/conditionz/assert.rb
|
70
|
+
- lib/conditionz/assertion_error.rb
|
71
|
+
- lib/conditionz/condition_base.rb
|
72
|
+
- lib/conditionz/post_condition.rb
|
73
|
+
- lib/conditionz/post_condition_not_met_error.rb
|
74
|
+
- lib/conditionz/pre_condition.rb
|
75
|
+
- lib/conditionz/pre_condition_not_met_error.rb
|
76
|
+
- lib/version.rb
|
77
|
+
- spec/lib/assert_spec.rb
|
78
|
+
- spec/lib/assertion_error_spec.rb
|
79
|
+
- spec/lib/condition_base_spec.rb
|
80
|
+
- spec/lib/post_condition_not_met_error_spec.rb
|
81
|
+
- spec/lib/post_condition_spec.rb
|
82
|
+
- spec/lib/pre_condition_not_met_error_spec.rb
|
83
|
+
- spec/lib/pre_condition_spec.rb
|
84
|
+
homepage: https://github.com/yanivpr/conditionz
|
35
85
|
licenses:
|
36
86
|
- MIT
|
37
87
|
metadata: {}
|
@@ -55,4 +105,11 @@ rubygems_version: 2.2.2
|
|
55
105
|
signing_key:
|
56
106
|
specification_version: 4
|
57
107
|
summary: Semantic 'Design-By-Contract pre and post conditions'
|
58
|
-
test_files:
|
108
|
+
test_files:
|
109
|
+
- spec/lib/assert_spec.rb
|
110
|
+
- spec/lib/assertion_error_spec.rb
|
111
|
+
- spec/lib/condition_base_spec.rb
|
112
|
+
- spec/lib/post_condition_not_met_error_spec.rb
|
113
|
+
- spec/lib/post_condition_spec.rb
|
114
|
+
- spec/lib/pre_condition_not_met_error_spec.rb
|
115
|
+
- spec/lib/pre_condition_spec.rb
|