GitHubActionsメモ
# 好きな名前をつける name: RUN Rspec # どのタイミングで実行するかをここで決める pushとかpullreqestとかを指定するとそのタイミングで実行できる on: [push] jobs: test: # OSを選択するMacとかも選べる runs-on: ubuntu-latest services: # みま神のarrangyのやつコピペしました db: image: postgres:latest ports: ['5432:5432'] env: POSTGRES_PASSWORD: postgres POSTGRES_USER: postgres options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 env: # masterkeyはcredential読むのにgithubに設定した RAILS_ENV: test RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }} POSTGRES_PASSWORD: postgres POSTGRES_USER: postgres POSTGRES_HOST: 127.0.0.1 POSTGRES_PORT: 5432 steps: - name: check out code uses: actions/checkout@v2 # github actionsに用意されてるruby用の設定使っただけ - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: 2.7.2 # github actionsに用意されてるnode用の設定使っただけ - name: setup node.js 15.4.0 uses: actions/setup-node@v1 with: node-version: 15.4.0 # gemキャッシュしたい念を送ったけど行けてない感じがする - name: chache Gemfile.lock uses: actions/cache@v2 with: path: vendor/bundle key: bundle-${{ hashFiles('**/Gemfile.lock') }} # yarnはなんでもいいから1回build通したらキャッシュ出来た - name: chache yarn.lock uses: actions/cache@v2 with: path: node_modules key: yarn-${{ hashFiles('**/yarn.lock') }} - name: yarn install run: yarn install - name: Build run: | # postgres関連インストールしてる感ある sudo apt-get -yqq install libpq-dev # github actions用の設定ファイル作ってdatabase.ymlとして使ってる cp config/database.yml.github-actions config/database.yml # gemキャッシュできてる感ないから分けないといけないのかも gem install bundler bundle install --path vendor/bundle --jobs 4 bundle exec rails db:setup - name: RSpec run: bundle exec rails spec
require 'spec_helper' ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../config/environment', __dir__) abort("The Rails environment is running in production mode!") if Rails.env.production? require 'rspec/rails' begin ActiveRecord::Migration.maintain_test_schema! rescue ActiveRecord::PendingMigrationError => e puts e.to_s.strip exit 1 end RSpec.configure do |config| config.fixture_path = "#{::Rails.root}/spec/fixtures" config.use_transactional_fixtures = true config.infer_spec_type_from_file_location! config.filter_rails_from_backtrace! config.before(:each) do |example| if example.metadata[:type] == :system driven_by :selenium_chrome_headless, screen_size: [1600, 1600] end end end
test: adapter: postgresql encoding: unicode database: hieroglitter_test pool: 5 port: <%= ENV["POSTGRES_PORT"] %> username: <%= ENV["POSTGRES_USER"] %> password: <%= ENV["POSTGRES_PASSWORD"] %> host: <%= ENV["POSTGRES_HOST"] %>
環境変数はどこのやつを呼んでいるのじゃろうか envに設定したやつがPCに環境変数設定したのと同じ扱いになる感はある
- Google Chromeはデフォルトで入っているから入れる必要がなかった
- system specは
rails_helper.rb
にdriven_byの設定を書かないとエラー起きる
RSpec.configure do |config| config.before(:each) do |example| if example.metadata[:type] == :system driven_by :selenium_chrome_headless, screen_size: [1600, 1600] end end end