First draft of example single file roda app

This commit is contained in:
James 2025-07-02 03:38:16 -05:00
parent 671955a386
commit 514108bfc9
8 changed files with 143 additions and 2 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
/.rake_tasks~
/temp.db
/vendor/
/bin/

15
Gemfile Normal file
View file

@ -0,0 +1,15 @@
source "https://rubygems.org"
gem "roda"
# change to gunicorn or passenger if you prefer:
gem "puma"
group :development, :test do
gem "rerun"
end
group :test do
gem 'capybara'
gem 'minitest'
end

65
Gemfile.lock Normal file
View file

@ -0,0 +1,65 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
capybara (3.40.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.11)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
ffi (1.17.2)
ffi (1.17.2-arm64-darwin)
ffi (1.17.2-x86_64-darwin)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
matrix (0.4.3)
mini_mime (1.1.5)
mini_portile2 (2.8.9)
minitest (5.25.5)
nio4r (2.7.4)
nokogiri (1.18.8)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.18.8-arm64-darwin)
racc (~> 1.4)
nokogiri (1.18.8-x86_64-darwin)
racc (~> 1.4)
public_suffix (6.0.2)
puma (6.6.0)
nio4r (~> 2.0)
racc (1.8.1)
rack (3.1.16)
rack-test (2.2.0)
rack (>= 1.3)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
regexp_parser (2.10.0)
rerun (0.14.0)
listen (~> 3.0)
roda (3.93.0)
rack
xpath (3.2.0)
nokogiri (~> 1.8)
PLATFORMS
arm64-darwin
ruby
x86_64-darwin
x86_64-linux
DEPENDENCIES
capybara
minitest
puma
rerun
roda
BUNDLED WITH
2.6.9

View file

@ -1,3 +1,3 @@
# roda-step1-single-file-ish # Roda step 1 - Single File app (sort of)
Example single file Roda web app. There are extra files for launching the server, running tests, the license, etc, but the app itself is all in app.rb. Example single file Roda web app. There are extra files for launching the server, running tests, the license, etc, but the app itself is all in app.rb.

11
app.rb Normal file
View file

@ -0,0 +1,11 @@
require "roda"
class App < Roda
route do |r|
r.on do
"Hello World!"
end
end
end

3
config.ru Normal file
View file

@ -0,0 +1,3 @@
require "./app"
run App.freeze.app

17
myapp.service Normal file
View file

@ -0,0 +1,17 @@
[Unit]
Description=My roda template
After=network.target
[Service]
User=myapp
Group=myapp
WorkingDirectory=/opt/myapp
Environment=RACK_ENV=production
ExecStart=/usr/bin/puma
TimeoutStopSec=300
KillMode=mixed
Restart=on-failure
[Install]
WantedBy=multi-user.target

26
test_app.rb Normal file
View file

@ -0,0 +1,26 @@
require 'minitest/autorun'
require 'capybara/minitest'
require_relative 'app'
Capybara.app = App
class AppTest < Minitest::Test
include Capybara::DSL
include Capybara::Minitest::Assertions
def teardown
Capybara.reset_sessions!
Capybara.use_default_driver
end
# always passes, just to make sure tests are running
def test_the_truth
assert true
end
def test_home_page_exists
visit '/'
assert_equal 200, page.status_code
end
end