Core Assertions
The [assert] block allows you to define validation constraints on incoming HTTP responses. If any assertion fails, the request is marked as failed, triggering automatic retries or self-healing workflows if configured. Rumour supports status code checking, body substring matching, SLA duration limits, JSON Schema validation, leaf-node JSON path assertions ([assert.json]), and response header assertions ([assert.headers]).
1. Setup Environment
To set up a test environment from scratch and replicate the workspace example, follow these steps:
A. Initialize the Workspace
Create a new directory and initialize a clean, zero-clutter Rumour workspace root:
mkdir assert_example
cd assert_example
rumour init
B. Scaffold Modular Collections
Scaffold two modular collections inside the workspace (auth and users) using the scaffolding tool:
rumour new auth
rumour new users
2. Directory Structure & File Contents
After setting up the workspace, your directory structure will look like this:
assert_example/
├── assert_example.config.toml
├── assert_example.suite.toml
├── auth
│ ├── auth.config.toml
│ ├── auth.env.toml
│ ├── auth.suite.toml
│ └── requests
│ └── example.toml
├── users
│ ├── requests
│ │ └── example.toml
│ ├── users.config.toml
│ ├── users.env.toml
│ └── users.suite.toml
└── workspace.env.toml
Here are the complete contents for each file in this setup:
A. Workspace Level Files
workspace.env.toml
Defines base variables and global environment definitions.
# workspace.env.toml
[variables]
base_url = "http://localhost:4000"
"env.ENV_STAGE" = "staging"
B. auth Collection Files
auth/requests/login.toml
Performs authentication and extracts the returned token from the JSON body payload.
# auth/requests/login.toml
[request]
method = "POST"
url = "{{base_url}}/post"
[body]
raw = '{"username": "admin", "token": "session_secret_xyz123"}'
[extract]
token = "json.token"
C. users Collection Files
users/requests/user.schema.json
Draft-07 JSON Schema used to validate the structure of the JSON response payload.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"args": {
"type": "object",
"properties": {
"stage": { "type": "string" },
"userId": { "type": "string" },
"api_key": { "type": "string" }
},
"required": ["stage", "userId", "api_key"]
},
"headers": {
"type": "object"
},
"url": {
"type": "string"
}
},
"required": ["args", "headers", "url"]
}
users/requests/get_users.toml
Consumes the token extracted by login.toml, resolves environment variables, local variables, vault secrets, and enforces root assertions ([assert]), leaf-node JSON assertions ([assert.json]), and header assertions ([assert.headers]).
# users/requests/get_users.toml
[dependencies]
"../../auth/requests/login.toml" = "token"
[request]
method = "GET"
url = "{{base_url}}/get"
[headers]
Authorization = "Bearer {{../../auth/requests/login.token}}"
[params]
stage = "{{env.ENV_STAGE}}"
userId = "{{../../auth/requests/login.token}}"
api_key = "{{vault.SECURE_KEY}}"
[assert]
# 1. Exact HTTP status code validation
status = 200
# 2. HTTP status code range validation
status_range = "200-299"
# 3. Raw response body substring match
body_contains = "session_secret_xyz123"
# 4. Performance SLA (duration limit in milliseconds)
duration = 2000
# 5. Draft-07 JSON Schema validation against local file
schema = "./user.schema.json"
[assert.json."args.stage"]
equal = "staging"
[assert.json."args.userId"]
equal = "session_secret_xyz123"
[assert.json."args.api_key"]
equal = "super_secure_vault_value_987"
[assert.headers."content-type"]
contains = "application/json"
The get_users.toml request relies on {{vault.SECURE_KEY}}. Before executing the request, set up your encrypted Rumour Vault and store SECURE_KEY:
# 1. Set vault password and store secret key
export RUMOUR_VAULT_PASS=mypassword123
rumour vault set SECURE_KEY super_secure_vault_value_987
For a comprehensive guide on managing secrets, see the Vault Commands & Secret Management Guide.
3. Run the Requests & Outputs
To run the execution of the main request, run the following command. The runner automatically detects the dependency on login.toml, executes it, extracts the token, unlocks vault secrets, and evaluates all root, JSON path, and header assertions:
Command
RUMOUR_VAULT_PASS=mypassword123 rumour run users/requests/get_users.toml -vt
Output
~/workspace/testing/assert_example main* ❯ RUMOUR_VAULT_PASS=mypassword123 rumour run users/requests/get_users.toml -vt
POST http://localhost:4000/post
Body (json): {"username": "admin", "token": "session_secret_xyz123"}
✓ SUCCESS: auth/requests/login.toml (991ms)
GET http://localhost:4000/get
Header: Authorization: Bearer session_secret_xyz123
✓ Assertion Passed: status == 200
✓ Assertion Passed: status_range matches "200-299"
✓ Assertion Passed: body_contains "session_secret_xyz123"
✓ Assertion Passed: duration <= 2000ms (240ms)
✓ Assertion Passed: schema validation against ./user.schema.json
✓ Assertion Passed: json."args.stage" == "staging"
✓ Assertion Passed: json."args.userId" == "session_secret_xyz123"
✓ Assertion Passed: json."args.api_key" == "super_secure_vault_value_987"
✓ Assertion Passed: headers."content-type" contains "application/json"
✓ SUCCESS: users/requests/get_users.toml (240ms)
✓ users/requests/get_users.toml → PASS (2 Pass, 0 Fail, 0 Skip)
╭──────────────────────────────────────────────────────────────────────────╮
│ RUMOUR EXECUTION REPORT │
├──────────────────────────────────────────────────────────────────────────┤
│ Total Requests: 2 │
│ Successful: 2 │
│ Failed: 0 │
│ Skipped: 0 │
│ Success Rate: 100.0% │
│ Total Time: 1265ms │
╰──────────────────────────────────────────────────────────────────────────╯
✓ Successful Requests:
- auth/requests/login.toml [200] [992ms]
- users/requests/get_users.toml [200] [272ms]
Actionable Recommendations:
→ Run with --json to export this report for your CI/CD pipeline.
4. Root Assertion Types & Configurations
Rumour supports five key assertions in the root [assert] block:
A. Status Code (status)
Asserts that the HTTP status matches the exact integer code specified.
- Syntax:
status = <integer> - Example:
status = 200
B. Status Range (status_range)
Asserts that the HTTP status falls within a range, or matches a comma-separated list of acceptable status codes.
- Syntax formats:
status_range = "<min>-<max>": Inclusive status code range. Example:"200-299"checks if status is between 200 and 299 inclusive.status_range = "<status1>,<status2>,...": Exact matching list of acceptable codes. Example:"200,201,204".
If both status and status_range are defined in the same [assert] block, the exact status assertion takes precedence, and status_range will be ignored.
C. Response Duration (duration)
Asserts that the total network roundtrip transport duration is less than or equal to the specified limit in milliseconds.
- Syntax:
duration = <integer> - Example:
duration = 2000(fails if response execution takes strictly greater than 2000ms).
D. Substring Search (body_contains)
Asserts that the raw response body contains the specified substring.
- Syntax:
body_contains = "<string>" - Example:
body_contains = "session_secret_xyz123"
E. JSON Schema Validation (schema)
Validates that the JSON response body conforms to a Draft-07 JSON Schema. Rumour supports two syntax variations:
1. Path-Based Schema
A relative path to a local .json file containing the schema. The path is evaluated relative to the request TOML file.
[assert]
schema = "./user.schema.json"
2. Inline Schema
A multi-line string defining the JSON schema directly inside the TOML file:
[assert]
schema = """
{
"type": "object",
"properties": {
"slideshow": { "type": "object" }
},
"required": ["slideshow"]
}
"""
By default, JSON Schema Draft-07 operates on an additive constraint system.
- Fields listed under
"properties"but omitted from"required"are optional. - Extra fields returned by the server pass validation unless
"additionalProperties": falseis set.
5. Advanced Assertion Blocks
A. Leaf-Node JSON Assertions ([assert.json])
Target specific fields in JSON response payloads using dot-separated JSONPath selectors:
[assert.json."args.stage"]
equal = "staging"
[assert.json."args.userId"]
equal = "{{../../auth/requests/login.token}}"
[assert.json."headers.Authorization"]
contains = "Bearer"
Supported Operators:
equal: Exact value match.not_equal: Inverse value match.contains: Substring match for string fields.exists: Boolean check (true/false) verifying key presence.greater_than(orgreaterthan): Numeric lower bound limit.less_than(orlessthan): Numeric upper bound limit.regex: Regular expression pattern matching.
B. Response Header Assertions ([assert.headers])
Validate HTTP response headers returned by the server (evaluated case-insensitively):
[assert.headers."content-type"]
contains = "application/json"
[assert.headers."server"]
exists = true
For dedicated deep-dives into advanced JSON path and header assertions, see:
6. Dependency Resolution Options & Recommendations
When referencing extracted values from dependency requests (like token) inside assertions, you have two distinct syntaxes:
Option 1: Direct Dotted Relative Path (Explicit)
Directly reference the relative file path of the dependency request followed by the variable name:
[assert.json."args.userId"]
equal = "{{../../auth/requests/login.token}}"
Option 2: Simple Local Mapping
Alternatively, reference the variable using short-hand local variable mapping:
[assert.json."args.userId"]
equal = "{{token}}"
Recommended Practice: Explicit Mapping via [dependencies]
To keep your assertion blocks clean and deterministic, declare explicit dependency mappings:
[dependencies]
"../../auth/requests/login.toml" = "token"
For more details on execution and graphs, refer to the Dependency Overview and Explicit Dependencies sections.
7. Troubleshooting & Verification
To audit assertion failures and inspect outgoing/incoming request payloads:
- Trace Mode (
-t/--trace): Displays exact assertion failure messages and raw body diagnostics. - Verbose Mode (
-v/-vt): Shows all evaluated headers, query parameters, and assertion pass/fail indicators in real time. - JSON Output (
--json): Exports anassertion_resultsarray containing structured pass/fail results for CI/CD pipelines.
If Rumour fails execution with a Variable Resolution Error complaining about a missing vault.SECURE_KEY, ensure you have correctly set the RUMOUR_VAULT_PASS environment variable when launching the run to unlock the vault.