Restflow

Simple DSL to assert REST services

Installation

$ gem install restflow

Usage

Create a file that contains the sequences of REST calls and add assertions to test the payloads you get back.

Example with a file name sequence.rb:

base_url 'https://api.github.com'

sequence 'Retrieve info of a Github user' do
get 'users/simcap'
json['login'].should == "simcap"
status.should == 200
end

sequence 'Retrieve info of a Github repo' do
get 'users/simcap/repos'
json[0]['full_name'].should == "simcap/anagram-kata"
status.should == 200

get 'repos/simcap/anagram-kata'
json['name'].should == "anagram-kata"
end

Then run on the file

$ restflow sequence.rb

A report file sequences-report.html will be generated in the current directory.

Examples

GET asserting response code

sequence 'List all users' do
  get 'users'
  status.should == 200
end

sequence 'Cannot find user' do
  get 'users/3'
  status.should == 404  
end

GET asserting json content

sequence 'List one users' do
  get 'users/1'
  json['firstname'].should == "John"
  json['lastname'].should == "Doe"

  get 'users/2'
  json['firstname'].should == "Sue"
  json['lastname'].should == "Helen"
end

POST inline post data

sequence 'Create new user' do
  post 'users', <<-BODY
    {"firstname":"James","lastname":"Bond"}
  BODY
  
  get 'users/3'
  status.should == 200 
  json['firstname'].should == "James"
  json['lastname'].should == "Bond"
end

POST post data from file 

sequence 'Create new user with body from file' do
  post 'users', :file => "new_user.json"
  
  get 'users/4'
  status.should == 200 
  json['firstname'].should == "Bob"
  json['lastname'].should == "Marley"
end

DELETE

sequence 'Delete users' do
  delete 'users/3'
  status.should == 200
  get 'users/3'
  status.should == 404 

  delete 'users/4'
  status.should == 200
  get 'users/4'
  status.should == 404 
end

Checking raw response content

sequence 'Error when creating' do
  post 'users', <<-BODY
    {"firstname":"James"}
  BODY
    
  response.should =~ /lastname is missing/

  post 'users', <<-BODY
    {"lastname":"Bond"}
  BODY

  response.should =~ /firstname is missing/
end

Copyright (c) 2013 simcap. See LICENSE.txt for further details.