Backdrop

Gem Version Build Status Coverage Status Code Climate Dependency Status

JSON fixture generation for integration testing apps which consume multiple remote APIs.

Installation

Gemfile

gem 'backdrop'

config/routes.rb

mount Backdrop::App => '/backdrop'

Configuration

Backdrop stores JSON in temporary files whilst it runs which should not be checked into version control. This can be specificied in an initializer:

Backdrop.configure do |config|
  # defaults to tmp/backdrop
  config.output_dir = '/your/temp/path'
end

Usage

require 'backdrop'

Backdrop can be used on either a single OpenStruct or an array of OpenStructs. Each of these must have a property called 'backdrop_url' which is where the generated JSON will be located. This will be removed before being used for the API.

To create an API, call Backdrop.load on the data. To clear all loaded APIs, use Backdrop.clear.

Integration with Factory Girl

Backdrop is most easily used alongside FactoryGirl.

FactoryGirl.define do
  factory :example, class: OpenStruct do
    backdrop_url { name }
    name "example"
  end
end

You can then use Backdrop.load(FactoryGirl.build :example) to create the following JSON at /backdrop/example:

{"name":"example"}

Similarly, Backdrop.load(FactoryGirl.build_list :example, 2) would create the following JSON:

[{"name":"example"},{"name":"example"}]

Dependencies

  • Ruby >= 1.9.3