pub struct Expectations { /* private fields */ }
Implementations§
Source§impl Expectations
impl Expectations
Sourcepub fn new() -> Expectations
pub fn new() -> Expectations
Create a new Expectations
instance. Call this when your mock object is created.
Sourcepub fn expect<I, O>(&mut self, name: &'static str) -> Method<'_, I, O>where
I: 'static,
O: 'static,
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?
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 }
Sourcepub fn then(&mut self) -> &mut Expectations
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.
Sourcepub fn was_called<I, O>(&self, name: &'static str, params: I)where
I: 'static,
O: 'static,
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?
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 }
Sourcepub fn was_called_returning<I, O>(&self, name: &'static str, params: I) -> Owhere
I: 'static,
O: 'static,
pub fn was_called_returning<I, O>(&self, name: &'static str, params: I) -> Owhere
I: 'static,
O: 'static,
Same as the was_called
method, but also returns the result.