spec_forge 0.1.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 +7 -0
- data/.envrc +1 -0
- data/.rspec +1 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +426 -0
- data/Rakefile +6 -0
- data/bin/spec_forge +5 -0
- data/flake.lock +61 -0
- data/flake.nix +41 -0
- data/lib/spec_forge/attribute/chainable.rb +86 -0
- data/lib/spec_forge/attribute/factory.rb +63 -0
- data/lib/spec_forge/attribute/faker.rb +54 -0
- data/lib/spec_forge/attribute/literal.rb +27 -0
- data/lib/spec_forge/attribute/matcher.rb +118 -0
- data/lib/spec_forge/attribute/parameterized.rb +76 -0
- data/lib/spec_forge/attribute/resolvable.rb +21 -0
- data/lib/spec_forge/attribute/resolvable_array.rb +24 -0
- data/lib/spec_forge/attribute/resolvable_hash.rb +24 -0
- data/lib/spec_forge/attribute/transform.rb +39 -0
- data/lib/spec_forge/attribute/variable.rb +36 -0
- data/lib/spec_forge/attribute.rb +208 -0
- data/lib/spec_forge/cli/actions.rb +23 -0
- data/lib/spec_forge/cli/command.rb +127 -0
- data/lib/spec_forge/cli/init.rb +29 -0
- data/lib/spec_forge/cli/new.rb +161 -0
- data/lib/spec_forge/cli/run.rb +17 -0
- data/lib/spec_forge/cli.rb +43 -0
- data/lib/spec_forge/config.rb +84 -0
- data/lib/spec_forge/environment.rb +71 -0
- data/lib/spec_forge/error.rb +150 -0
- data/lib/spec_forge/factory.rb +104 -0
- data/lib/spec_forge/http/backend.rb +106 -0
- data/lib/spec_forge/http/client.rb +33 -0
- data/lib/spec_forge/http/request.rb +93 -0
- data/lib/spec_forge/http/verb.rb +118 -0
- data/lib/spec_forge/http.rb +6 -0
- data/lib/spec_forge/normalizer/config.rb +104 -0
- data/lib/spec_forge/normalizer/constraint.rb +47 -0
- data/lib/spec_forge/normalizer/expectation.rb +85 -0
- data/lib/spec_forge/normalizer/factory.rb +65 -0
- data/lib/spec_forge/normalizer/factory_reference.rb +66 -0
- data/lib/spec_forge/normalizer/spec.rb +73 -0
- data/lib/spec_forge/normalizer.rb +183 -0
- data/lib/spec_forge/runner.rb +91 -0
- data/lib/spec_forge/spec/expectation/constraint.rb +52 -0
- data/lib/spec_forge/spec/expectation.rb +53 -0
- data/lib/spec_forge/spec.rb +77 -0
- data/lib/spec_forge/type.rb +45 -0
- data/lib/spec_forge/version.rb +5 -0
- data/lib/spec_forge.rb +90 -0
- data/lib/templates/config.tt +19 -0
- data/spec_forge/config.yml +19 -0
- data/spec_forge/factories/user.yml +4 -0
- data/spec_forge/specs/users.yml +63 -0
- metadata +234 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 588d2718c1fbacbfd1505a216f4b324c1ba83f12363a740f09cbd0f494595caa
|
4
|
+
data.tar.gz: 54dc440972584290ec208b60d0c22a0ebedb8c186fd90479b688f451281a7db0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d6e2030a3d788df3ca19c3193f37d78cc0a7b0b6f641ac5e07ec15c5386807b231eb5bb052265b12389e0cc5c95ca950a7703889ae1bfe3441bc13793a45495b
|
7
|
+
data.tar.gz: '0581cfbf2db39d3a30b2698e22e9f74c65229004269c49efb656e4cc169473273ddaf366250447ea9d9633d4007eb379bbce65bc4f3d5920cd63fa62bfb20c9a'
|
data/.envrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
use flake
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Bryan
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,426 @@
|
|
1
|
+
# SpecForge
|
2
|
+
|
3
|
+
**Please note: This gem is under active development and isn't quite ready for use**
|
4
|
+
|
5
|
+
I have 98% of the first release done, but I still have a lot of testing and polishing to ensure it works as expected.
|
6
|
+
|
7
|
+
---
|
8
|
+
|
9
|
+
Write API tests in YAML that read like documentation:
|
10
|
+
|
11
|
+
```yaml
|
12
|
+
user_profile:
|
13
|
+
path: /users/1
|
14
|
+
expect:
|
15
|
+
status: 200
|
16
|
+
json:
|
17
|
+
name: kind_of.string
|
18
|
+
email: /@/
|
19
|
+
```
|
20
|
+
|
21
|
+
That's a complete test. No Ruby code, no configuration files, no HTTP client setup - just a clear description of what you're testing. Under the hood, you get all the power of RSpec's matchers, Faker's data generation, and FactoryBot's test objects.
|
22
|
+
|
23
|
+
But that's just scratching the surface.
|
24
|
+
|
25
|
+
## Table of Contents
|
26
|
+
|
27
|
+
- [Features](#features)
|
28
|
+
- [Compatibility](#compatibility)
|
29
|
+
- [Installation](#installation)
|
30
|
+
- [Getting Started](#getting-started)
|
31
|
+
- [Writing Your First Test](#writing-your-first-test)
|
32
|
+
- [Configuration](#configuration)
|
33
|
+
- [Base URL](#base-url)
|
34
|
+
- [Authorization](#authorization)
|
35
|
+
- [The Spec Structure](#the-spec-structure)
|
36
|
+
- [Basic Structure](#basic-structure)
|
37
|
+
- [Testing Response Data](#testing-response-data)
|
38
|
+
- [Multiple Expectations](#multiple-expectations)
|
39
|
+
- [Request Data](#request-data)
|
40
|
+
- [Dynamic Features](#dynamic-features)
|
41
|
+
- [Variables](#variables)
|
42
|
+
- [Transformations](#transformations)
|
43
|
+
- [Factory Integration](#factory-integration)
|
44
|
+
- [RSpec Matchers](#rspec-matchers)
|
45
|
+
- ["be" namespace](#be-namespace)
|
46
|
+
- ["kind_of" namespace](#kind_of-namespace)
|
47
|
+
- ["matchers" namespace](#matchers-namespace)
|
48
|
+
- [Roadmap](#roadmap)
|
49
|
+
- [Contributing](#contributing)
|
50
|
+
- [License](#license)
|
51
|
+
- [Looking for a Software Engineer?](#looking-for-a-software-engineer)
|
52
|
+
|
53
|
+
## Features
|
54
|
+
|
55
|
+
- **Write Tests in YAML**: Create clear, maintainable API tests using a declarative YAML syntax
|
56
|
+
- **RSpec Integration**: Harness RSpec's powerful matcher system and reporting through an intuitive interface
|
57
|
+
- **Dynamic Test Data**: Generate realistic test data using Faker, transformations, and a flexible variable system
|
58
|
+
- **Factory Integration**: Seamless integration with FactoryBot for test data generation
|
59
|
+
|
60
|
+
## Compatibility
|
61
|
+
|
62
|
+
Currently tested on:
|
63
|
+
- MRI Ruby 3.0+
|
64
|
+
- NixOS (see `flake.nix` for details)
|
65
|
+
|
66
|
+
## Installation
|
67
|
+
|
68
|
+
Add this line to your application's Gemfile:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
gem "spec_forge"
|
72
|
+
```
|
73
|
+
|
74
|
+
And then execute:
|
75
|
+
|
76
|
+
```bash
|
77
|
+
bundle install
|
78
|
+
```
|
79
|
+
|
80
|
+
Or install it yourself as:
|
81
|
+
|
82
|
+
```bash
|
83
|
+
gem install spec_forge
|
84
|
+
```
|
85
|
+
|
86
|
+
## Getting Started
|
87
|
+
|
88
|
+
Initialize the required directory structure:
|
89
|
+
|
90
|
+
```bash
|
91
|
+
spec_forge init
|
92
|
+
```
|
93
|
+
|
94
|
+
Or with bundle:
|
95
|
+
```bash
|
96
|
+
bundle exec spec_forge init
|
97
|
+
```
|
98
|
+
|
99
|
+
This creates the `spec_forge` directory with the following structure:
|
100
|
+
```
|
101
|
+
spec_forge/
|
102
|
+
config.yml # Global configuration
|
103
|
+
factories/ # Your factory definitions
|
104
|
+
specs/ # Your test specifications
|
105
|
+
```
|
106
|
+
|
107
|
+
## Writing Your First Test
|
108
|
+
|
109
|
+
Let's write a simple test to verify a user endpoint. Create a new spec file:
|
110
|
+
|
111
|
+
```bash
|
112
|
+
spec_forge new spec users
|
113
|
+
```
|
114
|
+
|
115
|
+
This creates `spec_forge/specs/users.yml`. Here's a basic example:
|
116
|
+
|
117
|
+
```yaml
|
118
|
+
get_user:
|
119
|
+
path: /users/1
|
120
|
+
method: GET
|
121
|
+
expectations:
|
122
|
+
- name: "Retrieves a user successfully"
|
123
|
+
expect:
|
124
|
+
status: 200
|
125
|
+
json:
|
126
|
+
id: 1
|
127
|
+
name: kind_of.string
|
128
|
+
email: /@/
|
129
|
+
```
|
130
|
+
|
131
|
+
Run your tests with:
|
132
|
+
|
133
|
+
```bash
|
134
|
+
spec_forge run
|
135
|
+
```
|
136
|
+
|
137
|
+
## Configuration
|
138
|
+
|
139
|
+
The configuration file (`spec_forge/config.yml`) supports ERB and allows you to set global options for your test suite.
|
140
|
+
|
141
|
+
### Base URL
|
142
|
+
|
143
|
+
The base URL can be specified at three levels (in order of precedence):
|
144
|
+
1. Expectation level
|
145
|
+
2. Spec level
|
146
|
+
3. Config level (`config.yml`)
|
147
|
+
|
148
|
+
```yaml
|
149
|
+
# config.yml
|
150
|
+
base_url: https://api.example.com
|
151
|
+
|
152
|
+
# specs/users.yml
|
153
|
+
get_user:
|
154
|
+
base_url: https://staging.example.com # Overrides config.yml
|
155
|
+
path: /users/1
|
156
|
+
expectations:
|
157
|
+
- name: "Production check"
|
158
|
+
base_url: https://prod.example.com # Overrides spec level
|
159
|
+
expect:
|
160
|
+
status: 200
|
161
|
+
```
|
162
|
+
|
163
|
+
### Authorization
|
164
|
+
|
165
|
+
SpecForge currently supports header-based authorization. Configure it in your `config.yml`:
|
166
|
+
|
167
|
+
```yaml
|
168
|
+
authorization:
|
169
|
+
default:
|
170
|
+
header: Authorization
|
171
|
+
value: Bearer <%= ENV['API_TOKEN'] %> # ERB is supported!
|
172
|
+
```
|
173
|
+
|
174
|
+
## The Spec Structure
|
175
|
+
|
176
|
+
### Basic Structure
|
177
|
+
|
178
|
+
Every spec needs a path, HTTP method, and at least one expectation to be useful:
|
179
|
+
|
180
|
+
```yaml
|
181
|
+
show_user:
|
182
|
+
path: /users/1
|
183
|
+
method: GET # Optional for GET requests, can be lowercase too if that's your style
|
184
|
+
expectations:
|
185
|
+
- name: "Retrieves a User" # Recommended. May be required in future versions for OpenAPI generation
|
186
|
+
expect:
|
187
|
+
status: 200
|
188
|
+
```
|
189
|
+
|
190
|
+
### Testing Response Data
|
191
|
+
|
192
|
+
Let's verify the response JSON:
|
193
|
+
|
194
|
+
```yaml
|
195
|
+
show_user:
|
196
|
+
path: /users/1
|
197
|
+
method: GET
|
198
|
+
expectations:
|
199
|
+
- name: "Retrieves a User"
|
200
|
+
expect:
|
201
|
+
status: 200
|
202
|
+
json:
|
203
|
+
id: 1
|
204
|
+
name: kind_of.string
|
205
|
+
role: admin
|
206
|
+
```
|
207
|
+
|
208
|
+
### Multiple Expectations
|
209
|
+
|
210
|
+
Each expectation can override any spec-level setting. This is useful for testing different scenarios:
|
211
|
+
|
212
|
+
```yaml
|
213
|
+
show_user:
|
214
|
+
path: /users/1
|
215
|
+
method: GET
|
216
|
+
expectations:
|
217
|
+
- name: "Retrieves a User"
|
218
|
+
expect:
|
219
|
+
status: 200
|
220
|
+
json:
|
221
|
+
id: 1
|
222
|
+
role: admin
|
223
|
+
- name: "Invalid User ID"
|
224
|
+
path: /users/999 # Overrides spec-level path
|
225
|
+
expect:
|
226
|
+
status: 404
|
227
|
+
```
|
228
|
+
|
229
|
+
### Request Data
|
230
|
+
|
231
|
+
For POST/PUT/PATCH requests, you can include query parameters and body data:
|
232
|
+
|
233
|
+
```yaml
|
234
|
+
create_user:
|
235
|
+
path: /users
|
236
|
+
method: POST
|
237
|
+
query: # or 'params' if you prefer
|
238
|
+
team_id: 123
|
239
|
+
body: # or 'data' if you prefer
|
240
|
+
name: John Doe
|
241
|
+
email: john@example.com
|
242
|
+
role: admin
|
243
|
+
expectations:
|
244
|
+
- expect:
|
245
|
+
status: 201
|
246
|
+
json:
|
247
|
+
id: kind_of.integer
|
248
|
+
name: John Doe
|
249
|
+
```
|
250
|
+
|
251
|
+
## Dynamic Features
|
252
|
+
|
253
|
+
SpecForge provides powerful features for generating and manipulating test data dynamically.
|
254
|
+
|
255
|
+
### Variables
|
256
|
+
|
257
|
+
Variables let you define and reuse values across your tests. They support complex chaining and can reference generated data:
|
258
|
+
|
259
|
+
```yaml
|
260
|
+
list_posts:
|
261
|
+
path: /posts
|
262
|
+
variables:
|
263
|
+
author: factories.user
|
264
|
+
category_name: faker.lorem.word
|
265
|
+
query:
|
266
|
+
author_id: variables.author.id
|
267
|
+
category: variables.category_name
|
268
|
+
expectations:
|
269
|
+
- name: "Lists user's posts"
|
270
|
+
expect:
|
271
|
+
status: 200
|
272
|
+
json:
|
273
|
+
posts:
|
274
|
+
matcher.include:
|
275
|
+
- author:
|
276
|
+
id: variables.author.id
|
277
|
+
name: variables.author.name
|
278
|
+
category: variables.category_name
|
279
|
+
```
|
280
|
+
|
281
|
+
Variables support deep traversal:
|
282
|
+
```yaml
|
283
|
+
variables:
|
284
|
+
user: factories.user
|
285
|
+
first_post: variables.user.posts.last
|
286
|
+
author: variables.first_post.comments.2.author.name
|
287
|
+
```
|
288
|
+
|
289
|
+
### Transformations
|
290
|
+
|
291
|
+
Transform data using built-in helpers:
|
292
|
+
|
293
|
+
```yaml
|
294
|
+
create_user:
|
295
|
+
variables:
|
296
|
+
first_name: faker.name.first_name
|
297
|
+
last_name: faker.name.last_name
|
298
|
+
full_name:
|
299
|
+
transform.join:
|
300
|
+
- variables.first_name
|
301
|
+
- " "
|
302
|
+
- variables.last_name
|
303
|
+
body:
|
304
|
+
name: variables.full_name
|
305
|
+
email: faker.internet.email
|
306
|
+
```
|
307
|
+
|
308
|
+
### Factory Integration
|
309
|
+
|
310
|
+
SpecForge provides a YAML interface to FactoryBot, making it easy to define and use factories in your tests:
|
311
|
+
|
312
|
+
1. **Existing FactoryBot Factories**: Out of the box, SpecForge automatically discovers your existing Ruby-defined factories from:
|
313
|
+
- Standard paths (`spec/factories` and `test/factories`)
|
314
|
+
- Any custom paths you configure via your `config.yml`:
|
315
|
+
```yaml
|
316
|
+
factories:
|
317
|
+
# Override default FactoryBot factory paths
|
318
|
+
paths:
|
319
|
+
- custom/factories/path
|
320
|
+
|
321
|
+
# Disable automatic factory discovery if needed (default: true)
|
322
|
+
auto_discover: false
|
323
|
+
```
|
324
|
+
|
325
|
+
2. **YAML Factory Definitions**: Define factories using YAML in `spec_forge/factories/`:
|
326
|
+
```yaml
|
327
|
+
# spec_forge/factories/user.yml
|
328
|
+
user:
|
329
|
+
class: User # Optional model class name
|
330
|
+
attributes:
|
331
|
+
name: faker.name.name
|
332
|
+
email: faker.internet.email
|
333
|
+
role: admin
|
334
|
+
```
|
335
|
+
SpecForge registers these YAML definitions with FactoryBot, making them work exactly like Ruby-defined factories.
|
336
|
+
|
337
|
+
Use factories in your tests:
|
338
|
+
```yaml
|
339
|
+
create_post:
|
340
|
+
variables:
|
341
|
+
author: factories.user # Works with both YAML and Ruby-defined factories
|
342
|
+
```
|
343
|
+
|
344
|
+
## RSpec Matchers
|
345
|
+
|
346
|
+
SpecForge provides access to RSpec's powerful matcher system through an intuitive dot notation syntax. The matcher system dynamically integrates with RSpec's matchers through three main namespaces:
|
347
|
+
|
348
|
+
#### "be" namespace
|
349
|
+
```yaml
|
350
|
+
expect:
|
351
|
+
json:
|
352
|
+
# Simple predicates
|
353
|
+
active: be.true
|
354
|
+
deleted: be.false
|
355
|
+
description: be.nil
|
356
|
+
tags: be.empty
|
357
|
+
email: be.present
|
358
|
+
|
359
|
+
# Comparisons (aliases available)
|
360
|
+
price:
|
361
|
+
be.greater_than: 18 # be.greater also works
|
362
|
+
stock:
|
363
|
+
be.less_than_or_equal: 100 # be.less_or_equal also works
|
364
|
+
rating:
|
365
|
+
be.between:
|
366
|
+
- 1
|
367
|
+
- 5
|
368
|
+
|
369
|
+
# Dynamic predicate methods
|
370
|
+
published: be.published # Maps to be_published
|
371
|
+
admin: be.admin # Maps to be_admin
|
372
|
+
```
|
373
|
+
|
374
|
+
#### "kind_of" namespace
|
375
|
+
```yaml
|
376
|
+
expect:
|
377
|
+
json:
|
378
|
+
id: kind_of.integer
|
379
|
+
name: kind_of.string
|
380
|
+
metadata: kind_of.hash
|
381
|
+
scores: kind_of.array
|
382
|
+
```
|
383
|
+
|
384
|
+
#### "matchers" namespace
|
385
|
+
```yaml
|
386
|
+
expect:
|
387
|
+
json:
|
388
|
+
# Direct RSpec matcher usage
|
389
|
+
tags:
|
390
|
+
matcher.include:
|
391
|
+
- featured
|
392
|
+
- published
|
393
|
+
|
394
|
+
slug: /^[a-z0-9-]+$/ # Shorthand for matching regexes
|
395
|
+
|
396
|
+
# Any RSpec matcher can be used
|
397
|
+
config:
|
398
|
+
matcher.have_key: api_version
|
399
|
+
```
|
400
|
+
|
401
|
+
Note: Matchers that require Ruby blocks (like `change`) are not supported.
|
402
|
+
|
403
|
+
## Roadmap
|
404
|
+
|
405
|
+
- [ ] Negated matchers
|
406
|
+
- [ ] OpenAPI generation from your tests
|
407
|
+
- [ ] Support for XML/HTML response handling
|
408
|
+
- [ ] Support for running individual specs
|
409
|
+
|
410
|
+
## Contributing
|
411
|
+
|
412
|
+
1. Fork it
|
413
|
+
2. Create your feature branch (`git checkout -b feature/my-new-feature`)
|
414
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
415
|
+
4. Push to the branch (`git push origin feature/my-new-feature`)
|
416
|
+
5. Create new Pull Request
|
417
|
+
|
418
|
+
Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.
|
419
|
+
|
420
|
+
## License
|
421
|
+
|
422
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|
423
|
+
|
424
|
+
## Looking for a Software Engineer?
|
425
|
+
|
426
|
+
I'm looking for work! Please send serious enquiries to bryan@itsthedevman.com
|
data/Rakefile
ADDED
data/bin/spec_forge
ADDED
data/flake.lock
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
{
|
2
|
+
"nodes": {
|
3
|
+
"flake-utils": {
|
4
|
+
"inputs": {
|
5
|
+
"systems": "systems"
|
6
|
+
},
|
7
|
+
"locked": {
|
8
|
+
"lastModified": 1731533236,
|
9
|
+
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
10
|
+
"owner": "numtide",
|
11
|
+
"repo": "flake-utils",
|
12
|
+
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
13
|
+
"type": "github"
|
14
|
+
},
|
15
|
+
"original": {
|
16
|
+
"owner": "numtide",
|
17
|
+
"repo": "flake-utils",
|
18
|
+
"type": "github"
|
19
|
+
}
|
20
|
+
},
|
21
|
+
"nixpkgs": {
|
22
|
+
"locked": {
|
23
|
+
"lastModified": 1737469691,
|
24
|
+
"narHash": "sha256-nmKOgAU48S41dTPIXAq0AHZSehWUn6ZPrUKijHAMmIk=",
|
25
|
+
"owner": "NixOS",
|
26
|
+
"repo": "nixpkgs",
|
27
|
+
"rev": "9e4d5190a9482a1fb9d18adf0bdb83c6e506eaab",
|
28
|
+
"type": "github"
|
29
|
+
},
|
30
|
+
"original": {
|
31
|
+
"owner": "NixOS",
|
32
|
+
"ref": "nixos-unstable",
|
33
|
+
"repo": "nixpkgs",
|
34
|
+
"type": "github"
|
35
|
+
}
|
36
|
+
},
|
37
|
+
"root": {
|
38
|
+
"inputs": {
|
39
|
+
"flake-utils": "flake-utils",
|
40
|
+
"nixpkgs": "nixpkgs"
|
41
|
+
}
|
42
|
+
},
|
43
|
+
"systems": {
|
44
|
+
"locked": {
|
45
|
+
"lastModified": 1681028828,
|
46
|
+
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
47
|
+
"owner": "nix-systems",
|
48
|
+
"repo": "default",
|
49
|
+
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
50
|
+
"type": "github"
|
51
|
+
},
|
52
|
+
"original": {
|
53
|
+
"owner": "nix-systems",
|
54
|
+
"repo": "default",
|
55
|
+
"type": "github"
|
56
|
+
}
|
57
|
+
}
|
58
|
+
},
|
59
|
+
"root": "root",
|
60
|
+
"version": 7
|
61
|
+
}
|