0.0
No commit activity in last 3 years
No release in over 3 years
any request in the rack layer, returns any json response(Content-Type: application/json) and http status.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
= 3.3.0

Runtime

 Project Readme

rack-mock_json

Gem Version Circle CI

Overview

rack-mock_json is for any request in the rack layer, returns any json response(Content-Type: application/json) and http status.

Setting it defined in yaml.

Installation

Add this line to your application's Gemfile:

gem 'rack-mock_json'

Usage

Rails

Rails.application.configure do
  # ...
  config.middleware.use Rack::MockJson::Middleware, config_file_path: "#{config.root}/config/mock_json.yml"
end

Examples For more information, click here

Config

- request_path: 'GET /users'
  contents:
    - '{ "name": "retu", "age" : "20" }'
    - '{ "name": "jane", "age" : "25" }'
- request_path: 'POST /user'
  status: 201
  contents:
    - '{ "name": "taro", "age" : 17 }'

If you have multiple elements specified in the contents, and then picked up at random. Also, if you specify the mock_element_index=i in parameter, and it returns a particular element.

Ex.

$ curl http://localhost:3000/users -X GET -d "mock_element_index=0"
{ "name": "retu", "age" : "20" }
$ curl http://localhost:3000/users -X GET -d "mock_element_index=1"
{ "name": "jane", "age" : "25" }
Propety Required Default Remarks
request_path - Use the regular expression
status × 200 HTTP Status
contents - Body Content

Examples For more information, click here

License

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