Skip to content

tetsuya/sinatra-hello-world

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sinatra-hello-world

A simple Sinatra web application with Rake tasks and testing setup.

Setup

  1. Install Ruby 3.3.5 (check .ruby-version for the exact version)

  2. Install dependencies:

    bundle install

Running the App

Development Server

bundle exec rackup config.ru

The app will be available at http://localhost:9292

Production (Heroku)

The app is configured to run on Heroku using the Procfile. Heroku automatically runs:

bundle exec puma config.ru -p $PORT

Testing

Run the full test suite:

bundle exec rspec

Run specific test files:

bundle exec rspec spec/app_spec.rb
bundle exec rspec spec/tasks/greeting_spec.rb

Linting

This project uses Standard Ruby for code formatting and linting.

Check for style violations:

bundle exec standardrb

Auto-fix style violations:

bundle exec standardrb --fix

Routes

  • GET / - Returns "Hello, world!"
  • GET /h12 - Demonstrates Heroku H12 timeout (sleeps for 31 seconds)

Rake Tasks

The application includes custom Rake tasks:

Available Tasks

# List all available tasks
bundle exec rake -T

Greeting Tasks

# English greeting
bundle exec rake greeting:english

# Japanese greeting  
bundle exec rake greeting:japanese

Setting Up New Tasks

  1. Create a new .rake file in lib/tasks/
  2. Define your task using the standard Rake syntax:
    namespace :your_namespace do
      task :your_task do
        # Task implementation
      end
    end
  3. Tasks are automatically loaded via the Rakefile

Project Structure

├── app/
│   ├── controllers/     # Application controllers
│   ├── views/          # View templates
│   └── public/         # Static assets
├── lib/
│   └── tasks/          # Custom Rake tasks
├── spec/               # Test files
├── app.rb              # Main application file
├── config.ru           # Rack configuration
└── Rakefile            # Rake configuration

About

Resources

Stars

Watchers

Forks