Skip to content

Instantly share code, notes, and snippets.

@brennovich
Last active August 29, 2015 14:24
Show Gist options
  • Save brennovich/36ba75ec589c2f004385 to your computer and use it in GitHub Desktop.
Save brennovich/36ba75ec589c2f004385 to your computer and use it in GitHub Desktop.

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

@mateusg
Copy link

mateusg commented Jul 7, 2015

@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. :(

@brennovich
Copy link
Author

Rails...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment