Struct goose_eggs::Validate [−][src]
pub struct Validate<'a> { /* fields omitted */ }
Expand description
Define one or more items to be validated in a web page response.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::Validate;
fn examples() {
// Manually build a Validate strucuture that validates the page title and
// some arbitrary texts in the response html.
let _validate = Validate::new(
None, Some("my page"), vec!["foo", r#"<a href="bar">"#], vec![], None
);
// Use `title_texts()` helper to perform the same validation.
let _validate = Validate::title_texts("my page", vec!["foo", r#"<a href="bar">"#]);
// Use `title_text()` helper to perform similar validation, validating only
// one text on the page.
let _validate = Validate::title_text("my page", r#"<a href="foo">"#);
}
Implementations
Create a new Validate struct, specifying status
, title
, texts
, headers
,
and redirect
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::new(
// Validate the response status code.
Some(404),
// Validate the response page title.
Some("Page Not Found"),
// Validate arbitrary text on the response page.
vec!["Oops, something went wrong!"],
// Validate that the response was sent via https.
vec![&Header::name_value("scheme", "https")],
// Validate that the page redirects.
Some(true),
);
Create a new Validate struct that validates nothing.
This is useful to load all static assets and return the body of the response.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::Validate;
let _validate = Validate::none();
Create a Validate object to validate the response status code.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::status(200);
Create a Validate object to validate the response title.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::title("Home page");
Create a Validate object to validate specific text is on the response page.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::text("This text should be on the page.");
Create a Validate object to validate the response has the correct title and also contains specific text.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::title_text("Example", "This text should be on the page.");
Create a Validate object to validate that the response page contains multiple specific texts.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::texts(vec!["This text should be on the page.", "And also this", r#"<span>and this</a>"#]);
Create a Validate object to validate the response title and that the page contains multiple specific texts.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::title_texts("Example", vec!["This text should be on the page.", "And also this", r#"<span>and this</a>"#]);
Create a Validate object to validate the response included a specific header.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::header(&Header::name("x-cache"));
Create a Validate object to validate that the response included multiple specific headers.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::headers(vec![&Header::name("x-cache"), &Header::name("x-generator")]);
Create a Validate object to validate whether or not the response redirected.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::Validate;
// Verify the response redirected.
let _validate = Validate::redirect(true);
// Verify the response did not redirect.
let _validate = Validate::redirect(false);
Update a Validate object, changing the expected status returned when loading the page.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::title("Home page")
.update_status(200);
Update a Validate object, changing the title expected on the page.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::status(200)
.update_title("Home Page");
Update a Validate object, changing the text validated on the page.
Use Validate::update_texts
if you want to validate multiple texts
on the page.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::title("Home Page")
.update_text("Welcome to my Home Page");
Update a Validate object, changing the texts validated on the page.
Use Validate::update_text
if you want to validate only one text
on the page.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::title("Home Page")
.update_texts(vec!["Welcome", "Log in"]);
Update a Validate object, changing the header expected on the page.
Use Validate::update_headers
if you want to validate multiple headers
on the page.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::title("Home Page")
.update_header(&Header::name("x-cache"));
Update a Validate object, changing the headers expected on the page.
Use Validate::update_header
if you want to validate only one header
on the page.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::{Header, Validate};
let _validate = Validate::title("Home Page")
.update_headers(vec![&Header::name("x-cache"), &Header::name("x-generator")]);
Update a Validate object, changing whether or not the page should redirect.
This structure is passed to validate_and_load_static_assets
.
Example
use goose_eggs::Validate;
// Verify the response redirected.
let _validate = Validate::title("Home Page")
.update_redirect(false);
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for Validate<'a>
impl<'a> UnwindSafe for Validate<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: 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
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub 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. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
type Output = T
type Output = T
Should always be Self