This document provides comprehensive testing instructions for the Z.ai Ruby SDK across multiple Ruby environments.
- Ruby >= 3.2.8 or JRuby >= 10.0.4.0
- Bundler 2.5+
- Git
- Docker 20.10+
- Docker Compose 2.0+
# Run all tests across all environments
./test_all_environments.sh all
# Or run specific test suites
./test_all_environments.sh local # Quick local tests
./test_all_environments.sh docker # Docker-based tests
./test_all_environments.sh ruby # Ruby 3.2.8 only
./test_all_environments.sh jruby # JRuby 10.0.4.0 only# Install dependencies
bundle install
# Run RSpec tests
bundle exec rspec
# Run smoke test
ruby smoke_test.rb
# Run basic verification
ruby verify_sdk.rbPurpose: Verifies project structure and syntax without dependencies
ruby smoke_test.rb
# or
ruby smoke_test_simple.rbWhat it checks:
- ✓ All source files exist
- ✓ All directories present
- ✓ Ruby syntax valid for all files
- ✓ Examples available
- ✓ Documentation complete
- ✓ Version consistency
Time: ~2-3 seconds
Purpose: Tests core SDK functionality
ruby verify_sdk.rbWhat it tests:
- ✓ SDK loads without errors
- ✓ Version constant accessible
- ✓ Configuration works
- ✓ Client initialization
- ✓ All 4 API resources accessible
- ✓ Error classes functional
- ✓ JWT token generation
- ✓ Model instantiation
Time: ~5-10 seconds
Purpose: Comprehensive unit and integration tests
bundle install
bundle exec rspec
# With coverage
COVERAGE=true bundle exec rspec
# Specific test file
bundle exec rspec spec/resources/chat/completions_spec.rb
# With documentation format
bundle exec rspec --format documentationWhat it tests:
- ✓ Configuration validation
- ✓ Authentication (JWT, API key)
- ✓ Chat API (completions, streaming)
- ✓ Embeddings API
- ✓ Images API
- ✓ Files API
- ✓ Error handling
- ✓ HTTP client retry logic
- ✓ Integration scenarios
Time: ~30-60 seconds
Purpose: Test in clean, reproducible environments
# Build Docker images
cd docker
docker-compose build
# Run Ruby 3.2.8 tests
docker-compose up ruby-test
# Run JRuby 10.0.4.0 tests
docker-compose up jruby-test
# Run both
docker-compose up ruby-test jruby-test
# Interactive Ruby shell
docker-compose run ruby-interactiveBenefits:
- ✅ Isolated environment
- ✅ No system dependencies
- ✅ Reproducible results
- ✅ Tests both Ruby and JRuby
- ✅ Clean slate every time
Time: ~2-5 minutes (first build: ~10 minutes)
Docker Image: ruby:3.2.8-slim
What gets tested:
- Core functionality
- Standard library compatibility
- Performance characteristics
- Ruby 3.2+ features (YJIT, etc.)
Run tests:
./test_all_environments.sh ruby
# or
docker-compose up ruby-testDocker Image: jruby:10.0.4.0-jdk21
What gets tested:
- JVM compatibility
- Thread safety
- Java integration
- Performance on JVM
Run tests:
./test_all_environments.sh jruby
# or
docker-compose up jruby-testJRuby-specific considerations:
- Some C extensions not available
- Different threading model
- Longer startup time
- Better for long-running processes
Run everything:
./test_all_environments.sh allThis will:
- ✓ Run smoke tests (structure verification)
- ✓ Run basic verification (functionality)
- ✓ Build Docker images (Ruby + JRuby)
- ✓ Run Ruby 3.2.8 tests
- ✓ Run JRuby 10.0.4.0 tests
- ✓ Generate coverage reports
- ✓ Clean up Docker resources
Total time: ~5-10 minutes (first run: ~15-20 minutes with Docker build)
| Component | Unit Tests | Integration Tests | Docker Tests |
|---|---|---|---|
| Configuration | ✅ | ✅ | ✅ |
| Authentication | ✅ | ✅ | ✅ |
| Chat API | ✅ | ✅ | ✅ |
| Embeddings API | ✅ | ✅ | ✅ |
| Images API | ✅ | ✅ | ✅ |
| Files API | ✅ | ✅ | ✅ |
| HTTP Client | ✅ | ✅ | ✅ |
| Error Handling | ✅ | ✅ | ✅ |
| Streaming | ✅ | ✅ | ✅ |
- Unit Tests: >90% code coverage
- Integration Tests: All major workflows
- Docker Tests: All APIs on both Ruby and JRuby
# Install specific Bundler version
gem install bundler:2.5.23
bundle _2.5.23_ install# Install to local directory
bundle install --path vendor/bundle# Start Docker (Linux)
sudo systemctl start docker
# Start Docker (macOS)
open -a DockerJRuby doesn't support all C extensions. The gemspec excludes C-based gems for JRuby:
- Uses
platform: :rubywhere needed - Falls back to pure Ruby implementations
# Clean and reinstall
rm -rf vendor/bundle
rm Gemfile.lock
bundle install# Ensure SimpleCov is loaded
COVERAGE=true bundle exec rspec
# Check coverage directory
ls -la coverage/Our CI pipeline (.github/workflows/ci.yml) runs:
- Smoke tests
- Basic verification
- RSpec tests on Ruby 3.2.8, 3.3.0, 3.4.0
- RuboCop linting
- Coverage reporting
# Run what CI runs
./test_all_environments.sh local
bundle exec rspec
bundle exec rubocopCreate .git/hooks/pre-commit:
#!/bin/bash
./smoke_test.rb && bundle exec rspec --format progressRun performance tests:
# Basic benchmarks
ruby examples/performance_benchmark.rb
# Memory profiling
ruby examples/memory_profile.rbTest fixtures are located in:
spec/fixtures/- Test data filesspec/factories.rb- FactoryBot definitionsspec/shared/- Shared examples and contexts
require 'spec_helper'
RSpec.describe Z::AI::Resources::NewAPI do
let(:client) { Z::AI::Client.new(api_key: 'test_key.12345') }
let(:api) { described_class.new(client) }
describe '#method' do
before do
stub_zai_request(:post, 'endpoint', { data: 'response' })
end
it 'returns expected result' do
result = api.method(param: 'value')
expect(result).to be_present
end
end
endAfter running tests:
- Coverage:
coverage/index.html - RSpec Results:
tmp/rspec_results.txt - SimpleCov JSON:
coverage/coverage.json
Choose your testing approach:
| Need | Command | Time |
|---|---|---|
| Quick check | ruby smoke_test.rb |
2-3s |
| Basic verification | ruby verify_sdk.rb |
5-10s |
| Full unit tests | bundle exec rspec |
30-60s |
| Docker tests | ./test_all_environments.sh docker |
2-5min |
| Complete suite | ./test_all_environments.sh all |
5-10min |
- ✅ Run smoke tests:
ruby smoke_test.rb - ✅ Install dependencies:
bundle install - ✅ Run RSpec:
bundle exec rspec - ✅ Test with Docker:
./test_all_environments.sh all - ✅ Check coverage: Open
coverage/index.html
For questions or issues, see:
- CONTRIBUTING.md - How to contribute
- README.md - SDK documentation
- GitHub Issues - Bug reports and feature requests