Skip to content

Commit

Permalink
Merge pull request #163 from leoarnold/leoarnold/github-actions
Browse files Browse the repository at this point in the history
Pivot to GitHub Actions
  • Loading branch information
sethpollack authored and leoarnold committed Jan 12, 2023
2 parents d253166 + 7425d62 commit 425273d
Show file tree
Hide file tree
Showing 46 changed files with 526 additions and 341 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
pull_request:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
ruby:
- 2.7.7
- 3.0.5
- 3.1.3
- 3.2.0

steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Update RubyGems / Bundler
run: |
gem update --system
gem --version
gem install bundler
- run: bundle exec rake
49 changes: 49 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require:
- rubocop-performance
- rubocop-rake
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.7
NewCops: enable

### Metrics ###

Metrics:
Exclude:
- lib/airborne/request_expectations.rb

Metrics/MethodLength:
CountAsOne:
- hash

### Style ###

Style/Documentation:
Enabled: false

Style/SymbolArray:
EnforcedStyle: brackets

### RSpec ###

RSpec/ContextWording:
Enabled: false

RSpec/DescribeClass:
Enabled: false

RSpec/ExampleLength:
Enabled: false

RSpec/MultipleDescribes:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

RSpec/NotToNot:
EnforcedStyle: to_not

RSpec/RepeatedDescription:
Enabled: false
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

9 changes: 8 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec

gem 'coveralls', require: false
gem 'faraday-retry', require: false
gem 'rubocop', require: false
gem 'rubocop-performance', require: false
gem 'rubocop-rake', require: false
gem 'rubocop-rspec', require: false

group :test do
gem 'webmock'
gem 'sinatra'
gem 'webmock'
end
15 changes: 2 additions & 13 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
require 'github_changelog_generator/task'

GitHubChangelogGenerator::RakeTask.new :changelog do |config|
raise(
ArgumentError,
'You need to export CHANGELOG_GITHUB_TOKEN first! You can generate one at: https://github.com/settings/tokens/new'
) if ENV['CHANGELOG_GITHUB_TOKEN'].nil?

config.project = 'airborne'

# change this to your github username if you plan to submit a PR with a new CHANGELOG.md
config.user = 'brooklynDev'
end
# frozen_string_literal: true

task default: [:spec]
23 changes: 14 additions & 9 deletions airborne.gemspec
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# frozen_string_literal: true

require 'date'

Gem::Specification.new do |s|
Gem::Specification.new do |s| # rubocop:disable Gemspec/RequireMFA
s.name = 'airborne'
s.version = '0.3.7'
s.date = Date.today.to_s
s.summary = 'RSpec driven API testing framework'
s.authors = ['Alex Friedman', 'Seth Pollack']
s.email = ['a.friedman07@gmail.com', 'seth@sethpollack.net']
s.require_paths = ['lib']
s.files = `git ls-files`.split("\n")
s.license = 'MIT'
s.add_runtime_dependency 'rspec', '~> 3.8'
s.add_runtime_dependency 'rest-client', '< 3.0', '>= 2.0.2'
s.add_runtime_dependency 'rack-test', '< 2.0', '>= 1.1.0'
s.add_runtime_dependency 'rack'
s.license = 'MIT'

s.required_ruby_version = ['>= 2.7', '< 4']

s.add_runtime_dependency 'activesupport'
s.add_development_dependency 'webmock', '~> 3'
s.add_development_dependency 'rake', '~> 12'
s.add_runtime_dependency 'rack'
s.add_runtime_dependency 'rack-test', '< 2.0', '>= 1.1.0'
s.add_runtime_dependency 'rest-client', '< 3.0', '>= 2.0.2'
s.add_runtime_dependency 'rspec', '~> 3.8'

s.add_development_dependency 'github_changelog_generator', '~> 1.14'
s.add_development_dependency 'rake', '~> 12'
s.add_development_dependency 'webmock', '~> 3'
end
25 changes: 18 additions & 7 deletions lib/airborne.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

require 'airborne/optional_hash_type_expectations'
require 'airborne/path_matcher'
require 'airborne/request_expectations'
require 'airborne/rest_client_requester'
require 'airborne/rack_test_requester'
require 'airborne/base'

RSpec.configure do |config|
RSpec.configure do |config| # rubocop:disable Metrics/BlockLength
config.add_setting :base_url
config.add_setting :match_expected
config.add_setting :match_actual
Expand All @@ -17,12 +19,21 @@
config.add_setting :requester_module
config.add_setting :verify_ssl, default: true
config.before do |example|
config.match_expected = example.metadata[:match_expected].nil? ?
Airborne.configuration.match_expected_default? : example.metadata[:match_expected]
config.match_actual = example.metadata[:match_actual].nil? ?
Airborne.configuration.match_actual_default? : example.metadata[:match_actual]
config.verify_ssl = example.metadata[:verify_ssl].nil? ?
Airborne.configuration.verify_ssl? : example.metadata[:verify_ssl]
config.match_expected = if example.metadata[:match_expected].nil?
Airborne.configuration.match_expected_default?
else
example.metadata[:match_expected]
end
config.match_actual = if example.metadata[:match_actual].nil?
Airborne.configuration.match_actual_default?
else
example.metadata[:match_actual]
end
config.verify_ssl = if example.metadata[:verify_ssl].nil?
Airborne.configuration.verify_ssl?
else
example.metadata[:verify_ssl]
end
end

# Include last since it depends on the configuration already being added
Expand Down
18 changes: 8 additions & 10 deletions lib/airborne/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'json'
require 'active_support'
require 'active_support/core_ext/hash/indifferent_access'
Expand All @@ -7,12 +9,10 @@ class InvalidJsonError < StandardError; end

include RequestExpectations

attr_reader :response, :headers, :body
attr_reader :response

def self.configure
RSpec.configure do |config|
yield config
end
def self.configure(&block)
RSpec.configure(&block)
end

def self.included(base)
Expand Down Expand Up @@ -57,10 +57,6 @@ def options(url, headers = nil)
@response = make_request(:options, url, headers: headers)
end

def response
@response
end

def headers
HashWithIndifferentAccess.new(response.headers)
end
Expand All @@ -70,7 +66,9 @@ def body
end

def json_body
JSON.parse(response.body, symbolize_names: true) rescue fail InvalidJsonError, 'Api request returned invalid json'
JSON.parse(response.body, symbolize_names: true)
rescue StandardError
raise InvalidJsonError, 'Api request returned invalid json'
end

private
Expand Down
9 changes: 5 additions & 4 deletions lib/airborne/optional_hash_type_expectations.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# frozen_string_literal: true

module Airborne
class OptionalHashTypeExpectations
include Enumerable
attr_accessor :hash

def initialize(hash)
@hash = hash
end

def each
@hash.each do|k, v|
yield(k, v)
end
def each(&block)
@hash.each(&block)
end

def [](val)
Expand Down
Loading

0 comments on commit 425273d

Please sign in to comment.