diff options
| author | mo khan <mo@mokhan.ca> | 2025-06-09 13:51:29 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-06-09 13:51:29 -0600 |
| commit | f42e23ad9847e11e86c77623eb77da3355b6d71b (patch) | |
| tree | 1f1cbb1c1ffe1b10f6bd188afd7ece427d8a0b96 /spec | |
| parent | 14c7a0e3ebf77451662bbbac1915facdec0bca3f (diff) | |
test: switch to rspec
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/integration/server_spec.rb | 46 | ||||
| -rw-r--r-- | spec/spec_helper.rb | 28 | ||||
| -rw-r--r-- | spec/support/server.rb | 24 |
3 files changed, 98 insertions, 0 deletions
diff --git a/spec/integration/server_spec.rb b/spec/integration/server_spec.rb new file mode 100644 index 0000000..1271f05 --- /dev/null +++ b/spec/integration/server_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe "Server" do + let(:base_url) { "http://#{RSpec.configuration.bind_addr}" } + let(:client) { Net::Hippie::Client.new } + + describe "GET /" do + it 'returns OK' do + response = client.get(base_url + "/") + expect(response.code).to eq("200") + end + end + + describe "GET /404" do + it 'returns 404' do + response = client.get(base_url + "/404") + expect(response.code).to eq("404") + end + end + + # https://datatracker.ietf.org/doc/html/rfc8414#section-3.1 + describe "GET /.well-known/oauth-authorization-server" do + it 'returns OK' do + response = client.get(base_url + "/.well-known/oauth-authorization-server") + expect(response.code).to eq("200") + expect(response["Content-Type"]).to eq("application/json") + end + end + + # https://datatracker.ietf.org/doc/html/rfc8693#section-2.3 + describe "POST /token" do + pending + end + + # https://datatracker.ietf.org/doc/html/rfc7662#section-2 + describe "POST /introspect" do + pending + end + + # https://datatracker.ietf.org/doc/html/rfc7009#section-2.1 + describe "POST /revoke" do + pending + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..b7fab03 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require "net/hippie" +require "uri" + +Dir[File.join(Dir.pwd, 'spec/support/**/*.rb')].sort.each { |f| require f } + +RSpec.configure do |config| + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + + config.shared_context_metadata_behavior = :apply_to_host_groups + config.filter_run_when_matching :focus + config.disable_monkey_patching! + config.warnings = true + + if config.files_to_run.one? + config.default_formatter = "doc" + end + + config.order = :random + Kernel.srand config.seed +end diff --git a/spec/support/server.rb b/spec/support/server.rb new file mode 100644 index 0000000..2fea6af --- /dev/null +++ b/spec/support/server.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +RSpec.configure do |config| + config.add_setting :bind_addr + config.bind_addr = ENV.fetch("BIND_ADDR", "127.0.0.1:7878") + + config.add_setting :pid + + config.before :suite do + RSpec.configuration.pid = Process.spawn({ + "BIND_ADDR" => RSpec.configuration.bind_addr, + }, "mise exec -- cargo run") + sleep 1 + end + + config.after :suite do + Process.kill('SIGTERM', RSpec.configuration.pid) + system("killall sts") + end +end + +at_exit do + system("killall sts") +end |
