Skip to content

ci: test against Ruby 3.3 #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
matrix:
include:
# Recent Rubies and Rails
- ruby-version: '3.3'
- ruby-version: '3.2'
- ruby-version: '3.1'
- ruby-version: '3.0'
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec_api_documentation/api_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module RspecApiDocumentation
class ApiFormatter < RSpec::Core::Formatters::BaseTextFormatter
RSpec::Core::Formatters.register self, :example_passed, :example_failed, :stop
RSpec::Core::Formatters.register self, :example_passed, :example_failed, :stop, :example_group_started

def initialize(output)
super
Expand All @@ -19,7 +19,7 @@ def start(notification)
def example_group_started(notification)
super

output.puts " #{@example_group.description}"
output.puts " #{notification.group.description}"
end

def example_passed(example_notification)
Expand Down
9 changes: 8 additions & 1 deletion lib/rspec_api_documentation/client_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def process(method, path, params = {}, headers ={})

def read_request_body
input = last_request.env["rack.input"]
input.rewind
return "" unless input
input.rewind if input.respond_to?(:rewind)
input.read
end

Expand Down Expand Up @@ -89,6 +90,12 @@ def record_response_body(response_content_type, response_body)
return nil if response_body.empty?

formatter = RspecApiDocumentation.configuration.response_body_formatter
# Only force UTF-8 for text-based content types
if response_body.respond_to?(:encoding) && response_body.encoding == Encoding::ASCII_8BIT
if response_content_type && (response_content_type.include?('json') || response_content_type.include?('text'))
response_body = response_body.force_encoding(Encoding::UTF_8)
end
end
formatter.call(response_content_type, response_body)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rspec_api_documentation/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def env_to_headers(env)
headers = {}
env.each do |key, value|
# HTTP_ACCEPT_CHARSET => Accept-Charset
if key =~ /^(HTTP_|CONTENT_TYPE)/
if key =~ /^(HTTP_|CONTENT_TYPE)/ && key != "HTTP_VERSION"
header = key.gsub(/^HTTP_/, '').split('_').map{|s| s.titleize}.join("-")
headers[header] = value
end
Expand Down
3 changes: 2 additions & 1 deletion lib/rspec_api_documentation/open_api/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ def as_json
end
end

def settings; @settings ||= {} end

private

def settings; @settings ||= {} end
def instance_settings; @instance_settings ||= [] end
def self.class_settings; @class_settings ||= [] end
end
Expand Down
62 changes: 43 additions & 19 deletions rspec_api_documentation.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,52 @@ Gem::Specification.new do |s|
s.required_rubygems_version = ">= 1.3.6"

s.add_runtime_dependency "rspec", "~> 3.0"
s.add_development_dependency "rspec", "~> 3.0"
s.add_runtime_dependency "activesupport", ">= 3.0.0"
s.add_runtime_dependency "mustache", "~> 1.0", ">= 0.99.4"

s.add_development_dependency "bundler", ">= 1.16"
s.add_development_dependency "fakefs", "~> 0.6.0"
s.add_development_dependency "sinatra", "~> 2.0.8"
s.add_development_dependency "aruba", "~> 0.14.14"
s.add_development_dependency "capybara", "~> 3.39.2"
s.add_development_dependency "rake", "~> 13.2.1"
s.add_development_dependency "rack-test", "~> 0.6.3"
s.add_development_dependency "rack-oauth2", "~> 1.12.0"
s.add_development_dependency "webmock", "~> 3.23.0"
s.add_development_dependency "rspec-its", "~> 1.3.0"
s.add_development_dependency "faraday", "~> 1.0.0"
s.add_development_dependency "nokogiri", "~> 1.8.4"
s.add_development_dependency "yard", "~> 0.9.15"
s.add_development_dependency "inch", "~> 0.8.0"
s.add_development_dependency "minitest", "~> 5.8.4"
s.add_development_dependency "contracts", "~> 0.17"
s.add_development_dependency "gherkin", "~> 9.0.0"
s.add_development_dependency "multi_json", "~> 1.15.0"
s.add_development_dependency "rspec", "~> 3.0"
if RUBY_VERSION < '2.7'
s.add_development_dependency "bundler", ">= 1.16"
s.add_development_dependency "fakefs", "~> 0.6.0"
s.add_development_dependency "sinatra", "~> 1.4.7"
s.add_development_dependency "aruba", "~> 0.13.0"
s.add_development_dependency "capybara", "~> 2.6.2"
s.add_development_dependency "rake", "~> 10.5.0"
s.add_development_dependency "rack-test", "~> 0.6.3"
s.add_development_dependency "rack-oauth2", "~> 1.2.2"
s.add_development_dependency "webmock", "~> 3.8.3"
s.add_development_dependency "rspec-its", "~> 1.2.0"
s.add_development_dependency "faraday", "~> 1.0.0"
s.add_development_dependency "nokogiri", "~> 1.8.4"
s.add_development_dependency "yard", "~> 0.9.15"
s.add_development_dependency "inch", "~> 0.8.0"
s.add_development_dependency "minitest", "~> 5.8.4"
s.add_development_dependency "contracts", "~> 0.13.0"
s.add_development_dependency "gherkin", "~> 3.2.0"
s.add_development_dependency "multi_json", "~> 1.11.2"
else
s.add_development_dependency "bundler", ">= 1.16"
s.add_development_dependency "fakefs"
s.add_development_dependency "sinatra", "~> 2.0"
s.add_development_dependency "aruba"
s.add_development_dependency "capybara"
s.add_development_dependency "rake"
s.add_development_dependency "rack", "~> 2.2"
s.add_development_dependency "rack-test"
s.add_development_dependency "rack-oauth2"
s.add_development_dependency "webmock"
s.add_development_dependency "rspec-its"
s.add_development_dependency "faraday"
s.add_development_dependency "nokogiri"
s.add_development_dependency "yard"
s.add_development_dependency "inch"
s.add_development_dependency "minitest"
s.add_development_dependency "contracts"
s.add_development_dependency "gherkin"
s.add_development_dependency "multi_json"
s.add_development_dependency "webrick"
s.add_development_dependency "rackup"
end

