Skip
Arish's avatar

6. Running RSpec in CI


Basic RSpec Workflow

yaml
1name: Tests
2
3on: [push, pull_request]
4
5jobs:
6  test:
7    runs-on: ubuntu-latest
8    
9    services:
10      postgres:
11        image: postgres:15
12        env:
13          POSTGRES_PASSWORD: postgres
14        ports:
15          - 5432:5432
16        options: >-
17          --health-cmd pg_isready
18          --health-interval 10s
19          --health-timeout 5s
20          --health-retries 5
21      
22      redis:
23        image: redis:7
24        ports:
25          - 6379:6379
26    
27    env:
28      RAILS_ENV: test
29      DATABASE_URL: postgres://postgres:postgres@localhost:5432/test
30      REDIS_URL: redis://localhost:6379
31    
32    steps:
33      - uses: actions/checkout@v4
34      
35      - name: Setup Ruby
36        uses: ruby/setup-ruby@v1
37        with:
38          ruby-version: '3.2'
39          bundler-cache: true
40      
41      - name: Setup database
42        run: |
43          bundle exec rails db:create
44          bundle exec rails db:schema:load
45      
46      - name: Run RSpec
47        run: bundle exec rspec --format documentation

Test Artifacts

yaml
1- name: Upload coverage
2  uses: actions/upload-artifact@v3
3  with:
4    name: coverage
5    path: coverage/