From 8e7ca4f13ec993b1239bf04b1ddafc7c4ec79b44 Mon Sep 17 00:00:00 2001 From: Nsanjayboruds Date: Thu, 29 Jan 2026 13:34:55 +0530 Subject: [PATCH 1/3] Add Ruby + PostgreSQL quickstart guide - Created comprehensive quickstart documentation for Ruby (Sinatra) with PostgreSQL - Added Ruby language support to QuickStartFilter with gem icon - Registered Ruby quickstart in QuickStartList for both Docker and Local setups - Updated sidebar navigation to include Ruby category - Build verified successfully with no errors Signed-off-by: Nsanjayboruds --- src/components/QuickStartFilter.js | 3 +- src/components/QuickStartList.js | 20 ++ .../quickstart/ruby-sinatra-postgres.md | 284 ++++++++++++++++++ .../version-4.0.0-sidebars.json | 9 + 4 files changed, 315 insertions(+), 1 deletion(-) create mode 100644 versioned_docs/version-4.0.0/quickstart/ruby-sinatra-postgres.md diff --git a/src/components/QuickStartFilter.js b/src/components/QuickStartFilter.js index 8e86dfe54..924aa1a02 100644 --- a/src/components/QuickStartFilter.js +++ b/src/components/QuickStartFilter.js @@ -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"; @@ -28,6 +28,7 @@ export default function QuickstartFilter({defaultLanguage = null}) { {name: "Java", icon: , color: "#007396"}, {name: "JS/TS", icon: , color: "#F7DF1E"}, {name: "C#", icon: , color: "#512BD4"}, + {name: "Ruby", icon: , color: "#CC342D"}, ]; const servers = [ diff --git a/src/components/QuickStartList.js b/src/components/QuickStartList.js index 17f9e6e03..8562546e7 100644 --- a/src/components/QuickStartList.js +++ b/src/components/QuickStartList.js @@ -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 /* { diff --git a/versioned_docs/version-4.0.0/quickstart/ruby-sinatra-postgres.md b/versioned_docs/version-4.0.0/quickstart/ruby-sinatra-postgres.md new file mode 100644 index 000000000..57a0ca131 --- /dev/null +++ b/versioned_docs/version-4.0.0/quickstart/ruby-sinatra-postgres.md @@ -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'; + +## 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! ๐ŸŽข + + + +## 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) + + + +## 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!โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ + + + +## 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: + +### 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! โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ diff --git a/versioned_sidebars/version-4.0.0-sidebars.json b/versioned_sidebars/version-4.0.0-sidebars.json index 5ab6d0a00..0af1038e3 100644 --- a/versioned_sidebars/version-4.0.0-sidebars.json +++ b/versioned_sidebars/version-4.0.0-sidebars.json @@ -117,6 +117,15 @@ "items": [ "quickstart/samples-csharp" ] + }, + { + "type": "category", + "label": "Ruby", + "collapsible": true, + "collapsed": true, + "items": [ + "quickstart/samples-ruby" + ] } ] }, From 4f2b408e3b1086e860a5d7d413bbdf3da32ef72f Mon Sep 17 00:00:00 2001 From: Nsanjayboruds Date: Fri, 30 Jan 2026 08:12:54 +0530 Subject: [PATCH 2/3] Address Copilot review comments - improve Docker Compose workflow - Remove standalone docker-compose up --build step - Add clear instructions to stop containers before running tests - Prevent port-in-use conflicts and make workflow clearer - Ensure users stop services after test completion - Build verified successfully with no errors Signed-off-by: Nsanjayboruds --- .../quickstart/ruby-sinatra-postgres.md | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/versioned_docs/version-4.0.0/quickstart/ruby-sinatra-postgres.md b/versioned_docs/version-4.0.0/quickstart/ruby-sinatra-postgres.md index 57a0ca131..36d3a79ae 100644 --- a/versioned_docs/version-4.0.0/quickstart/ruby-sinatra-postgres.md +++ b/versioned_docs/version-4.0.0/quickstart/ruby-sinatra-postgres.md @@ -52,10 +52,12 @@ We will be using Docker compose to run the application as well as PostgreSQL on git clone https://github.com/Nsanjayboruds/keploy-ruby-postgresql-quickstart.git && cd keploy-ruby-postgresql-quickstart ``` -### Build and Start Services +### Lights, Camera, Record! ๐ŸŽฅ + +Capture the test-cases- ```bash -docker-compose up --build +keploy record -c "docker-compose up --build" --container-name "ruby-books-app" ``` This will: @@ -64,25 +66,6 @@ This will: - 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 @@ -135,6 +118,12 @@ 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`. +### Stop the Running Services + +```bash +docker-compose down +``` + Want to see if everything works as expected? ### Run Tests ๐Ÿงช @@ -145,6 +134,12 @@ Time to put things to the test ๐Ÿงช keploy test -c "docker-compose up" --container-name "ruby-books-app" --delay 10 ``` +After tests complete, stop the services: + +```bash +docker-compose down +``` + > 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!โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ From eadbf295205c207c7eb57db5e03173e505f9fdfc Mon Sep 17 00:00:00 2001 From: Nsanjayboruds Date: Mon, 2 Feb 2026 17:41:20 +0530 Subject: [PATCH 3/3] Fix Ruby quickstart - improve Docker workflow and clarity Signed-off-by: Nsanjayboruds --- .../quickstart/ruby-sinatra-postgres.md | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/versioned_docs/version-4.0.0/quickstart/ruby-sinatra-postgres.md b/versioned_docs/version-4.0.0/quickstart/ruby-sinatra-postgres.md index 36d3a79ae..4ce4d840e 100644 --- a/versioned_docs/version-4.0.0/quickstart/ruby-sinatra-postgres.md +++ b/versioned_docs/version-4.0.0/quickstart/ruby-sinatra-postgres.md @@ -57,7 +57,7 @@ git clone https://github.com/Nsanjayboruds/keploy-ruby-postgresql-quickstart.git Capture the test-cases- ```bash -keploy record -c "docker-compose up --build" --container-name "ruby-books-app" +keploy record -c "docker compose up --build" --container-name "ruby-books-app" ``` This will: @@ -121,7 +121,7 @@ And once you are done, you can stop the recording and give yourself a pat on the ### Stop the Running Services ```bash -docker-compose down +docker compose down ``` Want to see if everything works as expected? @@ -131,13 +131,13 @@ Want to see if everything works as expected? Time to put things to the test ๐Ÿงช ```bash -keploy test -c "docker-compose up" --container-name "ruby-books-app" --delay 10 +keploy test -c "docker compose up" --container-name "ruby-books-app" --delay 10 ``` After tests complete, stop the services: ```bash -docker-compose down +docker compose down ``` > The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking. @@ -183,10 +183,12 @@ cp .env.example .env # Edit .env if needed for your local PostgreSQL configuration ``` -### Start the Application +### Start the Application with Keploy + +If the app is already running, stop it before you start recording. ```bash -bundle exec ruby app.rb +keploy record -c "bundle exec ruby app.rb" ``` The API will be available at `http://localhost:8000` @@ -204,7 +206,7 @@ Expected Response: ### Lights, Camera, Record! ๐ŸŽฅ -Capture the test-cases- +If you stopped the app after verification, restart recording: ```bash keploy record -c "bundle exec ruby app.rb" @@ -272,6 +274,12 @@ Time to put things to the test ๐Ÿงช keploy test -c "bundle exec ruby app.rb" --delay 10 ``` +After tests complete, stop the app: + +```bash +Ctrl+C +``` + > 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!โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