philiprehberger-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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +11 -0
- data/lib/philiprehberger/assert/version.rb +1 -1
- data/lib/philiprehberger/assert.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5ea0634dc2cf5bdb5eeb61e2c7924c082fa9b0528be940055e2fda35d296b061
|
|
4
|
+
data.tar.gz: 72facd36929574b07e387b14939abab408ebd473d9fe01fae380b8df98f76ce7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6c3a46cc415a9b64224aadf69bad12e15133f9144f268505c2995d149eac440a734e89b89237dc94cb77b67e4443e95d12a9d5aa1621c751a2c99d14cbe552a7
|
|
7
|
+
data.tar.gz: 873d5cef9568cac111fb347346c64af94ef685049ad3a893693d475a5615a06d279817519dac054344195eeb4c139048e507cd732733d842eaa602d0dd1ba873
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.6.0] - 2026-05-02
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Assert.invariant(condition, message)` for Design by Contract class-invariant checks, completing the pre/post/invariant trio
|
|
14
|
+
|
|
10
15
|
## [0.5.0] - 2026-04-29
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -103,6 +103,16 @@ def withdraw(amount)
|
|
|
103
103
|
end
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
+
### Invariant (Design by Contract)
|
|
107
|
+
|
|
108
|
+
```ruby
|
|
109
|
+
def transfer(from, to, amount)
|
|
110
|
+
before = from.balance + to.balance
|
|
111
|
+
perform_transfer(from, to, amount)
|
|
112
|
+
Philiprehberger::Assert.invariant(from.balance + to.balance == before, 'total balance must be conserved')
|
|
113
|
+
end
|
|
114
|
+
```
|
|
115
|
+
|
|
106
116
|
## API
|
|
107
117
|
|
|
108
118
|
| Method | Description |
|
|
@@ -111,6 +121,7 @@ end
|
|
|
111
121
|
| `Assert.soft { \|a\| ... }` | Collect failures, raise at end |
|
|
112
122
|
| `Assert.precondition(condition, message)` | Design by Contract precondition check |
|
|
113
123
|
| `Assert.postcondition(condition, message)` | Design by Contract postcondition check |
|
|
124
|
+
| `Assert.invariant(condition, message)` | Design by Contract class-invariant check |
|
|
114
125
|
| `Assertion#is_a(type)` | Assert value is an instance of type |
|
|
115
126
|
| `Assertion#gte(num)` | Assert value >= num |
|
|
116
127
|
| `Assertion#lte(num)` | Assert value <= num |
|
|
@@ -42,5 +42,14 @@ module Philiprehberger
|
|
|
42
42
|
def self.postcondition(condition, message)
|
|
43
43
|
raise AssertionError, message unless condition
|
|
44
44
|
end
|
|
45
|
+
|
|
46
|
+
# Design by Contract invariant check.
|
|
47
|
+
#
|
|
48
|
+
# @param condition [Boolean] the condition to verify
|
|
49
|
+
# @param message [String] failure message
|
|
50
|
+
# @raise [AssertionError] if condition is false
|
|
51
|
+
def self.invariant(condition, message)
|
|
52
|
+
raise AssertionError, message unless condition
|
|
53
|
+
end
|
|
45
54
|
end
|
|
46
55
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-assert
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-05-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A lightweight runtime assertion library for Ruby with chainable matchers,
|
|
14
14
|
soft assertions, and Design by Contract preconditions.
|