I have a method defined in the
impl block for a struct. I want to mock it out as part of a unit test, and have been investigating mockers. In the user guide, it says that while it is possible with some extra effort to mock out struct impls (see Mocking structures),
Ideally, of course, you should extract a trait and make
AirConditionerimplement this trait.
Is that a good pattern, in general? If I have my
Tab struct (representing a browser tab), and some of its methods are related to finding DOM elements on the page via CSS selectors, should I put them in their own trait and write an implementation for
Tab, even though
Tab (for the foreseeable future) will be the only struct to implement it?
If you’re neutral towards that idea, how would you feel about my extracting the trait just to make it easier to work with mockers?
Finally, do you think it’s okay to split the new trait (and the one implementation) out into its own file?