s.files = Dir.glob("lib/**/*") + Dir.glob("templates/**/*")
s.require_path = "lib"
Expand Down
13 changes: 12 additions & 1 deletion spec/api_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

describe RspecApiDocumentation::ApiFormatter do
let(:metadata) { {} }
let(:group) { RSpec::Core::ExampleGroup.describe("Orders", metadata) }
let(:group) {
# Create an anonymous class that inherits from ExampleGroup but doesn't auto-register
Class.new(RSpec::Core::ExampleGroup) do
def self.description
"Orders"
end

def self.metadata
{}
end
end
}
let(:output) { StringIO.new }
let(:formatter) { RspecApiDocumentation::ApiFormatter.new(output) }

Expand Down
2 changes: 1 addition & 1 deletion spec/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
end

context "when the example is pending" do
let(:rspec_example) { rspec_example_group.pending(description, metadata) {} }
let(:rspec_example) { rspec_example_group.pending(description, metadata) { raise "Pending example" } }

it { should be_falsey }
end
Expand Down
4 changes: 2 additions & 2 deletions spec/http_test_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
require 'rack/test'
require 'capybara'
require 'capybara/server'
require 'sinatra/base'
require 'webmock/rspec'
require 'support/stub_app'

describe RspecApiDocumentation::HttpTestClient do
before(:all) do
WebMock.allow_net_connect!
server = Capybara::Server.new(StubApp.new, 8888)
Capybara.server = :webrick
server = Capybara::Server.new(StubApp.new, port: 8888)
server.boot
end

Expand Down
3 changes: 1 addition & 2 deletions spec/rack_test_client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require 'spec_helper'
require 'rack/test'
require 'sinatra/base'
require 'support/stub_app'

describe RspecApiDocumentation::RackTestClient do
let(:context) { |example| double(:app => StubApp, :example => example) }
let(:context) { |example| double(:app => StubApp.new, :example => example) }
let(:test_client) { RspecApiDocumentation::RackTestClient.new(context, {}) }

subject { test_client }
Expand Down
12 changes: 12 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@
require 'pry'

RSpec.configure do |config|
config.before(:all) do
if self.class.metadata[:api_doc_dsl] || self.respond_to?(:app)
begin
require 'support/stub_app'
RspecApiDocumentation.configure do |config|
config.app = StubApp.new unless config.app
end
rescue LoadError
# StubApp not available, skip
end
end
end
end
54 changes: 26 additions & 28 deletions spec/support/stub_app.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
class StubApp < Sinatra::Base
get "/" do
content_type :json

{ :hello => "world" }.to_json
end

post "/greet" do
content_type :json

request.body.rewind
begin
data = JSON.parse request.body.read
rescue JSON::ParserError
request.body.rewind
data = request.body.read
class StubApp
def call(env)
req = Rack::Request.new(env)

case "#{req.request_method} #{req.path_info}"
when "GET /"
[200, {'Content-Type' => 'application/json'}, [{ :hello => "world" }.to_json]]
when "POST /greet"
body = req.body.read
req.body.rewind if req.body.respond_to?(:rewind)

begin
data = JSON.parse(body) if body && !body.empty?
rescue JSON::ParserError
data = nil
end

target = data.is_a?(Hash) ? data["target"] : "nurse"
[200, {'Content-Type' => 'application/json', 'Content-Length' => '17'}, [{ :hello => target }.to_json]]
when "GET /xml"
[200, {'Content-Type' => 'application/xml'}, ["<hello>World</hello>"]]
when "GET /binary"
[200, {'Content-Type' => 'application/octet-stream'}, ["\x01\x02\x03".force_encoding(Encoding::ASCII_8BIT)]]
else
[404, {'Content-Type' => 'text/plain'}, ["Not Found"]]
end
{ :hello => data["target"] }.to_json
end

get "/xml" do
content_type :xml

"<hello>World</hello>"
end

get '/binary' do
content_type 'application/octet-stream'
"\x01\x02\x03".force_encoding(Encoding::ASCII_8BIT)
end
end

Loading