I was reading Practical Objected-Oriented Design With Ruby other day and Sandi Metz came up with a good and reasonable approach of how to deal with Roles (by role I mean Concerns
and overall duck typing stuff) specs.
- The Role itself should be tested with a test's built-in player. Ex.:
let(:mergeable_class) do
Class.new do
include Mergeable
# ...
end
end
- Then the real players of this role should have tests on their own regarding the interface that role player should respond.
This approach guaranties that we always have documented and tested the players that play certain roles, and also have the specific and shareable in the Role only
@brennovich Cool, I use this approach sometimes. :)
The only problem is when your concern depends on other stuff, like
ActiveRecord::Base
. And for me, in most cases, it does. :(