Skip to content

Commit

Permalink
Added request spec for api
Browse files Browse the repository at this point in the history
  • Loading branch information
taketo1113 committed Dec 24, 2021
1 parent 643f3b3 commit 25bb3e3
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ group :development, :test do
gem 'capybara'
gem 'webrat'
gem 'factory_bot_rails'
gem 'committee-rails'
# gem 'selenium-webdriver'
end

Expand Down
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ GEM
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
choice (0.2.0)
committee (4.4.0)
json_schema (~> 0.14, >= 0.14.3)
openapi_parser (>= 0.11.1, < 1.0)
rack (>= 1.5)
committee-rails (0.5.1)
actionpack
activesupport
committee (>= 3.0.0)
railties
concurrent-ruby (1.1.9)
crass (1.0.6)
diff-lcs (1.4.4)
Expand All @@ -93,6 +102,7 @@ GEM
concurrent-ruby (~> 1.0)
jbuilder (2.11.3)
activesupport (>= 5.0.0)
json_schema (0.21.0)
listen (3.7.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand All @@ -113,6 +123,7 @@ GEM
nokogiri (1.12.5)
mini_portile2 (~> 2.6.1)
racc (~> 1.4)
openapi_parser (0.15.0)
public_suffix (4.0.6)
puma (5.5.2)
nio4r (~> 2.0)
Expand Down Expand Up @@ -239,6 +250,7 @@ DEPENDENCIES
bootsnap (>= 1.4.4)
byebug
capybara
committee-rails
factory_bot_rails
jbuilder (~> 2.7)
listen (~> 3.3)
Expand Down
72 changes: 72 additions & 0 deletions docs/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
openapi: 3.0.0
info:
title: Say
version: '1.0'
contact:
name: Taketo Takashima
email: [email protected]
description: Say API Spec
servers:
- url: 'http://localhost:3000'
- url: 'https://sayy.herokuapp.com'
description: ''
paths:
'/messages/{messageId}':
get:
summary: GET message
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Message'
'404':
description: Not Found
operationId: get-messages-1
description: Get message
tags:
- say
parameters:
- schema:
type: integer
name: messageId
in: path
required: true
description: Message ID
components:
schemas:
Message:
description: ''
type: object
x-examples:
sample:
id: 1
body: げんざいこしょうはありません
created_at: '2021-01-01T12:00:00.000+09:00'
updated_at: '2021-01-01T12:00:00.000+09:00'
properties:
id:
type: integer
example: 1
body:
type: string
minLength: 1
example: げんざいこしょうはありません
created_at:
type: string
minLength: 1
format: date-time
example: '2021-01-01T12:00:00.000+09:00'
updated_at:
type: string
minLength: 1
format: date-time
example: '2021-01-01T12:00:00.000+09:00'
required:
- id
- body
- created_at
- updated_at
tags:
- name: say
5 changes: 5 additions & 0 deletions spec/requests/messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
get message_path(@message)
expect(response.status).to be(200)
end

it "api spec" do
get message_path(@message, format: :json)
assert_response_schema_confirm(200)
end
end

describe "GET /messages/edit/1" do
Expand Down
10 changes: 10 additions & 0 deletions spec/support/committee_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RSpec.configure do |config|
config.add_setting :committee_options
config.committee_options = {
schema_path: Rails.root.join('docs', 'api.yaml').to_s,
query_hash_key: 'rack.request.query_hash',
parse_response_by_content_type: false,
}

include Committee::Rails::Test::Methods
end

0 comments on commit 25bb3e3

Please sign in to comment.