2.11 Rails application testing example

You can run the tests for a Rails that requires a specific version of ruby and relies on a Postgres database.

Pipeline Configuration

---
resources:
- name: rails-contributors-git
  type: git
  icon: github
  source:
    uri: https://github.com/rails/rails-contributors.git

jobs:
- name: test
  public: true
  build_log_retention:
    builds: 50
  plan:
    - get: rails-contributors-git
      trigger: true
    - task: run-tests
      config:
        platform: linux
        image_resource:
          type: registry-image
          source: { repository: ruby, tag: 3.3.4 }
        inputs:
          - name: rails-contributors-git
        params:
          RAILS_ENV: test
          DATABASE_URL: postgresql://postgres@localhost
        run:
          path: /bin/bash
          args:
            - -ce
            - |
              cd rails-contributors-git

              echo "=== Setting up Postgres ==="
              apt-get update
              apt-get install -y postgresql libpq-dev cmake nodejs
              cat > /etc/postgresql/*/main/pg_hba.conf <<-EOF
              host   all   postgres   localhost   trust
              EOF
              service postgresql restart

              echo "=== Project requires that we clone rails ==="
              git clone --mirror https://github.com/rails/rails.git

              echo "=== Installing Gems ==="
              gem install -N bundler
              bundle install

              echo "=== Running Tests ==="
              bundle exec rails db:setup
              bundle exec rails test

References