version: 2

.build_template: &build_definition
  steps:
    - checkout
    - restore_cache:
        keys:
          # This branch if available
          - v1-dep-{{ checksum "Gemfile.lock" }}
          # Default branch if not
          - v1-dep-master-
          # Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly
          - v1-dep-
    - run:
        name: Install dependencies
        command: 'bundle check --path=vendor/bundle || bundle install --path=vendor/bundle
          --jobs=4 --retry=3 '
    - run:
        name: Run tests
        command: |
          bundle exec rspec
    - save_cache:
        key: v1-dep-{{ checksum "Gemfile.lock" }}
        paths:
          - ./vendor/bundle
  working_directory: ~/app

jobs:
  build_ruby2_5:
    <<: *build_definition
    docker:
      - image: ruby:2.5
  build_ruby2_4:
    <<: *build_definition
    docker:
      - image: ruby:2.4
  build_ruby2_3:
    <<: *build_definition
    docker:
      - image: ruby:2.3
  build_ruby2_2:
    <<: *build_definition
    docker:
      - image: ruby:2.2

workflows:
  version: 2
  build_ruby_versions:
    jobs:
      - build_ruby2_5
      - build_ruby2_4
      - build_ruby2_3
      - build_ruby2_2

version: 2

.build_template: &build_definition
  steps:
    - checkout
    - restore_cache:
        keys:
          # This branch if available
          - v1-dep-{{ checksum "Gemfile.lock" }}
          # Default branch if not
          - v1-dep-master-
          # Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly
          - v1-dep-
    - run:
        name: Update bundler
        # Bundler 2.x dropped support for ruby < 2.3.0
        command: gem install bundler -v "~>1.0"
    - run:
        name: Install dependencies
        command: 'bundle check --path=vendor/bundle || bundle install --path=vendor/bundle
          --jobs=4 --retry=3 '
    - run:
        name: Run tests
        command: |
          bundle exec rspec
    - save_cache:
        key: v1-dep-{{ checksum "Gemfile.lock" }}
        paths:
          - ./vendor/bundle
  working_directory: ~/app

jobs:
  build_ruby2_5:
    <<: *build_definition
    docker:
      - image: ruby:2.5
  build_ruby2_4:
    <<: *build_definition
    docker:
      - image: ruby:2.4
  build_ruby2_3:
    <<: *build_definition
    docker:
      - image: ruby:2.3
  build_ruby2_2:
    <<: *build_definition
    docker:
      - image: ruby:2.2

workflows:
  version: 2
  build_ruby_versions:
    jobs:
      - build_ruby2_5
      - build_ruby2_4
      - build_ruby2_3
      - build_ruby2_2

Make sure we've got a good version of `bundler`
Make sure we've got a good version of `bundler`
