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', "      {\"firstname\":\"James\",\"lastname\":\"Bond\"}\n    BODY\n\n    get 'users/3'\n    status.should == 200 \n    json['firstname'].should == \"James\"\n    json['lastname'].should == \"Bond\"\n  end\n\nPOST post data from file \n\n  sequence 'Create new user with body from file' do\n    post 'users', :file => \"new_user.json\"\n\n    get 'users/4'\n    status.should == 200 \n    json['firstname'].should == \"Bob\"\n    json['lastname'].should == \"Marley\"\n  end\n\nDELETE\n\n  sequence 'Delete users' do\n    delete 'users/3'\n    status.should == 200\n    get 'users/3'\n    status.should == 404 \n\n    delete 'users/4'\n    status.should == 200\n    get 'users/4'\n    status.should == 404 \n  end\n\nChecking raw response content\n\n  sequence 'Error when creating' do\n    post 'users', <<-BODY\n      {\"firstname\":\"James\"}\n    BODY\n\n    response.should =~ /lastname is missing/\n\n    post 'users', <<-BODY\n      {\"lastname\":\"Bond\"}\n    BODY\n\n    response.should =~ /firstname is missing/\n  end\n"

Copyright © 2013 simcap. See LICENSE.txt for further details.