SpecFormula AI
ISABackendInstructions

EntityNonExistenceValidate

Validate database record non-existence

EntityNonExistenceValidate lets you verify that a record has been deleted from the database, commonly used for testing delete operations.

Basic Usage

Then should not exist a todo, with table:
  | todoId    | userId    |
  | $todo1.id | $Alice.id |

This instruction will:

  1. Map "todo" to the todos table via Entity Spec and retrieve field definitions
  2. Use the provided fields as query conditions
  3. Validate the query result is empty (record does not exist)

Use Case

After a delete operation, confirm the record has been removed from the database:

When (UID="$Alice.id") delete todo, call table:
  | P:todoId  |
  | $todo1.id |
Then delete todo(200) response, with table:
  | message          |
  | Delete succeeded |
Then should not exist a todo, with table:
  | todoId    |
  | $todo1.id |

Mapping to Entity Spec

The EntityNonExistenceValidate instruction uses Entity Spec to map business entity names to actual database tables, and validates field existence against the DDL.

# entity_to_table_mapping.yml
entity_to_table_mapping:
  - todo: todos
  - user: users
-- schema.sql
CREATE TABLE todos (
    todo_id BIGINT AUTO_INCREMENT PRIMARY KEY,
    user_id BIGINT NOT NULL,
    title VARCHAR(200) NOT NULL,
    completed BOOLEAN DEFAULT FALSE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Then should not exist a todo, with table:
  | todoId    |
  | $todo1.id |

# SpecFormula automatically maps to the todos table
# SELECT * FROM todos WHERE todo_id = ?
# Validate query result is empty
Gherkin ElementMapping Source
todoentity_to_table_mapping key
todos tableentity_to_table_mapping value
todoId fieldDDL field definitions

Lookup Strategies

PK Query (Priority)

Provide the complete primary key to query directly:

| todoId    |
| $todo1.id |

# SELECT * FROM todos WHERE todo_id = ?
# Validate query result is empty

Probe Query

Use non-PK field combinations as query conditions:

| userId    | title    |
| $Alice.id | Buy milk |

# SELECT * FROM todos WHERE user_id = ? AND title = ?
# Validate query result is empty

Limitations

This instruction does not support:

  • CAS constraint symbols (&...)
  • VAR extraction keys (>contextKey)
  • Response source fields (<executionKey)

Error Handling

Lint Phase

ErrorDescription
Entity not definedNot found in entity_to_table_mapping
Field not foundField not found in table definition
Unsupported symbolCAS or VAR extraction syntax used

Runtime

ErrorDescription
Record still existsRecord expected to not exist actually exists
Missing query conditionNo fields provided as query conditions

Complete Example

Feature: Delete Todo

  Background:
    # EntitySetup instruction (see EntitySetup docs)
    Given prepare a user, with table:
      | >Alice.id | name  | email             | status |
      | <userId   | Alice | alice@example.com | ACTIVE |

  Example: Delete a todo item

    # ApiCall instruction (see ApiCall docs)
    When (UID="$Alice.id") create todo, call table:
      | >todo1.id | title    |
      | <todoId   | Buy milk |

    # ApiCall instruction — P: prefix for Path parameter
    When (UID="$Alice.id") delete todo, call table:
      | P:todoId  |
      | $todo1.id |

    # ResponseValidate instruction (see ResponseValidate docs)
    Then delete todo(200) response, with table:
      | message          |
      | Delete succeeded |

    # EntityNonExistenceValidate instruction — verify record deleted
    And should not exist a todo, with table:
      | todoId    | userId    |
      | $todo1.id | $Alice.id |

On this page