Struct Expectations

Source
pub struct Expectations { /* private fields */ }

Implementations§

Source§

impl Expectations

Source

pub fn new() -> Expectations

Create a new Expectations instance. Call this when your mock object is created.

Examples found in repository?
examples/manual.rs (line 38)
36    pub fn new() -> Self {
37        Self {
38            e: Expectations::new()
39        }
40    }
Source

pub fn expect<I, O>(&mut self, name: &'static str) -> Method<'_, I, O>
where I: 'static, O: 'static,

Returns a Method struct which you can use to add expectations for the method with the given name.

Examples found in repository?
examples/manual.rs (line 48)
47    pub fn expect_foo(&mut self) -> Method<(), ()> {
48        self.e.expect::<(), ()>("foo")
49    }
50
51    pub fn expect_bar(&mut self) -> Method<(), ()> {
52        self.e.expect::<(), ()>("bar")
53    }
54
55    pub fn expect_goop(&mut self) -> Method<bool, u32> {
56        self.e.expect::<bool, u32>("goop")
57    }
58
59    pub fn expect_zing(&mut self) -> Method<(i32, bool), ()> {
60        self.e.expect::<(i32, bool), ()>("zing")
61    }
62
63    pub fn expect_boop(&mut self) -> Method<&'static str, ()> {
64        self.e.expect::<&'static str, ()>("boop")
65    }
66
67    pub fn expect_store(&mut self) -> Method<*const i64, ()> {
68        self.e.expect::<*const i64, ()>("store")
69    }
70
71    pub fn expect_toggle(&mut self) -> Method<*mut bool, ()> {
72        self.e.expect::<*mut bool, ()>("toggle")
73    }
Source

pub fn then(&mut self) -> &mut Expectations

Begin a new Era. Expectations in one Era must be met before expectations in future eras will be evaluated.

Note that Eras are evaluated eagerly. This means that Eras may advance more quickly than you’d intuitively expect in certain situations. For example, called_any() is marked as complete after the first call is received. This menas that, for the purposes of telling if an Era should be advanced or not, called_any() and called_once() are the same.

Examples found in repository?
examples/manual.rs (line 43)
42    pub fn then(&mut self) -> &mut Self {
43        self.e.then();
44        self
45    }
Source

pub fn was_called<I, O>(&self, name: &'static str, params: I)
where I: 'static, O: 'static,

When a tracked method is called on the mock object, call this with the method’s name in order to tell the Expectations that the method was called.

Unlike was_called_returning, this method does not return a value.

Examples found in repository?
examples/manual.rs (line 78)
77    fn foo(&self) {
78        self.e.was_called::<(), ()>("foo", ())
79    }
80
81    fn bar(&mut self) {
82        self.e.was_called::<(), ()>("bar", ())
83    }
84
85    fn goop(&mut self, flag: bool) -> u32 {
86        self.e.was_called_returning::<bool, u32>("goop", flag)
87    }
88
89    fn zing(&self, first: i32, second: bool) {
90        self.e.was_called::<(i32, bool), ()>("zing", (first, second))
91    }
92
93    fn boop(&self, name: &'static str) {
94        self.e.was_called::<&'static str, ()>("boop", name)
95    }
96
97    fn store(&self, val: &i64) {
98        self.e.was_called::<*const i64, ()>("store", val)
99    }
100
101    fn toggle(&self, bit: &mut bool) {
102        self.e.was_called::<*mut bool, ()>("toggle", bit)
103    }
Source

pub fn was_called_returning<I, O>(&self, name: &'static str, params: I) -> O
where I: 'static, O: 'static,

Same as the was_called method, but also returns the result.

Examples found in repository?
examples/manual.rs (line 86)
85    fn goop(&mut self, flag: bool) -> u32 {
86        self.e.was_called_returning::<bool, u32>("goop", flag)
87    }

Trait Implementations§

Source§

impl Drop for Expectations

Source§

fn drop(&mut self)

All expectations will be verified when the mock object is dropped, panicking if any of them are unmet.

In the case where the Expectations object is being dropped because the thread is already panicking, the Expectations object is not verified.

Auto Trait Implementations§

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