airborne 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79d440d2df8f4d24cf08cfce862f3ab0e1c9ef7aefa0147c2950cb31f94fc18d
4
- data.tar.gz: 5ea1100a384ba25bf4cd91d170246e08bf85ff999ecf0ef9d64b8bc7c108385d
3
+ metadata.gz: e82ac09255660ba50383c09a309e13eeafbcbf02c0e6185fc4e9a034aa976043
4
+ data.tar.gz: 25624c608eab8122cedb12b433c267eef09ca36538dad9f3dfd73afd38163f29
5
5
  SHA512:
6
- metadata.gz: aa5e6922e85d08fa988ffbc63102a800b150a813bec543dc8448b4368ff20a35f8e97124ee6df3f4bdf679b59b4d312c0c277718e8b1a8c5f0ac2d7b86e74be5
7
- data.tar.gz: 00d4c4de596a4d2d72a936a7ed7c619b767d05fa41deef382112bf9254d6b39614366a44ac7d4a5c344857f6859b83691672e0eb972fb1ed23a0fdd1aed65f16
6
+ metadata.gz: b4ecf6d5a854d54863a2cd53e213baed22b00a9072b31e8769a66e8ca5ee7e832856b580cbc2eb736b3a9a35718b8a3cf437b70193c78fd04d4806c9b1eaaea4
7
+ data.tar.gz: 4ba44d43e8ed37e70e05f591e06060a89ba8efa8cb8cefa0001ca382f06505cdc19b38595e77a04bf7de54719f22231dfde9aebbf5abe5364ed4a62b20246899
@@ -33,3 +33,35 @@ jobs:
33
33
  ruby-version: ${{ matrix.ruby }}
34
34
  bundler-cache: true
35
35
  - run: bundle exec rake
36
+
37
+ rails:
38
+ runs-on: ubuntu-latest
39
+ strategy:
40
+ matrix:
41
+ load_order: [before, after]
42
+ framework:
43
+ - rails: '~> 7.1.0'
44
+ rspec: '~> 6.1'
45
+ rack: '~> 2.2'
46
+ sinatra: '~> 2.2'
47
+ - rails: '~> 7.2.0'
48
+ rspec: '~> 7.1'
49
+ rack: '~> 3.0'
50
+ sinatra: '~> 4.0'
51
+ - rails: '~> 8.1.0'
52
+ rspec: '~> 8.0'
53
+ rack: '~> 3.0'
54
+ sinatra: '~> 4.0'
55
+ env:
56
+ RAILS_VERSION: ${{ matrix.framework.rails }}
57
+ RSPEC_RAILS_VERSION: ${{ matrix.framework.rspec }}
58
+ RACK_VERSION: ${{ matrix.framework.rack }}
59
+ SINATRA_VERSION: ${{ matrix.framework.sinatra }}
60
+ AIRBORNE_LOAD_ORDER: ${{ matrix.load_order }}
61
+ steps:
62
+ - uses: actions/checkout@v4
63
+ - uses: ruby/setup-ruby@v1
64
+ with:
65
+ ruby-version: '3.3'
66
+ bundler-cache: true
67
+ - run: bundle exec rspec integration/rails --format progress
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## [v0.4.1](https://github.com/brooklynDev/airborne/tree/v0.4.1) (2026-11-24)
4
+
5
+ - Preserve Rails request helpers and response accessors when Airborne is loaded after `rspec-rails`.
6
+ - Add Rails request and controller integration tests in both load orders, including the JSON assertion reported in #167 and consecutive requests.
7
+ - Document Rails request specs and the upgrade needed for the older 0.0.18 JSON-response bug.
8
+
3
9
  ## [v0.4.0](https://github.com/brooklynDev/airborne/tree/v0.4.0) (2026-11-24)
4
10
 
5
11
  **Rack 3 support:**
data/Gemfile CHANGED
@@ -7,6 +7,11 @@ gem 'rack', ENV['RACK_VERSION'] if ENV['RACK_VERSION']
7
7
  gem 'coveralls', require: false
8
8
  gem 'faraday-retry', require: false
9
9
 
10
+ if ENV['RAILS_VERSION']
11
+ gem 'railties', ENV['RAILS_VERSION']
12
+ gem 'rspec-rails', ENV.fetch('RSPEC_RAILS_VERSION', '>= 0')
13
+ end
14
+
10
15
  group :test do
11
16
  gem 'webmock'
