[rspec-users] [RSpec] Testing a helper with or without model layer?
dchelimsky at gmail.com
Tue Aug 3 10:03:32 EDT 2010
On Aug 3, 2010, at 6:34 AM, Bruno Cardoso wrote:
> Hi guys,
> I wanted to get a more experienced opinion about a test I had to do.
> I posted the code at pastie with comments for best visual readability:
Even though the code is in a helper, it depends heavily on the model. This exhibits a code smell called Feature Envy, in which one object (the helper) does some computation but another object (the CfgInterface model) has all the data. Based on that, one might argue this method belongs on the model anyhow, in which case the argument of stubbing out the model layer makes little sense.
There are also several expectations that overlap. It doesn't matter that the class is a Hash - what matters is that it behaves like a hash, which is demonstrated in other expectations. The fact that the keys exist is also demonstrated in the expectations that access those keys.
Based on those comments, I'd probably do something like http://gist.github.com/506366. Then I'd figure out how to swap in factories for the fixtures - right now there's no way to understand what 'CONS_ALL_ACCOUNT' means without looking elsewhere.
> Any feedback is appreciated
> Posted via http://www.ruby-forum.com/.
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users