README.md in airborne-0.1.3 vs README.md in airborne-0.1.4

- old
+ new

@@ -12,11 +12,11 @@ ## Installation Install Airborne: gem install airborne - + Or add it to your Gemfile: gem 'airborne' ##Creating Tests @@ -24,16 +24,16 @@ ```ruby require 'airborne' describe 'sample spec' do it 'should validate types' do - get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" } + get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" } expect_json_types({name: :string}) end - it 'should validate values' do - get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" } + it 'should validate values' do + get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" } expect_json({:name => "John Doe"}) end end ``` @@ -52,11 +52,11 @@ * `:array_of_booleans` or `:array_of_bools` * `:array_of_objects` * `:array_of_arrays` If the properties are optional and may not appear in the response, you can append `_or_null` to the types above. - + ```ruby describe 'sample spec' do it 'should validate types' do get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" } or { "name" : "John Doe", "age" : 45 } expect_json_types({name: :string, age: :int_or_null}) @@ -106,35 +106,35 @@ end ``` ##Making requests -Airborne uses `rest_client` to make the HTTP request, and supports all HTTP verbs. When creating a test, you can call any of the following methods: `get`, `post`, `put`, `patch`, `delete`. This will then give you access the following properties: +Airborne uses `rest_client` to make the HTTP request, and supports all HTTP verbs. When creating a test, you can call any of the following methods: `get`, `post`, `put`, `patch`, `delete`, `head`. This will then give you access the following properties: * `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 For example: ```ruby it 'should validate types' do - get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" } + get 'http://example.com/api/v1/simple_get' #json api that returns { "name" : "John Doe" } name = json_body[:name] #name will equal "John Doe" body_as_string = body end ``` -When calling any of the methods above, you can pass request headers to be used. +When calling any of the methods above, you can pass request headers to be used. ```ruby get 'http://example.com/api/v1/my_api', {'x-auth-token' => 'my_token'} ``` 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 @@ -145,11 +145,11 @@ 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. +Under the covers, Airborne uses [rack-test](https://github.com/brynary/rack-test) to make the requests. ##Rails Applications If you're testing an API you've written in Rails, Airborne plays along with `rspec-rails`: @@ -177,11 +177,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`, `expect_json_keys` or `expect_json_sizes` you can optionally specify a path as a first parameter. +When calling `expect_json_types`, `expect_json`, `expect_json_keys` or `expect_json_sizes` you can optionally specify a path as a first parameter. For example, if our API returns the following JSON: ```json { @@ -195,13 +195,13 @@ "longitude": 104.5281 } } } ``` - + This test would only test the address object: - + ```ruby 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 }) @@ -213,20 +213,20 @@ 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]) + 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', {latitude: 33.3872, longitude: 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: @@ -248,26 +248,26 @@ ``` We can test against just the first car like this: ```ruby -it 'should index into array and test against specific element' do +it 'should index into array and test against specific element' do get '/array_api' expect_json('cars.0', {make: "Tesla", model: "Model S"}) end ``` To test the types of all elements in the array: ```ruby -it 'should test all elements of the array' do +it 'should test all elements of the array' do get 'http://example.com/api/v1/array_api' expect_json('cars.?', {make: "Tesla", model: "Model S"}) # tests that one car in array matches the tesla expect_json_types('cars.*', {make: :string, model: :string}) # tests all cars in array for make and model of type string end ``` - + `*` and `?` work for nested arrays as well. Given the following JSON: ```json { "cars": [ @@ -317,11 +317,11 @@ it 'should verify correct date value' do get '/get_date' #api that returns {createdAt: "Mon Oct 20 2014 16:10:42 GMT-0400 (EDT)"} prev_day = DateTime.new(2014,10,19) next_day = DateTime.new(2014,10,21) #within the date callback, you can use regular RSpec expectations that work with dates - expect_json({createdAt: date {|value| expect(value).to be_between(prev_day, next_day)}}) + expect_json({createdAt: date {|value| expect(value).to be_between(prev_day, next_day)}}) end ``` ##Configuration @@ -352,11 +352,11 @@ ### Run it from the CLI $ cd your/project $ rspec spec - -## License + +## License The MIT License Copyright (c) 2014 [brooklyndev](https://github.com/brooklynDev), [sethpollack](https://github.com/sethpollack)