pub struct Method<'a, I, O> { /* private fields */ }
Expand description
What you get from calling .expect_METHOD_NAME()
on a Mock.
From here, use this struct’s methods to set the number of calls expected.
Implementations§
Source§impl<'a, I, O> Method<'a, I, O>where
I: 'static,
O: 'static,
impl<'a, I, O> Method<'a, I, O>where
I: 'static,
O: 'static,
Sourcepub fn called_never(self) -> TrackedMethod<'a, I, O>
pub fn called_never(self) -> TrackedMethod<'a, I, O>
You expect this method to be called zero times.
Examples found in repository?
examples/macros_mid.rs (line 87)
82fn main() {
83 // Create a mock object
84 let mut m = CoolTraitMock::new();
85
86 // Set up expectations for it
87 m.expect_bar().called_never();
88 m.expect_foo().called_once();
89 m.then().expect_goop().called_once().with(true).returning(|_| 5);
90 m.then().expect_zing().called_once().with(params!(13, false));
91 m.expect_boop().called_times(2);
92 m.expect_store().called_once().with(deref(777));
93 m.expect_toggle().called_once().with(deref(true))
94 .modifying(|&mut arg| { unsafe { *arg = false } });
95
96 // Execute test code
97 m.foo();
98 assert_eq!(m.goop(true), 5);
99 m.zing(13, false);
100 m.boop("hey");
101 m.boop("yo");
102 m.store(&777);
103 let mut b = true;
104 m.toggle(&mut b);
105 assert_eq!(b, false);
106
107 // When the mock object is dropped, its expectations will be evaluated
108}
More examples
examples/manual.rs (line 111)
106fn main() {
107 // Create a mock object
108 let mut m = CoolTraitMock::new();
109
110 // Set up expectations for it
111 m.expect_bar().called_never();
112 m.expect_foo().called_once();
113 m.then().expect_goop().called_once().with(true).returning(|_| 5);
114 m.then().expect_zing().called_once().with(params!(13, false));
115 m.expect_boop().called_times(2);
116 m.expect_store().called_once().with(deref(777));
117 m.expect_toggle().called_once().with(deref(true))
118 .modifying(|&mut arg| { unsafe { *arg = false } });
119
120 // Execute test code
121 m.foo();
122 assert_eq!(m.goop(true), 5);
123 m.zing(13, false);
124 m.boop("hey");
125 m.boop("yo");
126 m.store(&777);
127 let mut b = true;
128 m.toggle(&mut b);
129 assert_eq!(b, false);
130
131 // When the mock object is dropped, its expectations will be evaluated
132}
examples/macros_high.rs (line 75)
70fn main() {
71 // Create a mock object
72 let mut m = CoolTraitMock::new();
73
74 // Set up expectations for it
75 m.expect_bar().called_never();
76 m.expect_foo().called_once();
77 m.then().expect_goop().called_once().with(true).returning(|_| 5);
78 m.then().expect_zing().called_once().with(params!(13, false));
79 m.expect_boop().called_times(2);
80 m.expect_store().called_once().with(deref(777));
81 m.expect_toggle().called_once().with(deref(true))
82 .modifying(|&mut arg| { unsafe { *arg = false } });
83 m.expect_ohno().called_once();
84
85 // Execute test code
86 m.foo();
87 assert_eq!(m.goop(true), 5);
88 m.zing(13, false);
89 m.boop("hey");
90 m.boop("yo");
91 m.store(&777);
92 let mut b = true;
93 m.toggle(&mut b);
94 assert_eq!(b, false);
95 unsafe {
96 m.ohno();
97 }
98
99 // When the mock object is dropped, its expectations will be evaluated
100}
Sourcepub fn called_once(self) -> TrackedMethod<'a, I, O>
pub fn called_once(self) -> TrackedMethod<'a, I, O>
You expect this method to be called only once.
Examples found in repository?
examples/macros_mid.rs (line 88)
82fn main() {
83 // Create a mock object
84 let mut m = CoolTraitMock::new();
85
86 // Set up expectations for it
87 m.expect_bar().called_never();
88 m.expect_foo().called_once();
89 m.then().expect_goop().called_once().with(true).returning(|_| 5);
90 m.then().expect_zing().called_once().with(params!(13, false));
91 m.expect_boop().called_times(2);
92 m.expect_store().called_once().with(deref(777));
93 m.expect_toggle().called_once().with(deref(true))
94 .modifying(|&mut arg| { unsafe { *arg = false } });
95
96 // Execute test code
97 m.foo();
98 assert_eq!(m.goop(true), 5);
99 m.zing(13, false);
100 m.boop("hey");
101 m.boop("yo");
102 m.store(&777);
103 let mut b = true;
104 m.toggle(&mut b);
105 assert_eq!(b, false);
106
107 // When the mock object is dropped, its expectations will be evaluated
108}
More examples
examples/manual.rs (line 112)
106fn main() {
107 // Create a mock object
108 let mut m = CoolTraitMock::new();
109
110 // Set up expectations for it
111 m.expect_bar().called_never();
112 m.expect_foo().called_once();
113 m.then().expect_goop().called_once().with(true).returning(|_| 5);
114 m.then().expect_zing().called_once().with(params!(13, false));
115 m.expect_boop().called_times(2);
116 m.expect_store().called_once().with(deref(777));
117 m.expect_toggle().called_once().with(deref(true))
118 .modifying(|&mut arg| { unsafe { *arg = false } });
119
120 // Execute test code
121 m.foo();
122 assert_eq!(m.goop(true), 5);
123 m.zing(13, false);
124 m.boop("hey");
125 m.boop("yo");
126 m.store(&777);
127 let mut b = true;
128 m.toggle(&mut b);
129 assert_eq!(b, false);
130
131 // When the mock object is dropped, its expectations will be evaluated
132}
examples/macros_high.rs (line 76)
70fn main() {
71 // Create a mock object
72 let mut m = CoolTraitMock::new();
73
74 // Set up expectations for it
75 m.expect_bar().called_never();
76 m.expect_foo().called_once();
77 m.then().expect_goop().called_once().with(true).returning(|_| 5);
78 m.then().expect_zing().called_once().with(params!(13, false));
79 m.expect_boop().called_times(2);
80 m.expect_store().called_once().with(deref(777));
81 m.expect_toggle().called_once().with(deref(true))
82 .modifying(|&mut arg| { unsafe { *arg = false } });
83 m.expect_ohno().called_once();
84
85 // Execute test code
86 m.foo();
87 assert_eq!(m.goop(true), 5);
88 m.zing(13, false);
89 m.boop("hey");
90 m.boop("yo");
91 m.store(&777);
92 let mut b = true;
93 m.toggle(&mut b);
94 assert_eq!(b, false);
95 unsafe {
96 m.ohno();
97 }
98
99 // When the mock object is dropped, its expectations will be evaluated
100}
Sourcepub fn called_times(self, calls: i64) -> TrackedMethod<'a, I, O>
pub fn called_times(self, calls: i64) -> TrackedMethod<'a, I, O>
You expect this method to be called calls
number of times.
Examples found in repository?
examples/macros_mid.rs (line 91)
82fn main() {
83 // Create a mock object
84 let mut m = CoolTraitMock::new();
85
86 // Set up expectations for it
87 m.expect_bar().called_never();
88 m.expect_foo().called_once();
89 m.then().expect_goop().called_once().with(true).returning(|_| 5);
90 m.then().expect_zing().called_once().with(params!(13, false));
91 m.expect_boop().called_times(2);
92 m.expect_store().called_once().with(deref(777));
93 m.expect_toggle().called_once().with(deref(true))
94 .modifying(|&mut arg| { unsafe { *arg = false } });
95
96 // Execute test code
97 m.foo();
98 assert_eq!(m.goop(true), 5);
99 m.zing(13, false);
100 m.boop("hey");
101 m.boop("yo");
102 m.store(&777);
103 let mut b = true;
104 m.toggle(&mut b);
105 assert_eq!(b, false);
106
107 // When the mock object is dropped, its expectations will be evaluated
108}
More examples
examples/manual.rs (line 115)
106fn main() {
107 // Create a mock object
108 let mut m = CoolTraitMock::new();
109
110 // Set up expectations for it
111 m.expect_bar().called_never();
112 m.expect_foo().called_once();
113 m.then().expect_goop().called_once().with(true).returning(|_| 5);
114 m.then().expect_zing().called_once().with(params!(13, false));
115 m.expect_boop().called_times(2);
116 m.expect_store().called_once().with(deref(777));
117 m.expect_toggle().called_once().with(deref(true))
118 .modifying(|&mut arg| { unsafe { *arg = false } });
119
120 // Execute test code
121 m.foo();
122 assert_eq!(m.goop(true), 5);
123 m.zing(13, false);
124 m.boop("hey");
125 m.boop("yo");
126 m.store(&777);
127 let mut b = true;
128 m.toggle(&mut b);
129 assert_eq!(b, false);
130
131 // When the mock object is dropped, its expectations will be evaluated
132}
examples/macros_high.rs (line 79)
70fn main() {
71 // Create a mock object
72 let mut m = CoolTraitMock::new();
73
74 // Set up expectations for it
75 m.expect_bar().called_never();
76 m.expect_foo().called_once();
77 m.then().expect_goop().called_once().with(true).returning(|_| 5);
78 m.then().expect_zing().called_once().with(params!(13, false));
79 m.expect_boop().called_times(2);
80 m.expect_store().called_once().with(deref(777));
81 m.expect_toggle().called_once().with(deref(true))
82 .modifying(|&mut arg| { unsafe { *arg = false } });
83 m.expect_ohno().called_once();
84
85 // Execute test code
86 m.foo();
87 assert_eq!(m.goop(true), 5);
88 m.zing(13, false);
89 m.boop("hey");
90 m.boop("yo");
91 m.store(&777);
92 let mut b = true;
93 m.toggle(&mut b);
94 assert_eq!(b, false);
95 unsafe {
96 m.ohno();
97 }
98
99 // When the mock object is dropped, its expectations will be evaluated
100}
Sourcepub fn called_any(self) -> TrackedMethod<'a, I, O>
pub fn called_any(self) -> TrackedMethod<'a, I, O>
This method can be called any number of times, including zero.
Auto Trait Implementations§
impl<'a, I, O> Freeze for Method<'a, I, O>
impl<'a, I, O> RefUnwindSafe for Method<'a, I, O>where
I: RefUnwindSafe,
O: RefUnwindSafe,
impl<'a, I, O> !Send for Method<'a, I, O>
impl<'a, I, O> !Sync for Method<'a, I, O>
impl<'a, I, O> Unpin for Method<'a, I, O>
impl<'a, I, O> !UnwindSafe for Method<'a, I, O>
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
Mutably borrows from an owned value. Read more