Skip to content

Commit 67f2e89

Browse files
feat: add script for local testing
1 parent b7b9e43 commit 67f2e89

6 files changed

Lines changed: 258 additions & 0 deletions

File tree

‎dump.rdb‎

16.7 KB
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# RSpec Reporter Testing
2+
3+
Simple script that can be used locally to view the output of `rspec-queue --report`.
4+
5+
## Setup
6+
7+
1. Run `dev up` within `/ruby`
8+
9+
## Usage
10+
11+
From the `/ruby` directory:
12+
```bash
13+
./test/fixtures/rspec_examples/test_reporter.sh
14+
```
15+
16+
This runs example tests with intentional failures and outputs the report
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
require 'rspec'
2+
3+
class Calculator
4+
def add(a, b)
5+
a + b
6+
end
7+
8+
def divide(a, b)
9+
a / b # Bug: no zero check
10+
end
11+
12+
def factorial(n)
13+
return 1 if n <= 1
14+
n * factorial(n - 1)
15+
end
16+
end
17+
18+
RSpec.describe Calculator do
19+
let(:calc) { Calculator.new }
20+
21+
describe '#add' do
22+
it 'adds two numbers correctly' do
23+
expect(calc.add(2, 3)).to eq(5)
24+
end
25+
26+
it 'handles negative numbers' do
27+
# This will fail - expecting 0 but will get -1
28+
expect(calc.add(2, -3)).to eq(0)
29+
end
30+
end
31+
32+
describe '#divide' do
33+
it 'divides two numbers' do
34+
expect(calc.divide(10, 2)).to eq(5)
35+
end
36+
37+
it 'handles division by zero' do
38+
# This will raise ZeroDivisionError
39+
expect(calc.divide(10, 0)).to eq(nil)
40+
end
41+
end
42+
43+
describe '#factorial' do
44+
it 'calculates factorial of 5' do
45+
expect(calc.factorial(5)).to eq(120)
46+
end
47+
48+
it 'handles large numbers' do
49+
# This will cause stack overflow
50+
expect(calc.factorial(10000)).to be > 0
51+
end
52+
end
53+
54+
describe 'complex expectations' do
55+
it 'has multiple failing expectations' do
56+
expect(calc.add(1, 1)).to eq(3) # Fails
57+
expect(calc.add(2, 2)).to eq(5) # Fails
58+
expect(calc.add(3, 3)).to eq(7) # Fails
59+
end
60+
end
61+
end
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
require 'rspec'
2+
3+
class Product
4+
attr_accessor :name, :price, :inventory
5+
6+
def initialize(name, price, inventory = 0)
7+
@name = name
8+
@price = price
9+
@inventory = inventory
10+
end
11+
12+
def in_stock?
13+
inventory > 0
14+
end
15+
16+
def apply_discount(percent)
17+
@price = @price * (1 - percent / 100.0)
18+
end
19+
20+
def sell(quantity)
21+
raise "Insufficient inventory" if quantity > inventory
22+
@inventory -= quantity
23+
end
24+
end
25+
26+
RSpec.describe Product do
27+
describe 'basic product operations' do
28+
let(:product) { Product.new('Widget', 100, 10) }
29+
30+
it 'creates a product with correct attributes' do
31+
expect(product.name).to eq('Widget')
32+
expect(product.price).to eq(100)
33+
expect(product.inventory).to eq(10)
34+
end
35+
36+
it 'checks if product is in stock' do
37+
expect(product.in_stock?).to be true
38+
39+
# This will fail
40+
empty_product = Product.new('Empty', 50, 0)
41+
expect(empty_product.in_stock?).to be true
42+
end
43+
end
44+
45+
describe '#apply_discount' do
46+
it 'applies discount correctly' do
47+
product = Product.new('Item', 100, 5)
48+
product.apply_discount(20)
49+
# This will fail - expecting 75 but will get 80
50+
expect(product.price).to eq(75)
51+
end
52+
53+
it 'handles 100% discount' do
54+
product = Product.new('Free', 100, 1)
55+
product.apply_discount(100)
56+
expect(product.price).to eq(0)
57+
end
58+
end
59+
60+
describe '#sell' do
61+
let(:product) { Product.new('Popular', 50, 5) }
62+
63+
it 'reduces inventory when selling' do
64+
product.sell(3)
65+
expect(product.inventory).to eq(2)
66+
end
67+
68+
it 'raises error when overselling' do
69+
# This will raise an error but we're not properly handling it
70+
product.sell(10)
71+
expect(product.inventory).to eq(-5)
72+
end
73+
74+
it 'handles nil quantity' do
75+
# This will cause an error
76+
product.sell(nil)
77+
end
78+
end
79+
80+
describe 'edge cases' do
81+
it 'creates product with nil name' do
82+
# This might cause issues in real scenarios
83+
product = Product.new(nil, 100)
84+
expect(product.name.upcase).to eq('NIL')
85+
end
86+
end
87+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# Script to test the improved reporting format - quiet version
4+
5+
# Clean Redis for fresh test
6+
redis-cli FLUSHDB > /dev/null 2>&1
7+
8+
BUILD_ID="test-improved-$(date +%s)"
9+
REDIS_URL="redis://localhost:6379"
10+
11+
# Start 2 workers in background (suppress all output)
12+
bundle exec rspec-queue \
13+
--queue "$REDIS_URL" \
14+
--build "$BUILD_ID" \
15+
--worker 1 \
16+
--timeout 30 \
17+
test/fixtures/rspec_examples/*.rb > /dev/null 2>&1 &
18+
WORKER1=$!
19+
20+
bundle exec rspec-queue \
21+
--queue "$REDIS_URL" \
22+
--build "$BUILD_ID" \
23+
--worker 2 \
24+
--timeout 30 \
25+
test/fixtures/rspec_examples/*.rb > /dev/null 2>&1 &
26+
WORKER2=$!
27+
28+
# Give workers time to start and process
29+
sleep 3
30+
31+
# Run reporter - this is the only output shown
32+
bundle exec rspec-queue \
33+
--queue "$REDIS_URL" \
34+
--build "$BUILD_ID" \
35+
--report \
36+
--timeout 30
37+
38+
# Cleanup silently
39+
kill $WORKER1 $WORKER2 2>/dev/null
40+
wait $WORKER1 $WORKER2 2>/dev/null
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
require 'rspec'
2+
3+
class User
4+
attr_accessor :name, :email
5+
6+
def initialize(name, email)
7+
@name = name
8+
@email = email
9+
end
10+
11+
def valid?
12+
!name.nil? && !email.nil?
13+
end
14+
15+
def admin?
16+
false # Bug: should check for admin status
17+
end
18+
end
19+
20+
RSpec.describe User do
21+
describe '#valid?' do
22+
it 'returns true when name and email are present' do
23+
user = User.new('John', 'john@example.com')
24+
expect(user.valid?).to eq(true)
25+
end
26+
27+
it 'returns false when name is missing' do
28+
user = User.new(nil, 'john@example.com')
29+
# This will fail - expecting true but will get false
30+
expect(user.valid?).to eq(true)
31+
end
32+
end
33+
34+
describe '#admin?' do
35+
it 'returns true for admin users' do
36+
user = User.new('Admin', 'admin@example.com')
37+
# This will fail - admin? always returns false
38+
expect(user.admin?).to eq(true)
39+
end
40+
end
41+
42+
describe 'error scenarios' do
43+
it 'raises an error when accessing undefined method' do
44+
user = User.new('Test', 'test@example.com')
45+
# This will cause a NoMethodError
46+
user.undefined_method
47+
end
48+
49+
it 'handles nil operations' do
50+
# This will cause an error
51+
nil.upcase
52+
end
53+
end
54+
end

0 commit comments

Comments
 (0)