philiprehberger-assert 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5fea50ef7ac475426e9456b67e82f2be344f3b97fccba75f2e0d1fe944c1ae7
4
- data.tar.gz: 5fd7d6aca18f9c06d4ace4a050483b433f014203252d2cd7a0b8fc4c8fdbf5a4
3
+ metadata.gz: 5ea0634dc2cf5bdb5eeb61e2c7924c082fa9b0528be940055e2fda35d296b061
4
+ data.tar.gz: 72facd36929574b07e387b14939abab408ebd473d9fe01fae380b8df98f76ce7
5
5
  SHA512:
6
- metadata.gz: 8ef0576d1e93ec43284b49a11668e1d3fc8412576ab96919a0fbc997c282c1626be2ba91f0fa6118f6b1f7ef6ca0ec1a467402d79113e476914d667d778355a0
7
- data.tar.gz: 69aa855412b4409cea2b6071ab560919acee192daa546a4b5bbd18cf2d5a7938e3751ebd947a56dbaf0510f9780525e9791058cf970177799c3112ffa6ecfa6f
6
+ metadata.gz: 6c3a46cc415a9b64224aadf69bad12e15133f9144f268505c2995d149eac440a734e89b89237dc94cb77b67e4443e95d12a9d5aa1621c751a2c99d14cbe552a7
7
+ data.tar.gz: 873d5cef9568cac111fb347346c64af94ef685049ad3a893693d475a5615a06d279817519dac054344195eeb4c139048e507cd732733d842eaa602d0dd1ba873
data/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ 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
+
15
+ ## [0.5.0] - 2026-04-29
16
+
17
+ ### Added
18
+ - `Assert.postcondition(condition, message)` for Design by Contract postcondition checks, complementing the existing `precondition`
19
+
10
20
  ## [0.4.0] - 2026-04-15
11
21
 
12
22
  ### Added
data/README.md CHANGED
@@ -92,13 +92,36 @@ end
92
92
  Philiprehberger::Assert.precondition(user.active?, 'user must be active')
93
93
  ```
94
94
 
95
+ ### Postconditions (Design by Contract)
96
+
97
+ ```ruby
98
+ def withdraw(amount)
99
+ Philiprehberger::Assert.precondition(amount.positive?, 'amount must be positive')
100
+ result = perform_withdrawal(amount)
101
+ Philiprehberger::Assert.postcondition(result.balance >= 0, 'balance must not go negative')
102
+ result
103
+ end
104
+ ```
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
+
95
116
  ## API
96
117
 
97
118
  | Method | Description |
98
119
  |--------|-------------|
99
120
  | `Assert.that(value, message = nil)` | Start a chainable assertion |
100
121
  | `Assert.soft { \|a\| ... }` | Collect failures, raise at end |
101
- | `Assert.precondition(condition, message)` | Design by Contract check |
122
+ | `Assert.precondition(condition, message)` | Design by Contract precondition check |
123
+ | `Assert.postcondition(condition, message)` | Design by Contract postcondition check |
124
+ | `Assert.invariant(condition, message)` | Design by Contract class-invariant check |
102
125
  | `Assertion#is_a(type)` | Assert value is an instance of type |
103
126
  | `Assertion#gte(num)` | Assert value >= num |
104
127
  | `Assertion#lte(num)` | Assert value <= num |
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module Assert
5
- VERSION = '0.4.0'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
@@ -33,5 +33,23 @@ module Philiprehberger
33
33
  def self.precondition(condition, message)
34
34
  raise AssertionError, message unless condition
35
35
  end
36
+
37
+ # Design by Contract postcondition check.
38
+ #
39
+ # @param condition [Boolean] the condition to verify
40
+ # @param message [String] failure message
41
+ # @raise [AssertionError] if condition is false
42
+ def self.postcondition(condition, message)
43
+ raise AssertionError, message unless condition
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
36
54
  end
37
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.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-04-15 00:00:00.000000000 Z
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.