tonyta / active_model_serializers_matchers

RSpec matchers for testing ActiveModel::Serializer
MIT License
19 stars 7 forks source link

Any chance to expand support to Minitest? #16

Open jayqui opened 7 years ago

jayqui commented 7 years ago

It'd be great if this gem would also work with Minitest as opposed only to Rspec.

I'd be willing to help with this , but I'd need to understand a little more clearly how this gem interacts with (or conflicts with) the shoulda-matchers gem (especially the should method). (E.g. where is should defined? How does the test suite know that should is supposed to work with the ActiveModelSerializersMatchers class as opposed to some class in the domain of Shoulda::Matchers (in the case that one is using both gems)?)

Thanks for any help or guidance you can provide.

tonyta commented 7 years ago

Hey @jayqui! Thanks for your interest!

The should in the readme is the one-liner syntax supported by RSpec Core so this gem has no dependencies or collisions with shoulda-matchers.

The entry point to this gem is through the #have_one and #have_many methods, which returns a matcher. RSpec will basically call #matches? and pass in the subject and will using the #failure_message if it doesn't pass. So for Minitest, here's a possible implementation:

def test_menu_serializer
  subject = MenuSerializer
  matcher = ActiveModelSerializersMatchers::AssociationMatcher.
    new(:entrees, :has_many).as(:dishes).serialized_with(FoodSerializer)
  assert matcher.matches?(subject), matcher.failure_message
end

Of course, we could probably figure out a cleaner interface. I hope this helps. I would love to see an extension to this gem for Minitest. Hope this helps!