12
17
  gem 'sinatra', ENV.fetch('SINATRA_VERSION', '>= 0')
data/README.md CHANGED
@@ -1,19 +1,13 @@
1
1
  # Airborne
2
2
 
3
- [![airborne travis](http://img.shields.io/travis/brooklynDev/airborne.svg?branch=master&style=flat-square)](https://travis-ci.org/brooklynDev/airborne)
4
- [![airborne coveralls](http://img.shields.io/coveralls/brooklynDev/airborne/master.svg?style=flat-square)](https://coveralls.io/r/brooklynDev/airborne?branch=master)
5
- [![Code Climate](https://api.codeclimate.com/v1/badges/00644ffcf94d5813aa80/maintainability)](https://codeclimate.com/github/brooklynDev/airborne/maintainability)
6
- [![airborne gem version](http://img.shields.io/gem/v/airborne.svg?style=flat-square)](http://rubygems.org/gems/airborne)
7
- [![airbore gem downloads](http://img.shields.io/gem/dt/airborne.svg?style=flat-square)](http://rubygems.org/gems/airborne)
8
- [![airborne gem stable downloads](http://img.shields.io/gem/dv/airborne/stable.svg?style=flat-square)](http://rubygems.org/gems/airborne)
3
+ [![Tests](https://img.shields.io/github/actions/workflow/status/brooklynDev/airborne/tests.yml?branch=master&style=flat-square&label=tests)](https://github.com/brooklynDev/airborne/actions/workflows/tests.yml)
4
+ [![Coverage](https://img.shields.io/coverallsCoverage/github/brooklynDev/airborne?branch=master&style=flat-square)](https://coveralls.io/github/brooklynDev/airborne?branch=master)
5
+ [![Gem version](https://img.shields.io/gem/v/airborne?style=flat-square)](https://rubygems.org/gems/airborne)
6
+ [![Total downloads](https://img.shields.io/gem/dt/airborne?style=flat-square)](https://rubygems.org/gems/airborne)
7
+ [![Stable version downloads](https://img.shields.io/gem/dv/airborne/stable?style=flat-square)](https://rubygems.org/gems/airborne)
9
8
 
10
9
  RSpec driven API testing framework
11
10
 
12
- ## Looking for Project Maintainers
13
- I am looking for project maintainers to help keep airborne up to date and bug-free while avoiding feature creep and maintaining backwards compatibility.
14
-
15
- Comment [here](https://github.com/brooklynDev/airborne/issues/134) if you would like to help out.
16
-
17
11
  ## Installation
18
12
 
19
13
  Install Airborne:
@@ -246,6 +240,28 @@ RACK_VERSION='~> 3.0' SINATRA_VERSION='~> 4.0' bundle exec rake
246
240
 
247
241
  If you're testing an API you've written in Rails, Airborne plays along with `rspec-rails`:
248
242
 
243
+ Require `airborne` in `rails_helper.rb` alongside `rspec/rails`. Rails request and
244
+ controller specs use Rails' own request helpers and response object; Airborne adds
245
+ JSON, status, and header assertions without requiring a separate server or `base_url`.
246
+
247
+ ```ruby
248
+ require 'rails_helper'
249
+
250
+ RSpec.describe 'Users API', type: :request do
251
+ it 'returns an error for a missing user' do
252
+ get '/api/users/1'
253
+ expect_status(:not_found)
254
+ expect_json('error', message: 'not found')
255
+ end
256
+ end
257
+ ```
258
+
259
+ If an older installation reports `undefined method '[]' for nil:NilClass`, check
260
+ the Airborne version in `Gemfile.lock` and run `bundle update airborne`. Early
261
+ versions such as 0.0.18 only populated `json_body` after Airborne's own requests;
262
+ current versions parse the Rails response directly, including after consecutive requests.
263
+
264
+ Controller specs are also supported:
249
265
 
250
266
  ```ruby
251
267
  require 'rails_helper'
data/airborne.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'date'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'airborne'
5
- s.version = '0.4.0'
5
+ s.version = '0.4.1'
6
6
  s.date = Date.today.to_s
7
7
  s.summary = 'RSpec driven API testing framework'
8
8
  s.authors = ['Alex Friedman', 'Seth Pollack']
@@ -0,0 +1,55 @@
1
+ require_relative 'spec_helper'
2
+
3
+ RSpec.describe 'Airborne with Rails request specs', type: :request do
4
+ it 'uses Rails requests and assertions against the Rails response (issue #167)' do
5
+ expect(method(:get).owner.name).to start_with('ActionDispatch::')
6
+ get '/api/users/1'
7
+
8
+ expect_json('error', message: 'not found')
9
+ expect_json_types('error', message: :string, id: :string)
10
+ expect_json_keys('error', [:message, :id])
11
+ expect_status(:not_found)
12
+ expect_header_contains(:content_type, 'application/json')
13
+ expect { expect_json('error', message: 'wrong') }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
14
+ end
15
+
16
+ it 'reads the latest response on consecutive Rails requests' do
17
+ get '/api/users/1'
18
+ expect_json('error', id: '1')
19
+
20
+ get '/api/users/2'
21
+ expect_json('error', id: '2')
22
+ end
23
+
24
+ it 'accepts the Rails keyword arguments for JSON requests' do
25
+ post '/api/users', params: { name: 'Alex' }, as: :json
26
+
27
+ expect_status(:created)
28
+ expect_json(name: 'Alex')
29
+ end
30
+ end
31
+
32
+ RSpec.describe 'Airborne requests outside Rails request and controller specs' do
33
+ it 'keeps the Airborne requester available when rspec-rails is loaded' do
34
+ external_response = Struct.new(:code, :headers, :body).new(200, {}, '{"ok":true}')
35
+ allow(RestClient::Request).to receive(:execute).and_return(external_response)
36
+
37
+ expect(method(:get).owner).to eq(Airborne::RequestMethods)
38
+ get 'https://example.test/ping'
39
+
40
+ expect_status(200)
41
+ expect_json(ok: true)
42
+ expect(RestClient::Request).to have_received(:execute).with(hash_including(url: 'https://example.test/ping'))
43
+ end
44
+ end
45
+
46
+ RSpec.describe AirborneRailsIntegration::UsersController, type: :controller do
47
+ it 'uses Rails controller helpers and response accessors' do
48
+ expect(method(:get).owner.name).to start_with('ActionController::')
49
+ get :show, params: { id: '1' }
50
+
51
+ expect_status(404)
52
+ expect_json('error', message: 'not found', id: '1')
53
+ expect_header_contains('Content-Type', 'application/json')
54
+ end
55
+ end
@@ -0,0 +1,35 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+
3
+ require 'rspec/core'
4
+ require 'airborne' if ENV.fetch('AIRBORNE_LOAD_ORDER', 'before') == 'before'
5
+ require 'rails'
6
+ require 'action_controller/railtie'
7
+
8
+ module AirborneRailsIntegration
9
+ class Application < Rails::Application
10
+ config.root = File.expand_path('../../tmp/rails-app', __dir__)
11
+ config.eager_load = false
12
+ config.secret_key_base = 'airborne-rails-integration-test-secret'
13
+ config.hosts.clear
14
+ config.logger = Logger.new(File::NULL)
15
+ end
16
+
17
+ class UsersController < ActionController::API
18
+ def show
19
+ render json: { error: { message: 'not found', id: params[:id] } }, status: :not_found
20
+ end
21
+
22
+ def create
23
+ render json: { name: params[:name] }, status: :created
24
+ end
25
+ end
26
+ end
27
+
28
+ AirborneRailsIntegration::Application.initialize!
29
+ AirborneRailsIntegration::Application.routes.draw do
30
+ get '/api/users/:id', to: 'airborne_rails_integration/users#show'
31
+ post '/api/users', to: 'airborne_rails_integration/users#create'
32
+ end
33
+
34
+ require 'rspec/rails'
35
+ require 'airborne' unless ENV.fetch('AIRBORNE_LOAD_ORDER', 'before') == 'before'
data/lib/airborne/base.rb CHANGED
@@ -2,14 +2,13 @@ require 'json'
2
2
  require 'active_support'
3
3
  require 'active_support/core_ext/hash/indifferent_access'
4
4
  require 'airborne/response_headers'
5
+ require 'airborne/request_methods'
5
6
 
6
7
  module Airborne
7
8
  class InvalidJsonError < StandardError; end
8
9
 
9
10
  include RequestExpectations
10
11
 
11
- attr_reader :response, :headers, :body
12
-
13
12
  def self.configure
14
13
  RSpec.configure do |config|
15
14
  yield config
@@ -17,6 +16,12 @@ module Airborne
17
16
  end
18
17
 
19
18
  def self.included(base)
19
+ # Rails request and controller specs own their request helpers and response.
20
+ if defined?(RSpec::Rails::RequestExampleGroup)
21
+ return if base < RSpec::Rails::RequestExampleGroup || base < RSpec::Rails::ControllerExampleGroup
22
+ end
23
+
24
+ base.send(:include, RequestMethods)
20
25
  if !Airborne.configuration.requester_module.nil?
21
26
  base.send(:include, Airborne.configuration.requester_module)
22
27
  elsif !Airborne.configuration.rack_app.nil?
@@ -30,38 +35,6 @@ module Airborne
30
35
  RSpec.configuration
31
36
  end
32
37
 
33
- def get(url, headers = nil, verify_ssl = base_verify_ssl)
34
- @response = make_request(:get, url, headers: headers, verify_ssl: verify_ssl)
35
- end
36
-
37
- def post(url, post_body = nil, headers = nil, verify_ssl = base_verify_ssl)
38
- @response = make_request(:post, url, body: post_body, headers: headers, verify_ssl: verify_ssl)
39
- end
40
-
41
- def patch(url, patch_body = nil, headers = nil, verify_ssl = base_verify_ssl)
42
- @response = make_request(:patch, url, body: patch_body, headers: headers, verify_ssl: verify_ssl)
43
- end
44
-
45
- def put(url, put_body = nil, headers = nil, verify_ssl = base_verify_ssl)
46
- @response = make_request(:put, url, body: put_body, headers: headers, verify_ssl: verify_ssl)
47
- end
48
-
49
- def delete(url, delete_body = nil, headers = nil, verify_ssl = base_verify_ssl)
50
- @response = make_request(:delete, url, body: delete_body, headers: headers, verify_ssl: verify_ssl)
51
- end
52
-
53
- def head(url, headers = nil)
54
- @response = make_request(:head, url, headers: headers)
55
- end
56
-
57
- def options(url, headers = nil)
58
- @response = make_request(:options, url, headers: headers)
59
- end
60
-
61
- def response
62
- @response
63
- end
64
-
65
38
  def headers
66
39
  ResponseHeaders.new(response.headers.to_h)
67
40
  end
@@ -0,0 +1,33 @@
1
+ module Airborne
2
+ module RequestMethods
3
+ attr_reader :response
4
+
5
+ def get(url, headers = nil, verify_ssl = base_verify_ssl)
6
+ @response = make_request(:get, url, headers: headers, verify_ssl: verify_ssl)
7
+ end
8
+
9
+ def post(url, post_body = nil, headers = nil, verify_ssl = base_verify_ssl)
10
+ @response = make_request(:post, url, body: post_body, headers: headers, verify_ssl: verify_ssl)
11
+ end
12
+
13
+ def patch(url, patch_body = nil, headers = nil, verify_ssl = base_verify_ssl)
14
+ @response = make_request(:patch, url, body: patch_body, headers: headers, verify_ssl: verify_ssl)
15
+ end
16
+
17
+ def put(url, put_body = nil, headers = nil, verify_ssl = base_verify_ssl)
18
+ @response = make_request(:put, url, body: put_body, headers: headers, verify_ssl: verify_ssl)
19
+ end
20
+
21
+ def delete(url, delete_body = nil, headers = nil, verify_ssl = base_verify_ssl)
22
+ @response = make_request(:delete, url, body: delete_body, headers: headers, verify_ssl: verify_ssl)
23
+ end
24
+
25
+ def head(url, headers = nil)
26
+ @response = make_request(:head, url, headers: headers)
27
+ end
28
+
29
+ def options(url, headers = nil)
30
+ @response = make_request(:options, url, headers: headers)
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airborne
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Friedman
@@ -173,12 +173,15 @@ files:
173
173
  - README.md
174
174
  - Rakefile
175
175
  - airborne.gemspec
176
+ - integration/rails/request_spec.rb
177
+ - integration/rails/spec_helper.rb
176
178
  - lib/airborne.rb
177
179
  - lib/airborne/base.rb
178
180
  - lib/airborne/optional_hash_type_expectations.rb
179
181
  - lib/airborne/path_matcher.rb
180
182
  - lib/airborne/rack_test_requester.rb
181
183
  - lib/airborne/request_expectations.rb
184
+ - lib/airborne/request_methods.rb
182
185
  - lib/airborne/response_headers.rb
183
186
  - lib/airborne/rest_client_requester.rb
184
187
  - rakelib/changelog.rake