version: 2.1
orbs:
  ruby: circleci/ruby@1.0
  codecov: codecov/codecov@5.3.0

jobs:
  build:
    docker:
      - image: cimg/ruby:3.1
    steps:
      - checkout 
      - ruby/install-deps
      - run:
          name: Make test.sh executable
          command: chmod +x test.sh

  test:
    docker:
      - image: cimg/ruby:3.1
    environment:
      CI: 'true'
      CODECOV_TOKEN: ${CODECOV_TOKEN}
    steps:
      - checkout 
      - ruby/install-deps 
      - run:
          name: Run tests and generate coverage
          command: ./test.sh
      - store_test_results:
          path: rspec.xml
      - store_artifacts:
          path: coverage
          destination: coverage

workflows:
  version: 2
  build_and_test:     
    jobs:           
      - build        
      - test:      
          requires:  
            - build
