faux
faux copied to clipboard
trait support?
good library.!!!!!!!!!
is there plan to support trait ?
pub trait A{ fn resize(&self, cols: u16, rows: u16) -> Result<(), String>; }
struct MockA{} //i will define a struct
#[cfg_attr(test, faux::create)] / impl A for MockA{ // i dont want to write there dummy code , and need faux auto generate fn resize(&self, cols: u16, rows: u16) -> Result<(), String>{ !todo() }; }
let a = MockA::faux() faux::when!(a.resize) .then_return(Ok(()));
This is definitely something I want to do, but I haven't prioritized it yet. The hardest part is coming up with something ergonomic that works for all traits. My ideal solution would be something like:
#[cfg_attr(test, faux::create)]
pub trait MyTrait {
/* declare methods */
}
#[test]
fn my_test() {
let mock = MyTrait::faux();
}
But rust only allows calling instance methods directly on traits for object safe traits which means it is not a global solution. Maybe I'll just have to say that it's good enough and provide a fallback for non-object safe traits? I am not sure... these design decisions slow me down haha
It looks like there's been code to support what I want in nightly for over 3 years but it has yet to be stabilized: https://github.com/rust-lang/rust/issues/43561.
There hasn't been any discussion on the tracking issue in a while though so it's hard to know if it's going to be merged soon or if it got lost in the shuffle.