【问题标题】:How can I run RSpec on Github Action , if it is not working?如果它不起作用,我如何在 Github Action 上运行 RSpec?
【发布时间】:2022-12-17 12:48:37
【问题描述】:

Click here to view the error 得到这样的错误

RSpec Tests
on:
  push:
    branches:
      - unit-testing-air
  pull_request:
    branches:
      - unit-testing-air
jobs:
  rspec:
    runs-on: ubuntu-latest
    env:
      RAILS_ENV: test
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v2
      - name: Install postgres client
        run: sudo apt-get install libpq-dev
      - name: Install Gemfile
        run: gem install bundler -v '2.3.6'  
      - name: Install dependencies
        run: bundle install
      - name: Create database
        run: |
          bundler exec rails db:create RAILS_ENV=test
          bundler exec rails db:migrate RAILS_ENV=test
      - name: RSpec
        run: bundler exec rspec

这是我项目中 .github/workflows 中包含的 .yml 文件。我可以在我的本地运行 rspec 测试,但我的唯一目的是将测试用例作为拉取请求或简单推送的 github 操作运行。

【问题讨论】:

    标签: rspec rspec-rails


    【解决方案1】:

    这是我的工作流程。

    请注意,我也处理 Postgres,这可能不是你的情况

    name: "RSpec"
    on:
      push:
        branches: [ "development" ]
      pull_request:
        branches: [ "development" ]
    jobs:
      test:
        runs-on: ubuntu-latest
        steps:
        - uses: actions/checkout@v3
        - uses: ruby/setup-ruby@v1
          with:
            bundler-cache: true # runs 'bundle install' and caches installed gems automatically
        - name: Set up PostgreSQL
          uses: Harmon758/postgresql-action@v1.0.0
          with:
            postgresql user: test
            postgresql password: password
        - name: Build app
          run: |
            gem install bundler
            bundle config path vendor/bundle
            bundle install --jobs 4 --retry 3
            bundle exec rails db:create RAILS_ENV=test
            bundle exec rails db:migrate RAILS_ENV=test
          env:
            DATABASE_URL: 'postgres://test:password@localhost/application_test'
        - name: Run specs
          run: |
            bundle exec rspec
          env:
            DATABASE_URL: 'postgres://test:password@localhost/application_test'
    

    【讨论】:

      猜你喜欢
      • 2020-01-01
      • 2021-10-27
      • 2012-04-28
      • 2022-06-13
      • 2020-10-10
      • 2021-01-06
      • 1970-01-01
      • 2021-11-13
      • 2020-09-11
      相关资源
      最近更新 更多