3 ms·
I don't know that gist just seems contrived. I'm totally not a rails guy so I have to ask: is that the only way you can implement that in rails land? In (most
by crazytony 12y ago
I don't know that gist just seems contrived. I'm totally not a rails guy so I have to ask: is that the only way you can implement that in rails land?
In (most)JS and/or python I would just monkey patch the save method and/or constructor on the employee object to get the isolation and branch coverage.
I would probably need to do some of the same crazy abstraction for Java though.
- colinramsay 12y agoHave a read of the gist comments. It is contrived to an extent, and the original author acknowledged that it wasn't the ideal way of doing things, just an example of a direction you could go.
- npinguy 12y agoNothing crazy required public EmployeeController(EmployeeMapper mapper){} public Employee create() { ... mapper.save(employee); return employee; } Done. All you do now is create a mock employee mapper in your tests, and you can verify just what you want in the Controller instead of anything else You've got * Single responsibility classes (Controller manages employee creation business logic; Mapper is a dumb database wrapper; If you want to go even further, use a Repository instead of a Mapper to introduce one more layer of abstraction between the data model, that way you can slide in caching or in-memory replacements, or what have you at will) * Clean dependencies. There's nothing hidden about what this class needs to get it's work done
- crazytony 12y agoSo the "damaged" class is not really damaged. It's what you'll wind up with if you started with a small rails project and you had to scale it as it got popular? hmmm.