1
0

More than 3 years have passed since last update.

設計と実装をRailsでシームレスに行う(API仕様書)

Last updated at Posted at 2020-08-27

目的

  • API仕様書のメンテコストをなくす
  • 実装に前倒しで着手する

前提

  • フレームワークにRailsを使用する
  • Railsの環境構築を行う

手順

  1. Gemfileにgemを指定してbundle installする
  2. spec/request/xxxx_spec.rbにテストケースを書く
  3. AUTODOC=1 bundle exec rspec spec/requests/xxxx_spec.rbを実行する

1. Gemfileにgemを指定してbundle installする

group :development do
 gem 'autodoc'
end

2. spec/request/xxxx_spec.rbにテストケースを書く


require 'rails_helper'

RSpec.describe "Api::V1::Users", type: :request, autodoc: true do
 describe "GET /api/v1/users/:id" do
   it "ユーザー詳細API" do
     get api_v1_user_path(1)
     expect(response).to have_http_status(200)
   end
 end

 describe "PUT /api/v1/users/:id" do
   it "ユーザー編集API" do
     require 'json'
     file = File.read("#{Rails.root}/sample-json/users-update.json")
     params = JSON.parse(file)
     put api_v1_user_path(1), params: params, as: :json
     expect(response).to have_http_status(200)
   end
 end
end

3. AUTODOC=1 bundle exec rspec spec/requests/xxxx_spec.rbを実行する

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0