rails-api/active_model_serializers — pull request #596 by bolshakov (2014-08-18 14:23:31+00:00)
Title: Test::Unit assert_serializer implemented

Rails uses `ActiveSupport::Notifications` to collect information about rendered views. So its possible to implement `assert_templete` method to test that template specified have been rendered.

We wrapped `as_json` method with `ActiveSupport::Notifications.instrument`and collect information about rendered serializers for each test case.

`assert_serializer` method uses this information to make assertions.

```ruby
# assert that the "PostSerializer" serializer was rendered
assert_serializer "PostSerializer"

# assert that the "PostSerializer" serializer was rendered
assert_serializer :post_serializer

# assert that the rendered serializer starts with "Post"
assert_serializer %r{\APost.+\Z}

# assert that no serializer was rendered
assert_serializer nil
```

In case of failure it generate useful message:

```ruby
assert_serializer 'PostSerializer'
# Raises exception with message 'expecting <"PostSerializer"> but rendering with <["ProfileSerializer"]'>
```