Project

restflow

0.0
No commit activity in last 3 years
No release in over 3 years
Simple DSL to assert REST services
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.8.4
>= 0
>= 0
 Project Readme

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.

The assertions for XML are done using Nokogiri. For json we use Ruby core json library.

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 the restflow command

$ 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 © 2013 simcap. See LICENSE.txt for further details.