Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/QuickStartFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {useState} from "react";
import quickstarts from "./QuickStartList";
import Link from "@docusaurus/Link";
import {FaGolang} from "react-icons/fa6";
import {FaJava, FaLaptopCode, FaDocker, FaPython, FaCheck, FaArrowRight, FaArrowLeft} from "react-icons/fa";
import {FaJava, FaLaptopCode, FaDocker, FaPython, FaCheck, FaArrowRight, FaArrowLeft, FaGem} from "react-icons/fa";
import {TbBrandCSharp} from "react-icons/tb";
import {IoLogoJavascript} from "react-icons/io5";
import {useColorMode} from "@docusaurus/theme-common";
Expand All @@ -28,6 +28,7 @@ export default function QuickstartFilter({defaultLanguage = null}) {
{name: "Java", icon: <FaJava size={24} />, color: "#007396"},
{name: "JS/TS", icon: <IoLogoJavascript size={24} />, color: "#F7DF1E"},
{name: "C#", icon: <TbBrandCSharp size={24} />, color: "#512BD4"},
{name: "Ruby", icon: <FaGem size={24} />, color: "#CC342D"},
];

const servers = [
Expand Down
20 changes: 20 additions & 0 deletions src/components/QuickStartList.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,26 @@ const quickstarts = [
link: "/docs/quickstart/flask-redis/",
},

// Ruby list

{
title: "Ruby + Postgres",
language: "Ruby",
server: "Docker",
description:
"A sample Books CRUD API to demonstrate how seamlessly Keploy integrates with Ruby (Sinatra) and PostgreSQL.",
link: "/docs/quickstart/samples-ruby/#using-docker-compose-",
},

{
title: "Ruby + Postgres",
language: "Ruby",
server: "Local",
description:
"A sample Books CRUD API to demonstrate how seamlessly Keploy integrates with Ruby (Sinatra) and PostgreSQL.",
link: "/docs/quickstart/samples-ruby/#running-app-locally-on-linuxwsl-",
},

//Javascript list

/* {
Expand Down
284 changes: 284 additions & 0 deletions versioned_docs/version-4.0.0/quickstart/ruby-sinatra-postgres.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
---
id: samples-ruby
title: Sample Books API
sidebar_label: Ruby + Postgres
description: The following sample app showcases how to use the Ruby (Sinatra) framework and the Keploy Platform.
tags:
- ruby
- quickstart
- samples
- examples
- tutorial
- sinatra
- postgresql
- ruby-framework
keyword:
- Sinatra Framework
- PostgreSQL
- Ruby
- API Test generator
- Auto case generation
---

import InstallReminder from '@site/src/components/InstallReminder';
import SectionDivider from '@site/src/components/SectionDivider';
Comment on lines +23 to +24
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ProductTier component is missing. Almost all other quickstart guides in the codebase include this component to indicate which Keploy tiers and offerings support the quickstart. For consistency with other guides, this should be added after the imports and before the Introduction section. Based on the pattern seen in other open-source compatible quickstarts (like C#, Django, FastAPI), it should likely be: <ProductTier tiers="Open Source, Enterprise" offerings="Self-Hosted, Dedicated" />

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +24
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import statement for ProductTier component is missing. Looking at other quickstart guides in the codebase (e.g., csharp-dotnet-postgres.md:24, python-django-sql.md:32), ProductTier should be imported alongside other components. Add import ProductTier from '@site/src/components/ProductTier'; with the other import statements.

Copilot uses AI. Check for mistakes.

## Introduction

πŸͺ„ Dive into the world of Books CRUD API and see how seamlessly Keploy integrates with [Ruby (Sinatra)](http://sinatrarb.com/) and [PostgreSQL](https://www.postgresql.org/). Buckle up, it's gonna be a fun ride! 🎒

<InstallReminder />

## Prerequisites

### For Local Setup:
- Ruby 3.2 or higher
- PostgreSQL 15 or higher
- Bundler (`gem install bundler`)

### For Docker Setup:
- Docker (20.10 or higher)
- Docker Compose (v2.0 or higher)

<SectionDivider />

## Using Docker Compose 🐳

We will be using Docker compose to run the application as well as PostgreSQL on Docker container.

### Clone the Application πŸ§ͺ

```bash
git clone https://github.com/Nsanjayboruds/keploy-ruby-postgresql-quickstart.git && cd keploy-ruby-postgresql-quickstart
```

### Build and Start Services

```bash
docker-compose up --build
```

This will:
- Start a PostgreSQL container
- Build and start the Ruby application container
- Initialize the database with sample data
- Expose the API on port 8000

### Verify the Setup

```bash
curl http://localhost:8000/health
```

Expected Response:
```json
{"status":"healthy","service":"Ruby Books API"}
```

### Lights, Camera, Record! πŸŽ₯

Capture the test-cases-

```bash
keploy record -c "docker-compose up" --container-name "ruby-books-app"
```

πŸ”₯**Make some API calls**. Postman, Hoppscotch or even curl - take your pick!

### Generate Testcases

To generate testcases we just need to **make some API calls.**

#### 1. Get All Books

```bash
curl http://localhost:8000/books
```

#### 2. Get a Specific Book

```bash
curl http://localhost:8000/books/1
```

#### 3. Create a New Book

```bash
curl -X POST http://localhost:8000/books \
-H "Content-Type: application/json" \
-d '{
"title": "The Hobbit",
"author": "J.R.R. Tolkien",
"isbn": "9780547928227",
"published_year": 1937
}'
```

#### 4. Update a Book

```bash
curl -X PUT http://localhost:8000/books/1 \
-H "Content-Type: application/json" \
-d '{
"title": "The Great Gatsby (Updated)",
"author": "F. Scott Fitzgerald",
"isbn": "9780743273565",
"published_year": 1925
}'
```

#### 5. Delete a Book

```bash
curl -X DELETE http://localhost:8000/books/1
```

And once you are done, you can stop the recording and give yourself a pat on the back! With that simple spell, you've conjured up test cases with mocks! Explore the **keploy** directory and you'll discover your handiwork in the `tests` directory and `mocks.yml`.

Want to see if everything works as expected?

### Run Tests πŸ§ͺ

Time to put things to the test πŸ§ͺ

```bash
keploy test -c "docker-compose up" --container-name "ruby-books-app" --delay 10
```

> The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking.

Final thoughts? Dive deeper! Try different API calls, tweak the DB response in the `mocks.yml`, or fiddle with the request or response in `test-x.yml`. Run the tests again and see the magic unfold!βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨

<SectionDivider />

## Running App Locally on Linux/WSL 🐧

We'll be running our sample application locally on Linux/WSL. There are 2 ways you can run this application:
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The statement "There are 2 ways you can run this application:" is misleading because only one way (local setup) is presented in this section. This text should either be removed or corrected to say "We'll be running our sample application locally on Linux/WSL." to match the actual content structure.

Suggested change
We'll be running our sample application locally on Linux/WSL. There are 2 ways you can run this application:
We'll be running our sample application locally on Linux/WSL.

Copilot uses AI. Check for mistakes.

### Clone the Application πŸ§ͺ

```bash
git clone https://github.com/Nsanjayboruds/keploy-ruby-postgresql-quickstart.git && cd keploy-ruby-postgresql-quickstart
```

### Install Dependencies

```bash
bundle install
```

### Set up PostgreSQL Database

Create the database:

```bash
createdb booksdb
```

Initialize the database with the schema:

```bash
psql -d booksdb -f init.sql
```

### Configure Environment Variables

```bash
cp .env.example .env
# Edit .env if needed for your local PostgreSQL configuration
```

### Start the Application

```bash
bundle exec ruby app.rb
```

The API will be available at `http://localhost:8000`

### Verify the Setup

```bash
curl http://localhost:8000/health
```

Expected Response:
```json
{"status":"healthy","service":"Ruby Books API"}
```

### Lights, Camera, Record! πŸŽ₯

Capture the test-cases-

```bash
keploy record -c "bundle exec ruby app.rb"
```

πŸ”₯**Make some API calls**. Postman, Hoppscotch or even curl - take your pick!

### Generate Testcases

To generate testcases we just need to **make some API calls.**

#### 1. Get All Books

```bash
curl http://localhost:8000/books
```

#### 2. Get a Specific Book

```bash
curl http://localhost:8000/books/1
```

#### 3. Create a New Book

```bash
curl -X POST http://localhost:8000/books \
-H "Content-Type: application/json" \
-d '{
"title": "The Hobbit",
"author": "J.R.R. Tolkien",
"isbn": "9780547928227",
"published_year": 1937
}'
```

#### 4. Update a Book

```bash
curl -X PUT http://localhost:8000/books/1 \
-H "Content-Type: application/json" \
-d '{
"title": "The Great Gatsby (Updated)",
"author": "F. Scott Fitzgerald",
"isbn": "9780743273565",
"published_year": 1925
}'
```

#### 5. Delete a Book

```bash
curl -X DELETE http://localhost:8000/books/1
```

And once you are done, you can stop the recording and give yourself a pat on the back! With that simple spell, you've conjured up test cases with mocks! Explore the **keploy** directory and you'll discover your handiwork in the `tests` directory and `mocks.yml`.

Want to see if everything works as expected?

### Run Tests πŸ§ͺ

Time to put things to the test πŸ§ͺ

```bash
keploy test -c "bundle exec ruby app.rb" --delay 10
```

> The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking.

Final thoughts? Dive deeper! Try different API calls, tweak the DB response in the `mocks.yml`, or fiddle with the request or response in `test-x.yml`. Run the tests again and see the magic unfold!βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨

Happy coding! βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨
9 changes: 9 additions & 0 deletions versioned_sidebars/version-4.0.0-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@
"items": [
"quickstart/samples-csharp"
]
},
{
"type": "category",
"label": "Ruby",
"collapsible": true,
"collapsed": true,
"items": [
"quickstart/samples-ruby"
]
}
]
},
Expand Down
Loading