pub struct ValidateBuilder<'a> { /* private fields */ }
Expand description

Used to build a Validate object, necessary to invoke the validate_page or validate_and_load_static_assets functions.

Example

use goose::prelude::*;
use goose_eggs::{validate_and_load_static_assets, Validate};

transaction!(load_and_validate_page);

async fn load_and_validate_page(user: &mut GooseUser) -> TransactionResult {
    // Make a GET request.
    let mut goose = user.get("example/path").await?;

    // Build a [`Validate`] object to confirm the response is valid.
    let validate = &Validate::builder()
        // Validate that the page has `Example` in the title.
        .title("Example")
        // Validate that the page has `foo` in the returned html body.
        .text("foo")
        // Validate that the page also has `<a href="bar">` in the returned
        // html body.
        .text(r#"<a href="bar">"#)
        .build();

    // Perform the actual validation, using `?` to pass up the error if any
    // validation fails.
    validate_and_load_static_assets(
        user,
        goose,
        &validate,
    ).await?;

    Ok(())
}

Implementations§

source§

impl<'a> ValidateBuilder<'a>

source

pub fn status(self, status_code: u16) -> Self

Define the HTTP status expected to be returned when loading the page.

This structure is passed to validate_page or validate_and_load_static_assets.

Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .status(200)
    .build();
source

pub fn not_status(self, status_code: u16) -> Self

Define an HTTP status not expected to be returned when loading the page.

This structure is passed to validate_page or validate_and_load_static_assets.

Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .not_status(404)
    .build();
source

pub fn title(self, title: impl Into<&'a str>) -> Self

Create a Validate object to validate that response title contains the specified text.

This structure is passed to validate_page or validate_and_load_static_assets.

Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .title("Home page")
    .build();
source

pub fn not_title(self, title: impl Into<&'a str>) -> Self

Create a Validate object to validate that response title does not contain the specified text.

This structure is passed to validate_page or validate_and_load_static_assets.

Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .not_title("Home page")
    .build();
source

pub fn text(self, text: &'a str) -> Self

Create a Validate object to validate that the response page contains the specified text.

This structure is passed to validate_page or validate_and_load_static_assets.

Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .text("example")
    .build();

It’s possible to call this function multiple times to validate that multiple texts appear on the page. Alternatively you can call ValidateBuilder::texts.

Multiple Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .text("example")
    .text("another")
    .build();
source

pub fn not_text(self, text: &'a str) -> Self

Create a Validate object to validate that the response page does not contain the specified text.

This structure is passed to validate_page or validate_and_load_static_assets.

Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .not_text("example not on page")
    .build();

It’s possible to call this function multiple times (and together with text(), texts() and not_texts()) to validate that multiple texts do or do not appear on the page. Alternatively you can call ValidateBuilder::texts.

Multiple Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .not_text("example not on the page")
    .not_text("another not on the page")
    .text("this is on the page")
    .build();
source

pub fn texts(self, texts: Vec<&'a str>) -> Self

Create a Validate object to validate that the response page contains the specified texts.

This structure is passed to validate_page or validate_and_load_static_assets.

Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .texts(vec!["example", "another"])
    .build();

It’s possible to call this function multiple times (and together with text(), not_text() and not_texts()) to validate that multiple texts do or do not appear on the page. Alternatively you can call ValidateBuilder::texts.

Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .texts(vec!["example", "another"])
    .not_texts(vec!["foo", "bar"])
    .texts(vec!["also this", "and this"])
    .build();

Alternatively you can call ValidateBuilder::text.

source

pub fn not_texts(self, texts: Vec<&'a str>) -> Self

Create a Validate object to validate that the response page does not contains the specified texts.

This structure is passed to validate_page or validate_and_load_static_assets.

Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .not_texts(vec!["example", "another"])
    .build();

It’s possible to call this function multiple times (and together with text(), not_text() and texts()) to validate that multiple texts do or do not appear on the page. Alternatively you can call ValidateBuilder::texts.

Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .not_texts(vec!["example", "another"])
    .texts(vec!["does include foo", "and bar"])
    .not_texts(vec!["but not this", "or this"])
    .build();

Alternatively you can call ValidateBuilder::text.

source

pub fn header(self, header: impl Into<&'a str>) -> Self

Create a Validate object to validate that the response includes the specified header.

To validate that a header contains a specific value (instead of just validating that it exists), use ValidateBuilder::header_value.

This structure is passed to validate_page or validate_and_load_static_assets.

Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .header("x-cache")
    .build();

It’s possible to call this function multiple times, and/or together with ValidateBuilder::not_header, ValidateBuilder::header_value and ValidateBuilder::not_header_value.

Multiple Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .header("x-cache")
    .header("x-generator")
    .build();
source

pub fn not_header(self, header: impl Into<&'a str>) -> Self

Create a Validate object to validate that the response does not include the specified header.

To validate that a header does not contain a specific value (instead of just validating that it does not exist), use ValidateBuilder::not_header_value.

This structure is passed to validate_page or validate_and_load_static_assets.

Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .not_header("x-cache")
    .build();

It’s possible to call this function multiple times, and/or together with ValidateBuilder::header, ValidateBuilder::header_value and ValidateBuilder::not_header_value.

Multiple Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .not_header("x-cache")
    .header("x-generator")
    .build();
source

pub fn header_value( self, header: impl Into<&'a str>, value: impl Into<&'a str> ) -> Self

Create a Validate object to validate that the response includes the specified header which contains the specified value.

To validate that a header simply exists without confirming that it contains a specific value, use ValidateBuilder::header.

This structure is passed to validate_page or validate_and_load_static_assets.

Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .header_value("x-generator", "Drupal 7")
    .build();

It’s possible to call this function multiple times, and/or together with ValidateBuilder::header, ValidateBuilder::not_header and ValidateBuilder::not_header_value.

Multiple Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    // Validate that the "x-cache" header is set.
    .header("x-cache")
    // Validate that the "x-generator" header is set and contains "Drupal 7".
    .header_value("x-generator", "Drupal-7")
    // Validate that the "x-drupal-cache" header is set and contains "HIT".
    .header_value("x-drupal-cache", "HIT")
    .build();
source

pub fn not_header_value( self, header: impl Into<&'a str>, value: impl Into<&'a str> ) -> Self

Create a Validate object to validate that given header does not contain the specified value.

To validate that a header simply doesn’t exist without confirming that it doesn’t contain a specific value, use ValidateBuilder::not_header.

This structure is passed to validate_page or validate_and_load_static_assets.

Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    .not_header_value("x-generator", "Drupal 7")
    .build();

It’s possible to call this function multiple times, and/or together with ValidateBuilder::header_value, ValidateBuilder::not_header and ValidateBuilder::header.

Multiple Example
use goose_eggs::Validate;

let _validate = Validate::builder()
    // Validate that the "x-cache" header is set.
    .header("x-cache")
    // Validate that the "x-generator" header if set does not contain "Drupal 7".
    .not_header_value("x-generator", "Drupal-7")
    // Validate that the "x-drupal-cache" header is set to "HIT".
    .header_value("x-drupal-cache", "HIT")
    .build();
source

pub fn redirect(self, redirect: impl Into<bool>) -> Self

Create a Validate object to validate whether or not the response page redirected.

This structure is passed to validate_page or validate_and_load_static_assets.

Example
use goose_eggs::Validate;

// Verify the response redirected.
let _validate = Validate::builder().redirect(true).build();

// Verify the response did not redirect.
let _validate = Validate::builder().redirect(false).build();
source

pub fn build(self) -> Validate<'a>

Build the Validate object which is then passed to the validate_page or validate_and_load_static_assets functions.

Example
use goose_eggs::Validate;

// Use the default search form to search for `example keys`.
let _validate = Validate::builder()
    .text("example text")
    .build();

Trait Implementations§

source§

impl<'a> Clone for ValidateBuilder<'a>

source§

fn clone(&self) -> ValidateBuilder<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for ValidateBuilder<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for ValidateBuilder<'a>

§

impl<'a> Send for ValidateBuilder<'a>

§

impl<'a> Sync for ValidateBuilder<'a>

§

impl<'a> Unpin for ValidateBuilder<'a>

§

impl<'a> UnwindSafe for ValidateBuilder<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for Twhere T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> GooseUserData for Twhere T: Send + Sync + 'static,