Developing FAQ - tobymao/18xx GitHub Wiki

Running specific tests

docker compose exec rack rspec spec/lib/x_spec.rb -e 'desc'  # run all tests in x_spec.rb with "desc" anywhere in it/describe/context blocks
docker compose exec rack rspec spec/lib/x_spec.rb:5:10  # run tests between specific lines
docker compose exec rack rspec spec/lib/x_spec.rb:134  # run test at specific line
docker compose exec rack rspec --only-failures  # run only tests that failed in the most recent rspec run
docker compose exec rack rspec -e '<fixture_id>'  # run all tests with <fixture_id> in the test description, good for JSON fixtures

More RSpec CLI documentation: https://rspec.info/documentation/3.11/rspec-core/

RuboCop

docker compose exec rack rubocop -A  # run with auto-correct, fixes most trivial issues
docker compose exec rack rubocop -A lib/engine/game/meta.rb  # run against specific file
docker compose exec rack rubocop -A lib/engine/game/  # run against all files in a directory

More RuboCop CLI documentation: https://docs.rubocop.org/rubocop/usage/basic_usage.html#command-line-flags

Testing a game

Add a game json to spec/fixtures and tests will run through it with the server-side engine code (https://github.com/tobymao/18xx/blob/master/spec/lib/engine/games/game_spec.rb#L12-L30). You can also set up tests for the fixture at specific actions to verify game state. This is a useful way to debug by setting up breakpoints in a test right before the broken action and then step through the ruby code: https://github.com/tobymao/18xx/blob/master/spec/game_state_spec.rb

docker compose exec rack rspec -e '<fixture_id>' will find and run all tests for <fixture_id>.json.

Permission problems when running make

db_1     | chmod: changing permissions of '/var/lib/postgresql/data': Operation not permitted
db_1     | The files belonging to this database system will be owned by user "db".
db_1     | This user must also own the server process.
[…]

Try: chown -R [your_user] ./db

⚠️ **GitHub.com Fallback** ⚠️