Skip to main content

Story

Struct Story 

Source
pub struct Story { /* private fields */ }
Expand description

A BDD story builder that captures steps and emits a RawTestCase on drop.

Call .pass() before the story goes out of scope to mark the test as passed. If .pass() is not called, the test case will be recorded with status "fail".

Implementations§

Source§

impl Story

Source

pub fn new(scenario: &str) -> Self

Create a new story with the given scenario description.

Source

pub fn with_tags(self, tags: &[&str]) -> Self

Set tags on the story (consumes and returns self for chaining at creation).

Source

pub fn with_tickets(self, tickets: &[&str]) -> Self

Set tickets on the story (consumes and returns self for chaining at creation).

Source

pub fn with_ticket_url(self, id: &str, url: &str) -> Self

Add a ticket with a URL to the story (consumes and returns self for chaining).

Source

pub fn with_trace_url_template(self, template: &str) -> Self

Set the URL template for OTel trace links (uses {traceId} placeholder). Also settable via OTEL_TRACE_URL_TEMPLATE env var.

Source

pub fn given(&mut self, text: &str) -> &mut Self

Add a Given step.

Source

pub fn when(&mut self, text: &str) -> &mut Self

Add a When step.

Source

pub fn then(&mut self, text: &str) -> &mut Self

Add a Then step.

Source

pub fn and(&mut self, text: &str) -> &mut Self

Add an And step.

Source

pub fn but(&mut self, text: &str) -> &mut Self

Add a But step.

Source

pub fn arrange(&mut self, text: &str) -> &mut Self

Add an Arrange step (alias for Given).

Source

pub fn act(&mut self, text: &str) -> &mut Self

Add an Act step (alias for When).

Source

pub fn assert_that(&mut self, text: &str) -> &mut Self

Add an Assert step (alias for Then). Uses assert_that because assert! is a macro.

Source

pub fn setup(&mut self, text: &str) -> &mut Self

Add a Setup step (alias for Given).

Source

pub fn context(&mut self, text: &str) -> &mut Self

Add a Context step (alias for Given).

Source

pub fn execute(&mut self, text: &str) -> &mut Self

Add an Execute step (alias for When).

Source

pub fn action(&mut self, text: &str) -> &mut Self

Add an Action step (alias for When).

Source

pub fn verify(&mut self, text: &str) -> &mut Self

Add a Verify step (alias for Then).

Source

pub fn with_docs(&mut self, docs: Vec<StepDoc>) -> &mut Self

Attach inline documentation entries to the most recently added step.

Source

pub fn start_timer(&mut self) -> usize

Start a high-resolution timer tied to the current step. Returns a token to pass to end_timer().

Source

pub fn end_timer(&mut self, token: usize)

Stop the timer and record duration_ms on the step that was active when start_timer() was called. Double-end is a no-op.

Source

pub fn fn_step<F, T>(&mut self, keyword: &str, text: &str, body: F) -> T
where F: FnOnce() -> T,

Wrap a closure as a BDD step with automatic timing. Creates a step marked as wrapped=true, executes the body, records duration_ms, and re-panics if the body panicked.

Source

pub fn expect_step<F, T>(&mut self, text: &str, body: F) -> T
where F: FnOnce() -> T,

Shorthand for fn_step("Then", text, body).

Source

pub fn note(&mut self, text: &str) -> &mut Self

Attach a text note to the current step or story.

Source

pub fn tag(&mut self, names: &[&str]) -> &mut Self

Attach tag annotations to the current step or story.

Source

pub fn kv(&mut self, label: &str, value: Value) -> &mut Self

Attach a key-value pair to the current step or story.

Source

pub fn json(&mut self, label: &str, value: &impl Serialize) -> &mut Self

Attach a JSON document (serialized as code with lang=json) to the current step or story.

Source

pub fn code( &mut self, label: &str, content: &str, lang: Option<&str>, ) -> &mut Self

Attach a code block to the current step or story.

Source

pub fn table( &mut self, label: &str, columns: &[&str], rows: &[&[&str]], ) -> &mut Self

Attach a table to the current step or story.

Attach a link to the current step or story.

Source

pub fn section(&mut self, title: &str, markdown: &str) -> &mut Self

Attach a markdown section to the current step or story.

Source

pub fn mermaid(&mut self, code: &str, title: Option<&str>) -> &mut Self

Attach a mermaid diagram to the current step or story.

Source

pub fn screenshot(&mut self, path: &str, alt: Option<&str>) -> &mut Self

Attach a screenshot reference to the current step or story.

Source

pub fn custom(&mut self, type_name: &str, data: Value) -> &mut Self

Attach a custom doc entry to the current step or story.

Source

pub fn attach(&mut self, name: &str, media_type: &str, path: &str) -> &mut Self

Attach a file-based attachment to the story.

Source

pub fn attach_inline( &mut self, name: &str, media_type: &str, body: &str, encoding: &str, ) -> &mut Self

Attach an inline (body-based) attachment to the story.

Source

pub fn attach_spans(&mut self, spans: Vec<Value>) -> &mut Self

Attach OTel spans for trace waterfall rendering in HTML reports.

Source

pub fn pass(&mut self)

Mark the story as passed. Must be called before the story goes out of scope.

Trait Implementations§

Source§

impl Drop for Story

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl Freeze for Story

§

impl RefUnwindSafe for Story

§

impl Send for Story

§

impl Sync for Story

§

impl Unpin for Story

§

impl UnsafeUnpin for Story

§

impl UnwindSafe for Story

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.