|
| 1 | +# Contributing to Stoplight |
| 2 | + |
| 3 | +Thank you for your interest in contributing to Stoplight! This guide will help you understand our codebase architecture |
| 4 | +and how to make effective contributions. If you're lost in the code, please read [architecture.md] |
| 5 | + |
| 6 | +## Development Setup |
| 7 | + |
| 8 | +### Prerequisites |
| 9 | + |
| 10 | +- Ruby version as defined at `stoplight.gemspec` |
| 11 | +- Bundler |
| 12 | + |
| 13 | +### Getting Started |
| 14 | + |
| 15 | +```bash |
| 16 | +# Clone the repository |
| 17 | +git clone https://github.com/bolshakov/stoplight.git |
| 18 | +cd stoplight |
| 19 | + |
| 20 | +# Install dependencies |
| 21 | +bundle install |
| 22 | + |
| 23 | +# Run tests |
| 24 | +bundle exec rspec |
| 25 | + |
| 26 | +# Run cucumber features with Redis data store |
| 27 | +STOPLIGHT_DATA_STORE=Redis bundle exec cucumber |
| 28 | + |
| 29 | + # Run cucumber features with Memory data store |
| 30 | +STOPLIGHT_DATA_STORE=Memory bundle exec cucumber |
| 31 | + |
| 32 | +# Run linter |
| 33 | +bundle exec standardrb |
| 34 | + |
| 35 | +# Auto-fix linting issues |
| 36 | +bundle exec standardrb --fix |
| 37 | +``` |
| 38 | + |
| 39 | +## Making Changes |
| 40 | + |
| 41 | +### Before You Start |
| 42 | + |
| 43 | +1. **Check existing issues** - Look for related discussions |
| 44 | +2. **Open an issue** - Discuss major changes before coding |
| 45 | +3. **Create a branch** - Use descriptive names: `feature/add-retry-strategy`, `fix/memory-leak` |
| 46 | + |
| 47 | +## Testing Guidelines |
| 48 | + |
| 49 | +### Test Organization |
| 50 | + |
| 51 | +- **Unit tests** (`spec/unit/`) - Fast, isolated, no I/O |
| 52 | +- **Integration tests** (`spec/integration/`) - End-to-end scenarios |
| 53 | +- **Feature tests** (`features/`) - User-facing behavior |
| 54 | + |
| 55 | +### Unit Test Principles |
| 56 | + |
| 57 | +Use test doubles for testing with abstract dependencies: |
| 58 | + |
| 59 | +```ruby |
| 60 | +RSpec.describe Stoplight::Domain::Light do |
| 61 | + let(:data_store) { instance_double(Stoplight::Domain::DataStore) } |
| 62 | + let(:notifier) { instance_double(Stoplight::Domain::StateTransitionNotifier) } |
| 63 | + |
| 64 | + # Test in isolation |
| 65 | + it "transitions to red after threshold" do |
| 66 | + allow(data_store).to receive(:get_metadata).and_return(metadata) |
| 67 | + # ... test logic |
| 68 | + end |
| 69 | +end |
| 70 | +``` |
| 71 | + |
| 72 | +Use real dependencies when testing infrastructure |
| 73 | + |
| 74 | +```ruby |
| 75 | +RSpec.describe Stoplight::Infrastructure::DataStore::Redis do |
| 76 | + let(:data_store) { described_class.new(redis) } |
| 77 | + let(:redis) { Redis.new(url: connection_string) } # connects to the real database |
| 78 | + |
| 79 | + it "transitions to red" do |
| 80 | + data_store.transition_to_color(Stoplight::Domain::Color::RED) |
| 81 | + # ... test logic |
| 82 | + end |
| 83 | +end |
| 84 | +``` |
| 85 | + |
| 86 | +### Integration Test Principles |
| 87 | + |
| 88 | +All user-facing functionality (described in the README file) should be covered with feature tests. In rare cases when |
| 89 | +it's tricky to use gherkin language for testing, you can opt out to using integration tests: |
| 90 | + |
| 91 | +```ruby |
| 92 | +RSpec.describe "Concurrency testing" do |
| 93 | + # Use real implementations |
| 94 | + let(:data_store) { Stoplight::Infrastructure::DataStore::Redis.new } |
| 95 | + |
| 96 | + it "persists state across instances" do |
| 97 | + # Test actual integration |
| 98 | + end |
| 99 | +end |
| 100 | +``` |
| 101 | + |
| 102 | +## Getting Help |
| 103 | + |
| 104 | +- **Questions?** Open a discussion on GitHub |
| 105 | +- **Found a bug?** Open an issue with reproduction steps |
| 106 | +- **Need guidance?** Tag maintainers in your PR |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +Thank you for contributing to Stoplight! Your efforts help make circuit breakers more reliable for everyone. |
| 111 | + |
| 112 | +[architecture.md]: https://github.com/bolshakov/stoplight/blob/develop/docs/architecture.md |
0 commit comments