Giter VIP home page Giter VIP logo

rspec_api_blueprint_matchers's Introduction

RspecApib

This gem allows your rspec test suite to validate requests and responses against your api blueprint documentation.

It also allows for validating that all documented http transactions are covered in your test suite. (Care should be taken with parallel specs if using this)

Installation

This gem uses the standard api blueprint parser called "drafter" which must be installed before using this gem.

To install it, please refer to https://github.com/apiaryio/drafter#build

Once drafter is installed, please do the following :-

Add this line to your application's Gemfile:

gem 'rspec_apib', group: :test

And then execute:

$ bundle

Or install it yourself as:

$ gem install rspec_apib

Usage

For the rest of the documentation, we will refer to "request" and "response". These can be a faraday request / response environment, or a rack request / response environment or a generic request / response from a rails integration test suite.

Validating a http transaction

A transaction is a struct containing "request" and "response" where request and response are typical requests and responses from rack / faraday etc.. At present, we are using this gem for faraday though.

expect(transaction).to match_api_docs_for(path: "/blogs", request_method: :post, content_type: "application/json")

How This Works

How this works is the request is repeatedly matched against all transactions (request / response pairs) in the api blueprint document. This is done in 2 phases - first a 'short list', then a detailed match on this short list. This is to prevent expensive schema matching when even the basics don't match. The short list is then further filtered by what the developer asked for in the 'match_api_docs_for' matcher.

The matcher also allows the symbol :any to mean "Don't care what it is" but use with caution.

The same is then done for the response and any transactions that match both are considered a good match.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

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

License

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

rspec_api_blueprint_matchers's People

Contributors

garytaylor avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.