Popularity
0.6
Stable
Activity
0.0
Stable
7
2
1

Monthly Downloads: 99
Programming language: Ruby
License: MIT License
Tags: Testing     Frameworks     RSpec     Rails     Ruby    

ResponseMatcher alternatives and similar gems

Based on the "RSpec" category.
Alternatively, view ResponseMatcher alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of ResponseMatcher or a related project?

Add another 'RSpec' Gem

README

ResponseMatcher

Gem Version CircleCI

Solution for matching JSON response into RSpec request tests.

Installation

Add this line to your application's Gemfile:

gem 'response_matcher'

And then execute:

$ bundle

Or install it yourself as:

$ gem install response_matcher

Usage

Quick start

In registration_spec.rb

describe RegistrationsController do
  describe 'POST /auth' do
    it 'response' do
      post user_registration_path, params: params

      expect(response).to response_match('schema_path', user: User.last)
    end
  end
end

You can create your own schema

└─ spec
    ├─ schemas
    │   ├─ my_schema.rb
    │   └─ ...
    └─ ...

In my_schema.rb you can describe by ruby language how looks like your response

# All the parameters that you transmit will be available as variables, like 'user'
{
  data: {
    id: user.id,
    type: user.class.name,
    attributes: {
      email: user.email,
      provider: user.provider,
      uid: user.uid
    }
  }
}

You can reuse your schemas in another schemas

└─ spec
    ├─ schemas
    │   ├─ my_schema.rb
    │   ├─ attributes.rb
    │   └─ ...
    └─ ...

In my_schema.rb

# All the parameters that you transmit will be available as variables, like 'user'
{
  data: {
    id: user.id,
    type: user.class.name,
    attributes: call('attributes', user: user)
  }
}

In attributes.rb

{
  email: user.email,
  provider: user.provider,
  uid: user.uid
}

You can use helpers in your schemas:

└─ spec
    ├─ schemas
    │   ├─ my_schema.rb
    │   ├─ attributes.rb
    │   └─ ...
    ├─ helpers
    │   ├─ my_helper.rb
    │   └─ ...
    ├─ rails_helper.rb
    └─ ...

In my_helper.rb

module Helpers
  module MyHelper
    def entity_class(entity)
      entity.class.name
    end
  end
end

In rails_helper.rb

ResponseMatcher::Settings.configure do |config|
  config.helpers = [
    Helpers::MyHelper,
    ...
  ]
end

In my_schema.rb

{
  data: {
    id: user.id,
    type: entity_class(user),
    attributes: call('attributes', user: user)
  }
}

You can set base directory of your schemas:

In rails_helper.rb

ResponseMatcher::Settings.configure do |config|
  config.directory = 'spec/schemas/api/v1'
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/bezrukavyi/response_matcher

License

The gem is available as open source under the terms of the MIT License.


*Note that all licence references and agreements mentioned in the ResponseMatcher README section above are relevant to that project's source code only.