Commit 0664daf
Changed files (5)
doc/_includes/curl.erb
@@ -0,0 +1,41 @@
+<% @configuration['http_interactions'].each do |interaction| %>
+#### <%= interaction['request']['method'].upcase %> <%= interaction['request']['uri'].gsub(/\h{8}-\h{4}-\h{4}-\h{4}-\h{12}/, ':id') %>
+
+Example curl request:
+
+<% headers = interaction['request']['headers'].map { |(key, value)| "-H \"#{key}: #{value[0]}\"" } %>
+```bash
+$ curl <%= interaction['request']['uri'] %> \
+ -X <%= interaction['request']['method'].upcase %> \
+ -d '<%= interaction['request']['body']['string'] %>' \
+ <%= headers.join(" \\\n ") %>
+```
+Request Headers:
+
+<% headers = interaction['request']['headers'].map { |(key, value)| "#{key}: #{value[0]}" } %>
+```text
+<%= headers.join("\n") %>
+```
+<% json = JSON.parse(interaction['request']['body']['string']) rescue {} %>
+<% if json.present? %>
+Request Body:
+```json
+<%= JSON.pretty_generate(json) %>
+```
+<% end %>
+
+Response Headers:
+
+<% headers = interaction['response']['headers'].map { |(key, value)| "#{key}: #{value[0]}" } %>
+```text
+<%= headers.join("\n") %>
+```
+<% json = JSON.parse(interaction['response']['body']['string']) rescue {} %>
+<% if json.present? %>
+Response Body:
+
+```json
+<%= JSON.pretty_generate(json) %>
+```
+<% end %>
+<% end %>
spec/documentation.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+require File.expand_path('../../config/environment', __FILE__)
+require 'rspec/rails'
+require 'vcr'
+require 'ffaker'
+require 'factory_bot_rails'
+
+RSpec.configure do |config|
+ config.include FactoryBot::Syntax::Methods
+ config.before :suite do
+ FileUtils.rm_rf(Rails.root.join('doc/_cassettes/'))
+ VCR.configure do |x|
+ x.cassette_library_dir = "doc/_cassettes"
+ x.hook_into :webmock
+ end
+ end
+
+ config.after :suite do
+ template = IO.read('doc/_includes/curl.erb')
+ erb = ERB.new(template)
+ Dir["doc/_cassettes/**/*.yml"].each do |cassette|
+ @configuration = YAML.safe_load(IO.read(cassette))
+ result = erb.result(binding)
+ IO.write("doc/_includes/#{File.basename(cassette).parameterize.gsub(/-yml/, '')}.html", result)
+ end
+ end
+end
+
+RSpec.describe "documentation" do
+ let(:client) { Net::Hippie::Client.new(verify_mode: OpenSSL::SSL::VERIFY_NONE) }
+ let(:host) { ENV.fetch('HOST', 'proof.test') }
+ let(:scheme) { ENV.fetch('SCHEME', 'https') }
+
+ specify do
+ VCR.use_cassette("get-well-known-oauth-authorization-server") do
+ response = client.get("#{scheme}://#{host}/.well-known/oauth-authorization-server")
+ expect(response.code).to eql('200')
+ end
+ end
+end
.gitignore
@@ -41,3 +41,4 @@ pkg
BUILD
.sass-cache
public/doc
+doc/_cassettes/
Gemfile
@@ -41,6 +41,7 @@ group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'i18n-tasks', '~> 0.9.24'
gem 'rspec-rails', '~> 3.8'
+ gem 'vcr', '~> 4.0'
end
group :test do
gem 'capybara', '~> 3.6'
Gemfile.lock
@@ -292,6 +292,7 @@ GEM
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.4.0)
+ vcr (4.0.0)
web-console (3.7.0)
actionview (>= 5.0)
activemodel (>= 5.0)
@@ -359,6 +360,7 @@ DEPENDENCIES
selenium-webdriver (~> 3.14)
spank (~> 1.0)
turbolinks (~> 5)
+ vcr (~> 4.0)
web-console (>= 3.3.0)
webmock (~> 3.4)
webpacker (~> 3.5)