I'm trying to figure out the best way to test find_communities
here without resorting to using polymorphism here to defeat the if
statement staring at me.
class CommunityFinder
def initialize(filters={})
@filters = filters
end
def find_communities
return my_communities if @filters[:my_communities]
visible_communities
end
def my_communities
# [...]
end
def visibile_communities
# [...]
end
end
I have both my_communities
and visible_communities
well tested, but I have concerns about testing find_communities
.
- I don't want to duplicate the test setup for both
my_communities
andvisible_communities
, because there's likely going to be - I would prefer for the class API to contain all 3 public methods because the conditions for
find_communities
won't ever change. - I'm writing this with the expectation that the class is going to change by someone other than me in the near future, and that there's going to be more methods
Should I:
- make
find_communities
live in the caller - make
find_communities
be it's own strategy - duplicate the tests into
find_communities
- pick your own 4th option.
Aucun commentaire:
Enregistrer un commentaire