-
-
Notifications
You must be signed in to change notification settings - Fork 0
Automated Testing
TokenAuthority uses RSpec for automated testing. The test suite includes unit tests for models and service objects, as well as request specs for controller endpoints.
Run the complete test suite:
bundle exec rspecRun tests in a specific file:
bundle exec rspec spec/models/token_authority/client_spec.rbRun a specific test by line number:
bundle exec rspec spec/models/token_authority/client_spec.rb:42Run tests with a specific tag:
bundle exec rspec --tag slow:factoryFor faster execution on multi-core machines, you can use parallel_tests (if configured):
bundle exec parallel_rspec spec/Tests are organized by type in the spec/ directory:
| Directory | Description |
|---|---|
spec/models/ |
Unit tests for models and service objects |
spec/requests/ |
Request specs for controller endpoints |
spec/factories/ |
Factory definitions for test data |
spec/dummy/ |
Dummy Rails application for integration testing |
TokenAuthority includes test-prof for analyzing test suite performance. Use these commands to identify bottlenecks and optimization opportunities.
Measure how long each type of spec (models, requests, etc.) takes to run:
TAG_PROF=type bundle exec rspecThis helps identify which spec types are slowest and may need optimization.
Generate an HTML chart showing execution time by spec type and specific events:
TAG_PROF=type TAG_PROF_FORMAT=html TAG_PROF_EVENT=sql.active_record,factory.create bundle exec rspecThis creates a visual breakdown of where time is spent, combining spec type with database and factory activity.
Measure time spent on database queries:
EVENT_PROF='sql.active_record' bundle exec rspecHigh database time may indicate:
- Missing database indexes
- N+1 queries in application code
- Excessive test data setup
Measure time spent creating factory objects:
EVENT_PROF='factory.create' bundle exec rspecSlow factories often indicate overly complex object graphs or unnecessary associations.
Identify all factory usages across the test suite:
FPROF=1 bundle exec rspecThis shows which factories are used most frequently and how much time each consumes.
Generate a flamegraph visualization of factory usage:
FPROF=flamegraph bundle exec rspecFlamegraphs help visualize nested factory calls and identify deep object creation chains.
Check for factories that create more data than necessary:
FDOC=1 bundle exec rspecThis identifies tests that may be using create when build or build_stubbed would suffice.
Find opportunities to use factory defaults for frequently created objects:
FACTORY_DEFAULT_PROF=1 bundle exec rspec --tag slow:factoryFactory defaults can significantly speed up tests by reusing common objects instead of recreating them.
Measure time spent in spec setup (before hooks, let blocks, etc.):
RD_PROF=1 bundle exec rspecHigh setup time may indicate:
- Expensive
before(:each)hooks that could bebefore(:all) - Complex
letdefinitions that are always evaluated - Unnecessary data setup for simple tests
When analyzing test performance:
- Focus on outliers - Look for specs that take significantly longer than average
- Check factory chains - Deep factory associations multiply creation time
-
Review database activity - Excessive queries often indicate missing
let_it_beor factory defaults - Consider test isolation - Some slowness is acceptable for thorough integration tests
Getting Started
- Installation Guide
- MCP Quickstart
- Configuration Reference
- User Authentication
- Protecting API Endpoints
- Customizing Views
- Event Logging
- Instrumentation
Process Flows
- Authorization Code Grant
- Authorization Code Redemption
- Token Refresh
- Token Revocation
- Authorization Server Metadata
- Protected Resource Metadata
- Dynamic Client Registration
- Client Metadata Documents
Development