Struct goose_eggs::ValidateBuilder
source · 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>
impl<'a> ValidateBuilder<'a>
sourcepub fn status(self, status_code: u16) -> Self
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();
sourcepub fn not_status(self, status_code: u16) -> Self
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();
sourcepub fn title(self, title: impl Into<&'a str>) -> Self
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();
sourcepub fn not_title(self, title: impl Into<&'a str>) -> Self
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();
sourcepub fn text(self, text: &'a str) -> Self
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();
sourcepub fn not_text(self, text: &'a str) -> Self
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();
sourcepub fn texts(self, texts: Vec<&'a str>) -> Self
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
.
sourcepub fn not_texts(self, texts: Vec<&'a str>) -> Self
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
.
sourcepub fn header(self, header: impl Into<&'a str>) -> Self
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();
sourcepub fn not_header(self, header: impl Into<&'a str>) -> Self
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();
sourcepub fn header_value(
self,
header: impl Into<&'a str>,
value: impl Into<&'a str>
) -> Self
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();
sourcepub fn not_header_value(
self,
header: impl Into<&'a str>,
value: impl Into<&'a str>
) -> Self
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();
sourcepub fn redirect(self, redirect: impl Into<bool>) -> Self
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();
sourcepub fn build(self) -> Validate<'a>
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>
impl<'a> Clone for ValidateBuilder<'a>
source§fn clone(&self) -> ValidateBuilder<'a>
fn clone(&self) -> ValidateBuilder<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.