Closed Pet3ris closed 1 year ago
The necessity to inline the associated type into the mock method signature is a limitation that can't be robustly fixed, at least not without introducing new syntax. But the QSelf syntax does work. In your case, the use of undeclared type Zen
error is probably due to some kind of module problem: you simply haven't imported the Zen
name into the right place. Your exact code works for me. If you still can't figure it out, please post a complete example file.
#[cfg(test)]
mod tests {
use async_trait::async_trait;
use mockall::*;
use super::*;
#[tokio::test]
async fn test_mockall() {
trait Zen {
type Item;
fn zen() -> Self::Item;
}
mock! {
pub Z {}
impl Zen for Z {
type Item = u64;
fn zen() -> <Self as Zen>::Item;
}
}
}
}
This works:
#[cfg(test)]
mod tests {
use async_trait::async_trait;
use mockall::*;
use super::*;
trait Zen {
type Item;
fn zen() -> Self::Item;
}
mock! {
pub Z {}
impl Zen for Z {
type Item = u64;
fn zen() -> <Self as Zen>::Item;
}
}
#[tokio::test]
async fn test_mockall() {
let mock = MockZ::new();
}
}
The following code does not work:
Detailed error
But the following code does:
While using an external create, this adds some extra work in copy/pasting associated type instantiations.
Tested under
mockall = "0.11.2"
.Note, this version, similar to what is specified in
mock!
documentation also didn't work:Detailed error
Detailed error