/sinatra-mock-server-template

A base template for a Ruby based local web server using Sinatra and Rack

Primary LanguageRuby

Sinatra Mock Server Base

Requirements

  • Ruby (v2.0+)
  • Bundler

Dependencies

  • Rack (web server middleware)
  • Sinatra (web server framework)

Setup

via Bundler

If you have Bundler (the Ruby gem for installing Ruby gem libraries via a Gemfile):

bundle install

Manual setup

Otherwise install the following libraries:

gem install rack

gem install sinatra

Troubleshooting

  • If you have permissions issues installing then a quick fix is to run the commands as root user e.g. sudo gem install rack and sudo gem install sinatra

Usage

Open a terminal and start the web server:

  • cd sinatra-mock-server-template/
  • rake

You should see an output similar to this:

Terminal screenshot

The server is now bound to your local IP address, making also possible to point devices to it.

Updating the API

  • Edit the App.rb and add new endpoints matching the URLs you want to mock
  • Add sample json responses in the responses folder

code screenshot

mock server screenshot

You can updated the responses and endpoints target this local server in automated tests for your mobile applications. 🎉

Visit http://YOUR_IP:9292/repos/contributors/ to see sample mock JSON response.