[rspec-users] Cucumber - stub! or mock?
matt at mattwynne.net
Tue Sep 16 12:03:48 EDT 2008
On 16 Sep 2008, at 15:41, Tim Glen wrote:
> Matt - in terms of subclassing it, I have the entire stable of
> projects, 1 "internal" project and 1 "slush fund" project. If I'm
> subclassing the project, I assume that I still need to have a
> record for them in the database that needs to be findable. So while
> the subclass suggestion helps, I'm not sure it gets me all the way
> there? Could very well be that I'm missing something there...
Yeah this is where ActiveRecord's tight coupling to databases really
starts to bite. You *could* override all the Project.find calls and
merge in the two stock, hard-coded projects (not subclasses) into
every resultset but that sounds like quite hard work.
You could also use STI maybe, and store a row for the two stock
projects but only store the type and put everything else in code. If
you only want one of each though, I don't think that refactoring to
subclasses is really appropriate. You more want to be able to call
Project.internal or Project.slush_fund and always get back that
singleton instance of Project...
I've never needed to do this yet in ruby / rails so you may notice
I'm becoming rather hand-wavey at this point. I think I'll get my
In case you wondered: The opinions expressed in this email are my own
and do not necessarily reflect the views of any former, current or
future employers of mine.
More information about the rspec-users