bundle exec rake test # Run all tests
bundle exec rake test:integration # Run integration tests only
bundle exec rake test:unit # Run unit tests onlyThe test suite is organized into unit tests (fast, isolated, with mocks) and integration tests (full-stack, with real database):
tests/
├── test_helper.rb # Shared setup, database helpers
├── unit/ # Unit tests (fast, isolated)
│ ├── domain/
│ │ ├── restaurant_test.rb # Domain model tests
│ │ └── matcher_test.rb # Pure matcher logic tests
│ ├── repositories/
│ │ └── restaurant_repository_test.rb # Data access tests
│ ├── services/
│ │ ├── index_restaurants_service_test.rb
│ │ ├── search_restaurants_service_test.rb
│ │ └── restaurant_details_service_test.rb
│ └── adapters/
│ ├── yelp_test.rb # Adapter tests (mocked HTTP)
│ └── google_test.rb
└── integration/ # Integration tests (full-stack)
├── cli_test.rb # CLI command tests
└── index_test.rb # Indexing workflow tests
Unit tests are fast and isolated. They use mocks and don't touch the database or make real HTTP calls.
Test pure business logic with zero dependencies:
class RestaurantTest < Minitest::Test
def test_distance_calculation
restaurant1 = Domain::Models::Restaurant.new(
latitude: 44.3894,
longitude: -79.6903
)
restaurant2 = Domain::Models::Restaurant.new(
latitude: 44.3900,
longitude: -79.6910
)
distance = restaurant1.distance_to(restaurant2)
assert distance < 0.1 # Less than 0.1 km
end
endTest business operations with mocked dependencies:
class SearchRestaurantsServiceTest < Minitest::Test
def test_search_by_name
# Create mock repository
mock_repo = Minitest::Mock.new
mock_repo.expect(:search_by_name, [mock_restaurant], ["pizza"])
# Test service
service = Services::SearchRestaurantsService.new(
restaurant_repo: mock_repo
)
results = service.search_by_name("pizza")
assert_equal 1, results.count
mock_repo.verify
end
endTest data access with an in-memory test database:
class RestaurantRepositoryTest < GrubStars::IntegrationTest
def test_find_by_id
# Setup test data
restaurant_id = @db[:restaurants].insert(
name: "Test Restaurant",
latitude: 44.3894,
longitude: -79.6903,
created_at: Time.now
)
# Test repository
repo = Infrastructure::Repositories::RestaurantRepository.new(@db)
restaurant = repo.find_by_id(restaurant_id)
assert_equal "Test Restaurant", restaurant.name
assert_instance_of Domain::Models::Restaurant, restaurant
end
endTest external API integrations with mocked HTTP responses:
class YelpAdapterTest < Minitest::Test
def test_search_businesses
# Mock HTTP client
mock_http = Minitest::Mock.new
mock_http.expect(:get, mock_response, [String, Hash])
adapter = Infrastructure::Adapters::Yelp.new(http_client: mock_http)
results = adapter.search_businesses(location: "Barrie, ON")
assert_equal 3, results.count
mock_http.verify
end
endIntegration tests use real components including database, services, and repositories. They test the full stack end-to-end.
Integration tests inherit from GrubStars::IntegrationTest, which:
- Creates a fresh SQLite database at
tmp/test.dbbefore each test - Applies the full schema
- Deletes the database after each test
class MyIntegrationTest < GrubStars::IntegrationTest
def test_full_workflow
# @db is a Sequel database connection with full schema
service = Services::IndexRestaurantsService.new
stats = service.index(location: "Barrie, ON", adapters: [mock_adapter])
assert stats[:total] > 0
end
endTest Thor CLI commands:
class CLITest < GrubStars::IntegrationTest
def test_search_command
# Setup test data
setup_test_restaurants
# Run CLI command
cli = GrubStars::CLI.new
output = capture_io { cli.search(name: "pizza") }.join
assert_match /Pizza Place/, output
end
endSchema is defined in lib/infrastructure/database.rb. Tables:
restaurants- Core restaurant data (name, address, coordinates)categories- Category tags (bakery, cafe, etc.)restaurant_categories- Join table linking restaurants to categoriesratings- Scores from each source (yelp, google, tripadvisor)reviews- Review snippets with URLsmedia- Photo/video URLsexternal_ids- Links restaurants to their IDs in external systems
- Create a file in
tests/unit/<layer>/ending in_test.rb - Require
test_helper - Use mocks/stubs for dependencies
- Test one component in isolation
- Keep tests fast (no I/O)
- Create a file in
tests/integration/ending in_test.rb - Require
test_helper - Inherit from
GrubStars::IntegrationTest - Use
@dbto interact with the database - Test complete workflows
Unit Tests:
- Fast (milliseconds)
- Isolated (no database, no HTTP)
- Test single units (one class/method)
- Use mocks for dependencies
- High coverage of business logic
Integration Tests:
- Slower (seconds)
- Use real components
- Test workflows and interactions
- Verify system works end-to-end
- Cover happy paths and critical flows
# Run a specific file
bundle exec ruby tests/unit/domain/restaurant_test.rb
# Run a specific test
bundle exec ruby tests/unit/domain/restaurant_test.rb -n test_distance_calculation
# Run all unit tests
bundle exec rake test:unit
# Run all integration tests
bundle exec rake test:integration
# Run all tests
bundle exec rake test