README.md in airborne-0.0.18 vs README.md in airborne-0.0.19

- old
+ new

@@ -1,8 +1,9 @@ # Airborne [![airborne travis](http://img.shields.io/travis/brooklynDev/airborne.svg?branch=master&style=flat-square)](https://travis-ci.org/brooklynDev/airborne) +[![airborne coveralls](http://img.shields.io/coveralls/brooklynDev/airborne/master.svg?style=flat-square)](https://coveralls.io/r/brooklynDev/airborne?branch=master) [![airborne gem version](http://img.shields.io/gem/v/airborne.svg?style=flat-square)](http://rubygems.org/gems/airborne) [![airbore gem downloads](http://img.shields.io/gem/dt/airborne.svg?style=flat-square)](http://rubygems.org/gems/airborne) [![airborne gem stable downloads](http://img.shields.io/gem/dv/airborne/stable.svg?style=flat-square)](http://rubygems.org/gems/airborne) RSpec driven API testing framework inspired by [frisby.js](https://github.com/vlucas/frisby) @@ -64,11 +65,11 @@ Additionally, if an entire object could be null, but you'd still want to test the types if it does exist, you can wrap the expectations in a call to `optional`: ```ruby it 'should allow optional nested hash' do get '/simple_path_get' #may or may not return coordinates - expect_json_types("address.coordinates", optional({lattitude: :float, longitutde: :float})) + expect_json_types("address.coordinates", optional({latitude: :float, longitude: :float})) end ``` When calling `expect_json` or `expect_json_types`, you can optionally provide a block and run your own `rspec` expectations: @@ -88,11 +89,11 @@ * `response` - The HTTP response returned from the request * `headers` - A symbolized hash of the response headers returned by the request * `body` - The raw HTTP body returned from the request * `json_body` - A symbolized hash representation of the JSON returned by the request -Fo example: +For example: ```ruby it 'should validate types' do get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" } name = json_body[:name] #name will equal "John Doe" @@ -109,10 +110,22 @@ For requests that require a body (`post`, `put`, `patch`) you can pass the body as a hash as well: ```ruby post 'http://example.com/api/v1/my_api', {:name => 'John Doe'}, {'x-auth-token' => 'my_token'} ``` + +##Testing Rack Applications + +If you have an existing Rack application like `sinatra` or `grape` you can run Airborne against your application and test without actually having a server running. To do that, just specify your rack application in your Airborne configuration: + +```ruby +Airborne.configure do |config| + config.rack_app = MySinatraApp +end +``` + +Under the covers, Airborne uses [rack-test](https://github.com/brynary/rack-test) to make the requests. (Rails applications are still not working correctly, support for Rails will come soon!) ##API * `expect_json_types` - Tests the types of the JSON property values returned * `expect_json` - Tests the values of the JSON property values returned @@ -121,11 +134,11 @@ * `expect_header` - Tests for a specified header in the response * `expect_header_contains` - Partial match test on a specified header ##Path Matching -When calling `expect_json_types`, `expect_json` or `expect_json_keys` you can optionaly specify a path as a first parameter. +When calling `expect_json_types`, `expect_json` or `expect_json_keys` you can optionally specify a path as a first parameter. For example, if our API returns the following JSON: ```json { @@ -133,11 +146,11 @@ "address": { "street": "Area 51", "city": "Roswell", "state": "NM", "coordinates": { - "lattitude": 33.3872, + "latitude": 33.3872, "longitude": 104.5281 } } } ``` @@ -148,21 +161,29 @@ describe 'path spec' do it 'should allow simple path and verify only that path' do get 'http://example.com/api/v1/simple_path_get' expect_json_types('address', {street: :string, city: :string, state: :string, coordinates: :object }) #or this - expect_json_types('address', {street: :string, city: :string, state: :string, coordinates: { lattitude: :float, longitude: :float } }) + expect_json_types('address', {street: :string, city: :string, state: :string, coordinates: { latitude: :float, longitude: :float } }) end end ``` +Or, to test the existence of specific keys: +```ruby +it 'should allow nested paths' do + get 'http://example.com/api/v1/simple_path_get' + expect_json_keys('address', [:street, :city, :state, :coordinates]) +end +``` + Alternativley, if we only want to test `coordinates` we can dot into just the `coordinates`: ```ruby it 'should allow nested paths' do get 'http://example.com/api/v1/simple_path_get' - expect_json('address.coordinates', {lattitude: 33.3872, longitutde: 104.5281} ) + expect_json('address.coordinates', {latitude: 33.3872, longitude: 104.5281} ) end ``` When dealing with `arrays`, we can optionally test all (`*`) or a single (`?` - any, `0` - index) element of the array: @@ -247,11 +268,11 @@ Airborne.configure.do |config| config.include MyModule end ``` -Additionally, you can specify a `base_url` and default `headers` to be used on every request (unless overriden in the actual request): +Additionally, you can specify a `base_url` and default `headers` to be used on every request (unless overridden in the actual request): ```ruby Airborne.configure.do |config| config.base_url = 'http://example.com/api/v1' config.headers = {'x-auth-token' => 'my_token'} @@ -263,9 +284,14 @@ expect_json_types({name: :string}) end end ``` +### Run it from the CLI + + $ cd your/project + $ rspec spec + ## License The MIT License Copyright (c) 2014 brooklyndev, sethpollack