From dfcea7ad3700df3140f1f28fc6aba32e39efba08 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Sat, 6 Jul 2024 16:06:53 -0500 Subject: [PATCH] Add a unit test --- .gitea/workflows/demo.yaml | 16 ++++++++++++++++ Gemfile | 2 ++ Gemfile.lock | 7 +++++++ app_test.rb | 19 +++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 app_test.rb diff --git a/.gitea/workflows/demo.yaml b/.gitea/workflows/demo.yaml index d1b1a36..f2c09b9 100644 --- a/.gitea/workflows/demo.yaml +++ b/.gitea/workflows/demo.yaml @@ -4,7 +4,23 @@ run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 on: [push] jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Test + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + bundler-cache: true + + - run: ruby app_test.rb + + release-image: + needs: test runs-on: ubuntu-latest container: image: catthehacker/ubuntu:act-latest diff --git a/Gemfile b/Gemfile index e88bc08..467acf6 100644 --- a/Gemfile +++ b/Gemfile @@ -17,4 +17,6 @@ group :development do gem "ruby-lsp" gem "rubocop" gem "rbs" + gem "rack-test" + gem "test-unit" end diff --git a/Gemfile.lock b/Gemfile.lock index 8942f7e..477fa6c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,6 +19,7 @@ GEM parser (3.3.3.0) ast (~> 2.4.1) racc + power_assert (2.0.3) prism (0.30.0) puma (6.4.2) nio4r (~> 2.0) @@ -29,6 +30,8 @@ GEM rack (>= 3.0.0, < 4) rack-session (2.0.0) rack (>= 3.0.0) + rack-test (2.1.0) + rack (>= 1.3) rackup (2.1.0) rack (>= 3) webrick (~> 1.8) @@ -72,6 +75,8 @@ GEM tilt (~> 2.0) sorbet-runtime (0.5.11435) strscan (3.1.0) + test-unit (3.6.2) + power_assert tilt (2.3.0) ulid (1.4.0) unicode-display_width (2.5.0) @@ -90,12 +95,14 @@ DEPENDENCIES ksuid nanoid puma + rack-test rackup rbs rubocop ruby-lsp sinatra sinatra-contrib + test-unit ulid uuid7 diff --git a/app_test.rb b/app_test.rb new file mode 100644 index 0000000..450f709 --- /dev/null +++ b/app_test.rb @@ -0,0 +1,19 @@ +ENV['APP_ENV'] = 'test' + +require './app' +require 'test/unit' +require 'rack/test' + +class ToyTest < Test::Unit::TestCase + include Rack::Test::Methods + + def app + Sinatra::Application + end + + def test_root + get '/' + assert last_response.ok? + assert_equal "hello there!".encode("ASCII"), last_response.body + end +end