asomers / mockall

A powerful mock object library for Rust
Apache License 2.0
1.5k stars 62 forks source link

Struct with different traits that has identically named methods #551

Open ThomasConrad opened 7 months ago

ThomasConrad commented 7 months ago

Let say I want to mock a struct like this:

mock!(
Foo {}
impl A for Foo {
  fn new(&self) -> A;
}
impl B for Foo {
  fn new(&self) -> B;
} 
);

Then I am getting an error saying that expect_new() is already defined. I would strongly prefer the created method to be named something like expect_A_new(), you get the point.

asomers commented 7 months ago

This name collision is a well known problem, and there's no setting in Mockall that can fix it for you. You'll have to manually mock one of those methods.