Struct spectral::Spec
[−]
[src]
pub struct Spec<'s, S: 's> { pub subject: &'s S, // some fields omitted }
An assertion.
This is created by either the assert_that
function, or by calling that
on a
SpecDescription
.
Fields
subject: &'s S
Methods
impl<'s, S> Spec<'s, S>
[src]
fn with_expected(&mut self, expected: String) -> &mut Self
Builder method to add the expected value for the panic message.
fn with_actual(&mut self, actual: String) -> &mut Self
Builder method to add the actual value for the panic message.
fn fail(&mut self)
Builds the failure message with a description (if present), the expected value,
and the actual value and then calls panic
with the created message.
impl<'s, S> Spec<'s, S> where S: Debug + PartialEq
[src]
fn is_equal_to(&mut self, expected: &S) -> &mut Self
Asserts that the actual value and the expected value are equal. The value type must
implement PartialEq
.
assert_that(&"hello").is_equal_to(&"hello");Run
impl<'s, S> Spec<'s, S> where S: Debug
[src]
fn matches<F>(&mut self, matching_function: F) -> &mut Self where F: Fn(&'s S) -> bool
Accepts a function accepting the value type which returns a bool. Returning false will cause the assertion to fail.
NOTE: The resultant panic message will only state the actual value. It's recommended that you write your own assertion rather than relying upon this.
assert_that(&"hello").matches(|x| x.eq(&"hello"));Run
fn map<F, T>(self, mapping_function: F) -> Spec<'s, T> where F: Fn(&'s S) -> &'s T
Transforms the subject of the Spec
by passing it through to the provided mapping
function.
let test_struct = TestStruct { value: 5 }; assert_that(&test_struct).map(|val| &val.value).is_equal_to(&5);Run
Trait Implementations
impl<'s, T> OrderedSpec<T> for Spec<'s, T> where T: Debug + PartialOrd
[src]
fn is_less_than(&mut self, other: &T) -> &mut Self
Asserts that the subject is less than the expected value. The subject type must
implement PartialOrd
.
assert_that(&1).is_less_than(&2);Run
fn is_less_than_or_equal_to(&mut self, other: &T) -> &mut Self
Asserts that the subject is less than or equal to the expected value. The subject type
must implement PartialOrd
.
assert_that(&2).is_less_than_or_equal_to(&2);Run
fn is_greater_than(&mut self, other: &T) -> &mut Self
Asserts that the subject is greater than the expected value. The subject type must
implement PartialOrd
.
assert_that(&2).is_greater_than(&1);Run
fn is_greater_than_or_equal_to(&mut self, other: &T) -> &mut Self
Asserts that the subject is greater than or equal to the expected value. The subject
type must implement PartialOrd
.
assert_that(&2).is_greater_than_or_equal_to(&1);Run
impl<'s, T> ComparingOptionSpec<T> for Spec<'s, Option<T>> where T: Debug + PartialEq
[src]
fn contains_value(&mut self, expected_value: &T) -> &mut Self
Asserts that the subject is a Some
containing the expected value. The subject type must
be an Option
.
assert_that(&Some(1)).contains_value(&1);Run
impl<'s, T> OptionSpec<T> for Spec<'s, Option<T>> where T: Debug
[src]
fn is_some(&mut self) -> &mut Self
Asserts that the subject is Some
. The subject type must be an Option
.
assert_that(&Some(1)).is_some();Run
fn is_none(&mut self) -> &mut Self
Asserts that the subject is None
. The value type must be an Option
.
assert_that(&Option::None::<String>).is_none();Run
impl<'s, T, E> ResultSpec<T, E> for Spec<'s, Result<T, E>> where T: Debug, E: Debug
[src]
fn is_ok(&mut self) -> &mut Self
Asserts that the subject is Ok
. The value type must be a Result
.
assert_that(&Result::Ok::<usize, usize>(1)).is_ok();Run
fn is_error(&mut self) -> &mut Self
Asserts that the subject is Err
. The value type must be a Result
.
assert_that(&Result::Err::<usize, usize>(1)).is_error();Run
impl<'s> StrSpec for Spec<'s, &'s str>
[src]
fn starts_with(&mut self, expected: &str) -> &mut Self
Asserts that the subject &str
starts with the provided &str
.
assert_that(&"Hello").starts_with(&"H");Run
fn ends_with(&mut self, expected: &str) -> &mut Self
Asserts that the subject &str
ends with the provided &str
.
assert_that(&"Hello").ends_with(&"o");Run
fn contains(&mut self, expected: &str) -> &mut Self
Asserts that the subject &str
contains the provided &str
.
assert_that(&"Hello").contains(&"e");Run
impl<'s, T> VecSpec for Spec<'s, Vec<T>>
[src]
fn has_length(&mut self, expected: usize) -> &mut Self
Asserts that the length of the subject vector is equal to the provided length. The subject
type must be of Vec
.
assert_that(&vec![1, 2, 3, 4]).has_length(4);Run
impl<'s, T> MappingComparingVecSpec<'s, T> for Spec<'s, Vec<T>> where T: Debug
[src]
fn mapped_contains<F, M: 's>(&mut self, mapping_function: F, expected_value: &M) -> &mut Self where M: Debug + PartialEq, F: Fn(&'s T) -> M
Maps the values of the subject Vec
before asserting that the mapped Vec
contains the
provided value. The type of the mapped value must implement PartialEq
.
NOTE: The panic message will refer to the mapped values rather than the values present in
the original Vec
.
#[derive(PartialEq, Debug)] struct Simple { pub val: usize, } ... assert_that(&vec![Simple { val: 1 }, Simple { val: 2 } ]).mapped_contains(|x| &x.val, &2);Run
impl<'s, T: 's, I> ComparingIterSpec<'s, T> for Spec<'s, I> where T: Debug + PartialEq, &'s I: IntoIterator<Item=&'s T>
[src]
fn contains(&mut self, expected_value: &T) -> &mut Self
Asserts that the subject contains the provided value. The subject must implement
IntoIterator
, and the contained type must implement PartialEq
and Debug
.
let test_vec = vec![1,2,3]; assert_that(&test_vec).contains(&2);Run
impl<'s, T: 's, I> MatchingIterSpec<'s, T> for Spec<'s, I> where T: Debug, &'s I: IntoIterator<Item=&'s T>
[src]
fn matching_contains<F>(&mut self, matcher: F) -> &mut Self where F: Fn(&'s T) -> bool
Asserts that the subject contains a matching item by using the provided function.
The subject must implement IntoIterator
, and the contained type must implement Debug
.
let mut test_into_iter = LinkedList::new(); test_into_iter.push_back(TestEnum::Bad); test_into_iter.push_back(TestEnum::Good); test_into_iter.push_back(TestEnum::Bad); assert_that(&test_into_iter).matching_contains(|val| { match val { &TestEnum::Good => true, _ => false } });Run