Skip to content

Commit 8e7ca4f

Browse files
committed
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 <nishantborude555@gmail.com>
1 parent fa61c27 commit 8e7ca4f

4 files changed

Lines changed: 315 additions & 1 deletion

File tree

β€Žsrc/components/QuickStartFilter.jsβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, {useState} from "react";
22
import quickstarts from "./QuickStartList";
33
import Link from "@docusaurus/Link";
44
import {FaGolang} from "react-icons/fa6";
5-
import {FaJava, FaLaptopCode, FaDocker, FaPython, FaCheck, FaArrowRight, FaArrowLeft} from "react-icons/fa";
5+
import {FaJava, FaLaptopCode, FaDocker, FaPython, FaCheck, FaArrowRight, FaArrowLeft, FaGem} from "react-icons/fa";
66
import {TbBrandCSharp} from "react-icons/tb";
77
import {IoLogoJavascript} from "react-icons/io5";
88
import {useColorMode} from "@docusaurus/theme-common";
@@ -28,6 +28,7 @@ export default function QuickstartFilter({defaultLanguage = null}) {
2828
{name: "Java", icon: <FaJava size={24} />, color: "#007396"},
2929
{name: "JS/TS", icon: <IoLogoJavascript size={24} />, color: "#F7DF1E"},
3030
{name: "C#", icon: <TbBrandCSharp size={24} />, color: "#512BD4"},
31+
{name: "Ruby", icon: <FaGem size={24} />, color: "#CC342D"},
3132
];
3233

