I'm trying to refactor a testing suite that's way too tightly coupled to the implementation, but I'm having problems with relationships. For example, I have a simple user model:
class AdminUser < ActiveRecord::Base
belongs_to :user_role
delegate :executive?, to: :user_role
end
And this is the UserRole model:
class UserRole < ActiveRecord::Base
def executive?
name == 'Executive'
end
end
Testing the UserRole model is easy, but, following thorough testing rules, I think I should also test the AdminUser model, because I expect it to respond to .executive?, and that's where my problem starts.
If I follow the usual unit testing rules, I should be testing only AdminUser, so I could mock UserRole.executive? and get it done, but... What if UserRole's implementation changes over time? What if I want to change UserRole to another model or a more complex object to follow more complex rules? I would need to change AdminUser's tests to follow the new implementation, and that feels kinda dirty, because being anal about unit testing, I should only be testing the 'what', not the 'how'.
Am I being way too strict here? Is there a better way to do this that I'm not grasping?
Aucun commentaire:
Enregistrer un commentaire