{"id":13654011,"url":"https://github.com/brooklynDev/airborne","last_synced_at":"2025-04-23T07:30:25.643Z","repository":{"id":20685545,"uuid":"23968707","full_name":"brooklynDev/airborne","owner":"brooklynDev","description":"RSpec driven API testing framework","archived":false,"fork":false,"pushed_at":"2024-01-16T02:20:26.000Z","size":324,"stargazers_count":1129,"open_issues_count":45,"forks_count":123,"subscribers_count":27,"default_branch":"master","last_synced_at":"2024-11-10T04:36:41.085Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brooklynDev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-12T16:48:34.000Z","updated_at":"2024-10-30T19:18:54.000Z","dependencies_parsed_at":"2024-06-18T12:27:55.289Z","dependency_job_id":"937991ae-65f0-455d-9027-debe58908391","html_url":"https://github.com/brooklynDev/airborne","commit_stats":{"total_commits":279,"total_committers":46,"mean_commits":6.065217391304348,"dds":0.8673835125448028,"last_synced_commit":"5c08eeb5358c52d22a7967ee310c0827ca841514"},"previous_names":[],"tags_count":66,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brooklynDev%2Fairborne","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brooklynDev%2Fairborne/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brooklynDev%2Fairborne/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brooklynDev%2Fairborne/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brooklynDev","download_url":"https://codeload.github.com/brooklynDev/airborne/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250390782,"owners_count":21422780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T02:01:21.950Z","updated_at":"2025-04-23T07:30:25.394Z","avatar_url":"https://github.com/brooklynDev.png","language":"Ruby","readme":"# Airborne\n\n[![airborne travis](http://img.shields.io/travis/brooklynDev/airborne.svg?branch=master\u0026style=flat-square)](https://travis-ci.org/brooklynDev/airborne)\n[![airborne coveralls](http://img.shields.io/coveralls/brooklynDev/airborne/master.svg?style=flat-square)](https://coveralls.io/r/brooklynDev/airborne?branch=master)\n[![Code Climate](https://api.codeclimate.com/v1/badges/00644ffcf94d5813aa80/maintainability)](https://codeclimate.com/github/brooklynDev/airborne/maintainability)\n[![airborne gem version](http://img.shields.io/gem/v/airborne.svg?style=flat-square)](http://rubygems.org/gems/airborne)\n[![airbore gem downloads](http://img.shields.io/gem/dt/airborne.svg?style=flat-square)](http://rubygems.org/gems/airborne)\n[![airborne gem stable downloads](http://img.shields.io/gem/dv/airborne/stable.svg?style=flat-square)](http://rubygems.org/gems/airborne)\n\nRSpec driven API testing framework\n\n## Looking for Project Maintainers\nI am looking for project maintainers to help keep airborne up to date and bug-free while avoiding feature creep and maintaining backwards compatibility.\n\nComment [here](https://github.com/brooklynDev/airborne/issues/134) if you would like to help out.\n\n## Installation\n\nInstall Airborne:\n```shell\n$ gem install airborne\n```\nOr add it to your Gemfile:\n```ruby\ngem 'airborne'\n```\n## Creating Tests\n\n```ruby\nrequire 'airborne'\n\ndescribe 'sample spec' do\n  it 'should validate types' do\n    get 'http://example.com/api/v1/simple_get' #json api that returns { \"name\" : \"John Doe\" }\n    expect_json_types(name: :string)\n  end\n\n  it 'should validate values' do\n    get 'http://example.com/api/v1/simple_get' #json api that returns { \"name\" : \"John Doe\" }\n    expect_json(name: 'John Doe')\n  end\nend\n```\n\nWhen calling expect_json_types, these are the valid types that can be tested against:\n\n* `:int` or `:integer`\n* `:float`\n* `:bool` or `:boolean`\n* `:string`\n* `:date`\n* `:object`\n* `:null`\n* `:array`\n* `:array_of_integers` or `:array_of_ints`\n* `:array_of_floats`\n* `:array_of_strings`\n* `:array_of_booleans` or `:array_of_bools`\n* `:array_of_objects`\n* `:array_of_arrays`\n\nIf the properties are optional and may not appear in the response, you can append `_or_null` to the types above.\n\n```ruby\ndescribe 'sample spec' do\n  it 'should validate types' do\n    get 'http://example.com/api/v1/simple_get' #json api that returns { \"name\" : \"John Doe\" } or { \"name\" : \"John Doe\", \"age\" : 45 }\n    expect_json_types(name: :string, age: :int_or_null)\n  end\nend\n```\n\nAdditionally, 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`:\n\n```ruby\nit 'should allow optional nested hash' do\n  get '/simple_path_get' #may or may not return coordinates\n  expect_json_types('address.coordinates', optional(latitude: :float, longitude: :float))\nend\n```\n\nAdditionally, when calling `expect_json`, you can provide a regex pattern in a call to `regex`:\n\n```ruby\ndescribe 'sample spec' do\n  it 'should validate types' do\n    get 'http://example.com/api/v1/simple_get' #json api that returns { \"name\" : \"John Doe\" }\n    expect_json(name: regex(\"^John\"))\n  end\nend\n```\n\nWhen calling `expect_json` or `expect_json_types`, you can optionally provide a block and run your own `rspec` expectations:\n\n```ruby\ndescribe 'sample spec' do\n  it 'should validate types' do\n    get 'http://example.com/api/v1/simple_get' #json api that returns { \"name\" : \"John Doe\" }\n    expect_json(name: -\u003e (name){ expect(name.length).to eq(8) })\n  end\nend\n```\n\nCalling `expect_json_sizes` actually make use of the above feature and call `expect_json` under the hood:\n\n```ruby\ndescribe 'sample spec' do\n  it 'should validate types' do\n    get 'http://example.com/api/v1/simple_get_collection' #json api that returns { \"ids\" : [1, 2, 3, 4] }\n    expect_json_sizes(ids: 4)\n  end\nend\n```\n\n## Making requests\n\nAirborne 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`, `options`. This will then give you access the following properties:\n\n* `response` - The HTTP response returned from the request\n* `headers` - A symbolized hash of the response headers returned by the request\n* `body` - The raw HTTP body returned from the request\n* `json_body` - A symbolized hash representation of the JSON returned by the request\n\nFor example:\n\n```ruby\nit 'should validate types' do\n  get 'http://example.com/api/v1/simple_get' #json api that returns { \"name\" : \"John Doe\" }\n  name = json_body[:name] #name will equal \"John Doe\"\n  body_as_string = body\nend\n```\n\nWhen calling any of the methods above, you can pass request headers to be used.\n\n```ruby\nget 'http://example.com/api/v1/my_api', { 'x-auth-token' =\u003e 'my_token' }\n```\n\nFor requests that require a body (`post`, `put`, `patch`) you can pass the body as well:\n\n```ruby\npost 'http://example.com/api/v1/my_api', { :name =\u003e 'John Doe' }, { 'x-auth-token' =\u003e 'my_token' }\n```\n\nThe body may be any JSON-serializable type, as long as you want to post `application/json` content type.\nYou may set a different content type and post a string body this way:\n\n```ruby\npost 'http://example.com/api/v1/my_api', \"Hello there!\", { content_type: 'text/plain' }\n```\n\nFor requests that require Query params you can pass a params hash into headers.\n\n```ruby\npost 'http://example.com/api/v1/my_api', { }, { 'params' =\u003e {'param_key' =\u003e 'param_value' } }\n```\n\n### (Not) Verifying SSL Certificates\n\nSSL certificate verification is enabled by default (specifically, `OpenSSL::SSL::VERIFY_PEER`).\n\nCarefully consider how you use this. It's not a solution for getting around a failed SSL cert verification; rather, it's intended for testing systems that don't have a legitimate SSL cert, such as a development or test environment.\n\nYou can override this behavior per request:\n\n```ruby\nverify_ssl = false\npost 'http://example.com/api/v1/my_api', \"Hello there!\", { content_type: 'text/plain' }, verify_ssl\n```\n\nor with a global Airborne configuration:\n\n```ruby\nAirborne.configure do |config|\n  config.verify_ssl = false # equivalent to OpenSSL::SSL::VERIFY_NONE\nend\n```\n\nNote the per-request option always overrides the Airborne configuration:\n\n```ruby\nbefore do\n  Airborne.configuration.verify_ssl = false\nend\n\nit 'will still verify the SSL certificate' do\n  verify_ssl = true\n  post 'http://example.com/api/v1/my_api', \"Hello there!\", { content_type: 'text/plain' }, verify_ssl\nend\n```\n\nYou can use the `verify_ssl` setting to override your global defaults in test blocks like this:\n\n```ruby\ndescribe 'test something', verify_ssl: false do\nend\n```\n\nOR\n\n```ruby\ndescribe 'test something' do\n  Airborne.configuration.verify_ssl = false\nend\n```\n\nThis feature currently isn't supported when testing loaded Rack applications (see \"Testing Rack Applications\" below). If you need to set `verify_ssl: false`, then we recommend starting your Rack app server and sending the `airborne` HTTP requests as you would when testing any other service.\n\n## Testing Rack Applications\n\nIf 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:\n\n```ruby\nAirborne.configure do |config|\n  config.rack_app = MySinatraApp\nend\n```\n\nUnder the covers, Airborne uses [rack-test](https://github.com/brynary/rack-test) to make the requests.\n\n## Rails Applications\n\nIf you're testing an API you've written in Rails, Airborne plays along with `rspec-rails`:\n\n\n```ruby\nrequire 'rails_helper'\n\nRSpec.describe HomeController, :type =\u003e :controller do\n  describe 'GET index' do\n    it 'returns correct types' do\n      get :index, :format =\u003e 'json' #if your route responds to both html and json\n      expect_json_types(foo: :string)\n    end\n  end\nend\n```\n\n## API\n\n* `expect_json_types` - Tests the types of the JSON property values returned\n* `expect_json` - Tests the values of the JSON property values returned\n* `expect_json_keys` - Tests the existence of the specified keys in the JSON object\n* `expect_json_sizes` - Tests the sizes of the JSON property values returned, also test if the values are arrays\n* `expect_status` - Tests the HTTP status code returned\n* `expect_header` - Tests for a specified header in the response\n* `expect_header_contains` - Partial match test on a specified header\n\n## Path Matching\n\nWhen calling `expect_json_types`, `expect_json`, `expect_json_keys` or `expect_json_sizes` you can optionally specify a path as a first parameter.\n\nFor example, if our API returns the following JSON:\n\n```json\n{\n  \"name\": \"Alex\",\n  \"address\": {\n    \"street\": \"Area 51\",\n    \"city\": \"Roswell\",\n    \"state\": \"NM\",\n    \"coordinates\": {\n      \"latitude\": 33.3872,\n      \"longitude\": 104.5281\n    }\n  }\n}\n```\n\nThis test would only test the address object:\n\n```ruby\ndescribe 'path spec' do\n  it 'should allow simple path and verify only that path' do\n    get 'http://example.com/api/v1/simple_path_get'\n    expect_json_types('address', street: :string, city: :string, state: :string, coordinates: :object)\n    #or this\n    expect_json_types('address', street: :string, city: :string, state: :string, coordinates: { latitude: :float, longitude: :float })\n  end\nend\n```\nOr, to test the existence of specific keys:\n\n```ruby\nit 'should allow nested paths' do\n  get 'http://example.com/api/v1/simple_path_get'\n  expect_json_keys('address', [:street, :city, :state, :coordinates])\nend\n```\n\nAlternatively, if we only want to test `coordinates` we can dot into just the `coordinates`:\n\n```ruby\nit 'should allow nested paths' do\n  get 'http://example.com/api/v1/simple_path_get'\n  expect_json('address.coordinates', latitude: 33.3872, longitude: 104.5281)\nend\n```\n\nWhen dealing with `arrays`, we can optionally test all (`*`) or a single (`?` - any, `0` - index) element of the array:\n\nGiven the following JSON:\n\n```json\n{\n  \"cars\": [\n    {\n      \"make\": \"Tesla\",\n      \"model\": \"Model S\"\n    },\n    {\n      \"make\": \"Lamborghini\",\n      \"model\": \"Aventador\"\n    }\n  ]\n}\n```\n\nWe can test against just the first car like this:\n\n```ruby\nit 'should index into array and test against specific element' do\n  get '/array_api'\n  expect_json('cars.0', make: 'Tesla', model: 'Model S')\nend\n```\n\nTo test the types of all elements in the array:\n\n```ruby\nit 'should test all elements of the array' do\n  get 'http://example.com/api/v1/array_api'\n  expect_json('cars.?', make: 'Tesla', model: 'Model S') # tests that one car in array matches the tesla\n  expect_json_types('cars.*', make: :string, model: :string) # tests all cars in array for make and model of type string\nend\n```\n\n`*` and `?` work for nested arrays as well. Given the following JSON:\n\n```json\n{\n  \"cars\": [\n    {\n      \"make\": \"Tesla\",\n      \"model\": \"Model S\",\n      \"owners\": [\n        {\n          \"name\": \"Bart Simpson\"\n        }\n      ]\n    },\n    {\n      \"make\": \"Lamborghini\",\n      \"model\": \"Aventador\",\n      \"owners\": [\n        {\n          \"name\": \"Peter Griffin\"\n        }\n      ]\n    }\n  ]\n}\n```\n\n===\n\n```ruby\nit 'should check all nested arrays for specified elements' do\n  get 'http://example.com/api/v1/array_with_nested'\n  expect_json_types('cars.*.owners.*', name: :string)\nend\n```\n\n## Dates\n\nJSON has no support for dates, however airborne gives you the ability to check for dates using the following. For `expect_json_types` you would use it as you would for any of the other types:\n\n```ruby\nit 'should verify date type' do\n  get '/get_date' #api that returns {createdAt: \"Mon Oct 20 2014 16:10:42 GMT-0400 (EDT)\"}\n  expect_json_types(createdAt: :date)\nend\n```\nHowever if you want to check the actual date data with `expect_json`, you need to call the `date` function:\n\n```ruby\nit 'should verify correct date value' do\n  get '/get_date' #api that returns {createdAt: \"Mon Oct 20 2014 16:10:42 GMT-0400 (EDT)\"}\n  prev_day = DateTime.new(2014,10,19)\n  next_day = DateTime.new(2014,10,21)\n  #within the date callback, you can use regular RSpec expectations that work with dates\n  expect_json(createdAt: date { |value| expect(value).to be_between(prev_day, next_day) })\nend\n```\n\n## Configuration\n\nWhen setting up Airborne, you can call `configure` just like you would with `rspec`:\n\n```ruby\n#config is the RSpec configuration and can be used just like it\nAirborne.configure do |config|\n  config.include MyModule\nend\n```\n\nAdditionally, you can specify a `base_url` and default `headers` to be used on every request (unless overridden in the actual request):\n\n```ruby\nAirborne.configure do |config|\n  config.base_url = 'http://example.com/api/v1'\n  config.headers = { 'x-auth-token' =\u003e 'my_token' }\nend\n\ndescribe 'spec' do\n  it 'now we no longer need the full url' do\n    get '/simple_get'\n    expect_json_types(name: :string)\n  end\nend\n```\n\nYou can also control the strictness of `expect_json` and `expect_json_types` with the global settings `match_expected_default` and `match_actual_default` like this.\n\n```ruby\nAirborne.configure do |config|\n  config.match_expected_default = true\n  config.match_actual_default = false\nend\n```\n\n`match_expected_default` requires all the keys in the expected JSON are present in the response.\n`match_actual_default` requires that the keys in the response are tested in the expected Hash.\n\nSo you can do the following combinations:\n\n`match_expected_default=false`, `match_actual_default=false` - check only intersection\n`match_expected_default=false`, `match_actual_default=true` - raise on extra key in response\n`match_expected_default=true`, `match_actual_default=false` - raise on missing key in response\n`match_expected_default=true`, `match_actual_default=true` - expect exact match\n\n\nAirborne sets `match_expected_default` to `true` and `match_actual_default` to `false` by default.\n\nYou can use the `match_expected` and `match_actual` settings to override your global defaults in test blocks like this.\n\n```ruby\ndescribe 'test something', match_expected: true, match_actual: false do\nend\n```\n\nOR\n\n```ruby\ndescribe 'test something' do\n  Airborne.configuration.match_expected = true\n  Airborne.configuration.match_actual = false\nend\n```\n\n## Run it from the CLI\n\n```shell\n$ cd your/project\n$ rspec spec\n```\n## Authors\n* [Seth Pollack](https://github.com/sethpollack)\n* [Alex Friedman](https://github.com/brooklynDev)\n\n## Contributors\nhttps://github.com/brooklynDev/airborne/graphs/contributors\n\nInspired by [frisby.js](https://github.com/vlucas/frisby)\n\n## License\n\nThe MIT License\n\nCopyright (c) 2014 [brooklyndev](https://github.com/brooklynDev), [sethpollack](https://github.com/sethpollack)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":["Ruby","Testing"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FbrooklynDev%2Fairborne","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FbrooklynDev%2Fairborne","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FbrooklynDev%2Fairborne/lists"}