3334
const servers = [

β€Žsrc/components/QuickStartList.jsβ€Ž

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,26 @@ const quickstarts = [
306306
link: "/docs/quickstart/flask-redis/",
307307
},
308308

309+
// Ruby list
310+
311+
{
312+
title: "Ruby + Postgres",
313+
language: "Ruby",
314+
server: "Docker",
315+
description:
316+
"A sample Books CRUD API to demonstrate how seamlessly Keploy integrates with Ruby (Sinatra) and PostgreSQL.",
317+
link: "/docs/quickstart/samples-ruby/#using-docker-compose-",
318+
},
319+
320+
{
321+
title: "Ruby + Postgres",
322+
language: "Ruby",
323+
server: "Local",
324+
description:
325+
"A sample Books CRUD API to demonstrate how seamlessly Keploy integrates with Ruby (Sinatra) and PostgreSQL.",
326+
link: "/docs/quickstart/samples-ruby/#running-app-locally-on-linuxwsl-",
327+
},
328+
309329
//Javascript list
310330

311331
/* {
Lines changed: 284 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
---
2+
id: samples-ruby
3+
title: Sample Books API
4+
sidebar_label: Ruby + Postgres
5+
description: The following sample app showcases how to use the Ruby (Sinatra) framework and the Keploy Platform.
6+
tags:
7+
- ruby
8+
- quickstart
9+
- samples
10+
- examples
11+
- tutorial
12+
- sinatra
13+
- postgresql
14+
- ruby-framework
15+
keyword:
16+
- Sinatra Framework
17+
- PostgreSQL
18+
- Ruby
19+
- API Test generator
20+
- Auto case generation
21+
---
22+
23+
import InstallReminder from '@site/src/components/InstallReminder';
24+
import SectionDivider from '@site/src/components/SectionDivider';
25+
26+
## Introduction
27+
28+
πŸͺ„ 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! 🎒
29+
30+
<InstallReminder />
31+
32+
## Prerequisites
33+
34+
### For Local Setup:
35+
- Ruby 3.2 or higher
36+
- PostgreSQL 15 or higher
37+
- Bundler (`gem install bundler`)
38+
39+
### For Docker Setup:
40+
- Docker (20.10 or higher)
41+
- Docker Compose (v2.0 or higher)
42+
43+
<SectionDivider />
44+
45+
## Using Docker Compose 🐳
46+
47+
We will be using Docker compose to run the application as well as PostgreSQL on Docker container.
48+
49+
### Clone the Application πŸ§ͺ
50+
51+
```bash
52+
git clone https://github.com/Nsanjayboruds/keploy-ruby-postgresql-quickstart.git && cd keploy-ruby-postgresql-quickstart
53+
```
54+
55+
### Build and Start Services
56+
57+
```bash
58+
docker-compose up --build
59+
```
60+
61+
This will:
62+
- Start a PostgreSQL container
63+
- Build and start the Ruby application container
64+
- Initialize the database with sample data
65+
- Expose the API on port 8000
66+
67+
### Verify the Setup
68+
69+
```bash
70+
curl http://localhost:8000/health
71+
```
72+
73+
Expected Response:
74+
```json
75+
{"status":"healthy","service":"Ruby Books API"}
76+
```
77+
78+
### Lights, Camera, Record! πŸŽ₯
79+
80+
Capture the test-cases-
81+
82+
```bash
83+
keploy record -c "docker-compose up" --container-name "ruby-books-app"
84+
```
85+
86+
πŸ”₯**Make some API calls**. Postman, Hoppscotch or even curl - take your pick!
87+
88+
### Generate Testcases
89+
90+
To generate testcases we just need to **make some API calls.**
91+
92+
#### 1. Get All Books
93+
94+
```bash
95+
curl http://localhost:8000/books
96+
```
97+
98+
#### 2. Get a Specific Book
99+
100+
```bash
101+
curl http://localhost:8000/books/1
102+
```
103+
104+
#### 3. Create a New Book
105+
106+
```bash
107+
curl -X POST http://localhost:8000/books \
108+
-H "Content-Type: application/json" \
109+
-d '{
110+
"title": "The Hobbit",
111+
"author": "J.R.R. Tolkien",
112+
"isbn": "9780547928227",
113+
"published_year": 1937
114+
}'
115+
```
116+
117+
#### 4. Update a Book
118+
119+
```bash
120+
curl -X PUT http://localhost:8000/books/1 \
121+
-H "Content-Type: application/json" \
122+
-d '{
123+
"title": "The Great Gatsby (Updated)",
124+
"author": "F. Scott Fitzgerald",
125+
"isbn": "9780743273565",
126+
"published_year": 1925
127+
}'
128+
```
129+
130+
#### 5. Delete a Book
131+
132+
```bash
133+
curl -X DELETE http://localhost:8000/books/1
134+
```
135+
136+
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`.
137+
138+
Want to see if everything works as expected?
139+
140+
### Run Tests πŸ§ͺ
141+
142+
Time to put things to the test πŸ§ͺ
143+
144+
```bash
145+
keploy test -c "docker-compose up" --container-name "ruby-books-app" --delay 10
146+
```
147+
148+
> The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking.
149+
150+
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!βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨
151+
152+
<SectionDivider />
153+
154+
## Running App Locally on Linux/WSL 🐧
155+
156+
We'll be running our sample application locally on Linux/WSL. There are 2 ways you can run this application:
157+
158+
### Clone the Application πŸ§ͺ
159+
160+
```bash
161+
git clone https://github.com/Nsanjayboruds/keploy-ruby-postgresql-quickstart.git && cd keploy-ruby-postgresql-quickstart
162+
```
163+
164+
### Install Dependencies
165+
166+
```bash
167+
bundle install
168+
```
169+
170+
### Set up PostgreSQL Database
171+
172+
Create the database:
173+
174+
```bash
175+
createdb booksdb
176+
```
177+
178+
Initialize the database with the schema:
179+
180+
```bash
181+
psql -d booksdb -f init.sql
182+
```
183+
184+
### Configure Environment Variables
185+
186+
```bash
187+
cp .env.example .env
188+
# Edit .env if needed for your local PostgreSQL configuration
189+
```
190+
191+
### Start the Application
192+
193+
```bash
194+
bundle exec ruby app.rb
195+
```
196+
197+
The API will be available at `http://localhost:8000`
198+
199+
### Verify the Setup
200+
201+
```bash
202+
curl http://localhost:8000/health
203+
```
204+
205+
Expected Response:
206+
```json
207+
{"status":"healthy","service":"Ruby Books API"}
208+
```
209+
210+
### Lights, Camera, Record! πŸŽ₯
211+
212+
Capture the test-cases-
213+
214+
```bash
215+
keploy record -c "bundle exec ruby app.rb"
216+
```
217+
218+
πŸ”₯**Make some API calls**. Postman, Hoppscotch or even curl - take your pick!
219+
220+
### Generate Testcases
221+
222+
To generate testcases we just need to **make some API calls.**
223+
224+
#### 1. Get All Books
225+
226+
```bash
227+
curl http://localhost:8000/books
228+
```
229+
230+
#### 2. Get a Specific Book
231+
232+
```bash
233+
curl http://localhost:8000/books/1
234+
```
235+
236+
#### 3. Create a New Book
237+
238+
```bash
239+
curl -X POST http://localhost:8000/books \
240+
-H "Content-Type: application/json" \
241+
-d '{
242+
"title": "The Hobbit",
243+
"author": "J.R.R. Tolkien",
244+
"isbn": "9780547928227",
245+
"published_year": 1937
246+
}'
247+
```
248+
249+
#### 4. Update a Book
250+
251+
```bash
252+
curl -X PUT http://localhost:8000/books/1 \
253+
-H "Content-Type: application/json" \
254+
-d '{
255+
"title": "The Great Gatsby (Updated)",
256+
"author": "F. Scott Fitzgerald",
257+
"isbn": "9780743273565",
258+
"published_year": 1925
259+
}'
260+
```
261+
262+
#### 5. Delete a Book
263+
264+
```bash
265+
curl -X DELETE http://localhost:8000/books/1
266+
```
267+
268+
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`.
269+
270+
Want to see if everything works as expected?
271+
272+
### Run Tests πŸ§ͺ
273+
274+
Time to put things to the test πŸ§ͺ
275+
276+
```bash
277+
keploy test -c "bundle exec ruby app.rb" --delay 10
278+
```
279+
280+
> The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking.
281+
282+
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!βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨
283+
284+
Happy coding! βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨

β€Žversioned_sidebars/version-4.0.0-sidebars.jsonβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@
117117
"items": [
118118
"quickstart/samples-csharp"
119119
]
120+
},
121+
{
122+
"type": "category",
123+
"label": "Ruby",
124+
"collapsible": true,
125+
"collapsed": true,
126+
"items": [
127+
"quickstart/samples-ruby"
128+
]
120129
}
121130
]
122131
},

0 commit comments

Comments
Β (0)