philiprehberger-test_factory 0.6.0 → 0.7.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 +7 -0
- data/README.md +21 -0
- data/lib/philiprehberger/test_factory/registry.rb +15 -0
- data/lib/philiprehberger/test_factory/version.rb +1 -1
- data/lib/philiprehberger/test_factory.rb +15 -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: bd2d1bcb3612a9f66d4c6e4e8f2a1ae28481405e7c237e2118dc206b0d737f0b
|
|
4
|
+
data.tar.gz: 1118e9019f0e7aecdd41eb8106fd83d3b6f3748c80a6f915a5ffd4abd635ad77
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3bf20a9d96e8ce99d094f3a075109f8b7a8867027a048fc1634b8c5e492142c2fa9493a42b5560109f24c804ae8a2c756cabf7d22f7c9e3cc1b36dac6b829c9d
|
|
7
|
+
data.tar.gz: d8d4b8ab49266bc0a132c3956d9c0a527534a6aca0e3ede110fd3316bd02ed0e484838bcdae022ef777471de521bb1f71800fbf4b6701ad58d32ecc4384a5277
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.7.0] - 2026-04-27
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `TestFactory.factories` — list registered factory names in registration order.
|
|
14
|
+
- `TestFactory.defined?(name)` — predicate for whether a factory is registered.
|
|
15
|
+
- `Registry#factory_names` and `Registry#defined?` — corresponding registry-level inspection methods.
|
|
16
|
+
|
|
10
17
|
## [0.6.0] - 2026-04-23
|
|
11
18
|
|
|
12
19
|
### Added
|
data/README.md
CHANGED
|
@@ -164,6 +164,25 @@ attrs = Philiprehberger::TestFactory.attributes_for(:user, role: :admin)
|
|
|
164
164
|
Philiprehberger::TestFactory.reset!
|
|
165
165
|
```
|
|
166
166
|
|
|
167
|
+
### Registry Inspection
|
|
168
|
+
|
|
169
|
+
Check which factories are registered without poking at internal state. Useful
|
|
170
|
+
in shared spec helpers or library setup that should only register a factory
|
|
171
|
+
when it isn't already defined.
|
|
172
|
+
|
|
173
|
+
```ruby
|
|
174
|
+
Philiprehberger::TestFactory.define(:user) { { name: "Alice" } }
|
|
175
|
+
|
|
176
|
+
Philiprehberger::TestFactory.factories
|
|
177
|
+
# => [:user]
|
|
178
|
+
|
|
179
|
+
Philiprehberger::TestFactory.defined?(:user)
|
|
180
|
+
# => true
|
|
181
|
+
|
|
182
|
+
Philiprehberger::TestFactory.defined?(:post)
|
|
183
|
+
# => false
|
|
184
|
+
```
|
|
185
|
+
|
|
167
186
|
## API
|
|
168
187
|
|
|
169
188
|
| Method | Description |
|
|
@@ -177,6 +196,8 @@ Philiprehberger::TestFactory.reset!
|
|
|
177
196
|
| `TestFactory.build_trio(name, traits:, **overrides)` | Build exactly 3 data hashes |
|
|
178
197
|
| `TestFactory.attributes_for(name, traits:, **overrides)` | Resolve attributes without `after_build` callbacks or associations |
|
|
179
198
|
| `TestFactory.reset!` | Clear all definitions, traits, and sequences |
|
|
199
|
+
| `TestFactory.factories` | List all registered factory names in registration order |
|
|
200
|
+
| `TestFactory.defined?(name)` | Whether a factory has been registered under the given name |
|
|
180
201
|
| `DefinitionProxy#after_build(&block)` | Register a callback that runs after building |
|
|
181
202
|
| `DefinitionProxy#transient(&block)` | Declare transient attributes excluded from the result |
|
|
182
203
|
| `DefinitionProxy#association(name, factory:)` | Declare an association to another factory |
|
|
@@ -86,6 +86,21 @@ module Philiprehberger
|
|
|
86
86
|
@traits = {}
|
|
87
87
|
@sequences = {}
|
|
88
88
|
end
|
|
89
|
+
|
|
90
|
+
# Names of all registered factories in registration order.
|
|
91
|
+
#
|
|
92
|
+
# @return [Array<Symbol>]
|
|
93
|
+
def factory_names
|
|
94
|
+
@factories.keys
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Whether a factory has been registered under the given name.
|
|
98
|
+
#
|
|
99
|
+
# @param name [Symbol] factory name
|
|
100
|
+
# @return [Boolean]
|
|
101
|
+
def defined?(name)
|
|
102
|
+
@factories.key?(name)
|
|
103
|
+
end
|
|
89
104
|
end
|
|
90
105
|
end
|
|
91
106
|
end
|
|
@@ -103,6 +103,21 @@ module Philiprehberger
|
|
|
103
103
|
@builder = nil
|
|
104
104
|
end
|
|
105
105
|
|
|
106
|
+
# Names of all registered factories in registration order.
|
|
107
|
+
#
|
|
108
|
+
# @return [Array<Symbol>]
|
|
109
|
+
def factories
|
|
110
|
+
registry.factory_names
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Whether a factory has been registered under the given name.
|
|
114
|
+
#
|
|
115
|
+
# @param name [Symbol] factory name
|
|
116
|
+
# @return [Boolean]
|
|
117
|
+
def defined?(name)
|
|
118
|
+
registry.defined?(name)
|
|
119
|
+
end
|
|
120
|
+
|
|
106
121
|
private
|
|
107
122
|
|
|
108
123
|
def registry
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-test_factory
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.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-
|
|
11
|
+
date: 2026-04-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Lightweight DSL for building test data objects without ActiveRecord.
|
|
14
14
|
Define factories with default attributes, apply traits for variations, and use thread-safe
|