From b9713ad678b5fafdd246e8a99cfed5d757dc837d Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Fri, 5 Apr 2024 21:58:08 +0900 Subject: [PATCH] Update specs to use Yabeda RSpec matchers, refresh CI setup --- .github/workflows/lint.yml | 11 +++---- .github/workflows/test.yml | 42 ++++++++++---------------- spec/spec_helper.rb | 2 +- spec/yabeda/schked_spec.rb | 62 ++++++++++---------------------------- 4 files changed, 38 insertions(+), 79 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 52d1554..63e33dc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: Run lint +name: Lint on: push: @@ -8,15 +8,14 @@ on: jobs: rubocop: - name: "Run lint" + name: "RuboCop" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 + ruby-version: "3.3" + bundler-cache: true - name: Lint Ruby code with RuboCop run: | - gem install bundler - bundle install --jobs 4 --retry 3 bundle exec rubocop diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8070e6d..de2479f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,15 +1,18 @@ -name: Run tests +name: Tests on: + pull_request: push: branches: - - master - pull_request: + - '**' + tags-ignore: + - 'v*' jobs: - rspec: - name: "Run tests" - if: "!contains(github.event.head_commit.message, '[ci skip]')" + test: + name: "Ruby ${{ matrix.ruby }}" + # Skip running tests for local pull requests (use push event instead), run only for foreign ones + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login != github.event.pull_request.base.repo.owner.login runs-on: ubuntu-latest env: BUNDLE_JOBS: 4 @@ -19,28 +22,15 @@ jobs: fail-fast: false matrix: include: - - ruby: 3.1 - - ruby: 3.0 - - ruby: 2.7 - - ruby: 2.6 - - ruby: 2.5 + - ruby: "3.3" + - ruby: "3.2" + - ruby: "3.1" + - ruby: "3.0" steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v1 - with: - path: /home/runner/bundle - key: bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }} - restore-keys: | - bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }} - bundle-${{ matrix.ruby }}- + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - - name: Bundle install - run: | - bundle config path /home/runner/bundle - bundle install - bundle update + bundler-cache: true - name: Run RSpec - run: | - bundle exec rspec + run: bundle exec rspec diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a817835..246caca 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,7 @@ require "yabeda/schked" +require "yabeda/rspec" require_relative "support/schked" RSpec.configure do |config| @@ -18,7 +19,6 @@ end config.before(:all) do - Yabeda.configure! Schked.config.logger = Logger.new(nil) end end diff --git a/spec/yabeda/schked_spec.rb b/spec/yabeda/schked_spec.rb index 2ce1624..4f62261 100644 --- a/spec/yabeda/schked_spec.rb +++ b/spec/yabeda/schked_spec.rb @@ -9,23 +9,13 @@ let(:worker) { Schked.worker.tap(&:pause) } let(:job) { worker.job(job_name) } - before do - Yabeda.schked.jobs_executed_total.values.clear - Yabeda.schked.job_execution_runtime.values.clear - end - context "when job is successful" do let(:job_name) { "SuccessfulJob" } it "measures called job" do - job.trigger_off_schedule - - expect(Yabeda.schked.jobs_executed_total.values).to include( - {name: job_name, success: true} => 1 - ) - expect(Yabeda.schked.job_execution_runtime.values).to include( - {name: job_name, success: true} => kind_of(Numeric) - ) + expect { job.trigger_off_schedule }.to \ + increment_yabeda_counter(Yabeda.schked.jobs_executed_total).with_tags(name: job_name, success: true).and \ + measure_yabeda_histogram(Yabeda.schked.job_execution_runtime).with_tags(name: job_name, success: true) end end @@ -35,23 +25,13 @@ it "measures the job with failure and success" do job.opts[:failed] = true - job.trigger_off_schedule + expect { job.trigger_off_schedule }.to \ + increment_yabeda_counter(Yabeda.schked.jobs_executed_total).with_tags(name: job_name, success: false).and \ + measure_yabeda_histogram(Yabeda.schked.job_execution_runtime).with_tags(name: job_name, success: false) - expect(Yabeda.schked.jobs_executed_total.values).to include( - {name: job_name, success: false} => 1 - ) - expect(Yabeda.schked.job_execution_runtime.values).to include( - {name: job_name, success: false} => kind_of(Numeric) - ) - - job.trigger_off_schedule - - expect(Yabeda.schked.jobs_executed_total.values).to include( - {name: job_name, success: true} => 1 - ) - expect(Yabeda.schked.job_execution_runtime.values).to include( - {name: job_name, success: true} => kind_of(Numeric) - ) + expect { job.trigger_off_schedule }.to \ + increment_yabeda_counter(Yabeda.schked.jobs_executed_total).with_tags(name: job_name, success: true).and \ + measure_yabeda_histogram(Yabeda.schked.job_execution_runtime).with_tags(name: job_name, success: true) end end @@ -59,14 +39,9 @@ let(:job_name) { "FailedJob" } it "measures called job" do - job.trigger_off_schedule - - expect(Yabeda.schked.jobs_executed_total.values).to include( - {name: job_name, success: false} => 1 - ) - expect(Yabeda.schked.job_execution_runtime.values).to include( - {name: job_name, success: false} => kind_of(Numeric) - ) + expect { job.trigger_off_schedule }.to \ + increment_yabeda_counter(Yabeda.schked.jobs_executed_total).with_tags(name: job_name, success: false).and \ + measure_yabeda_histogram(Yabeda.schked.job_execution_runtime).with_tags(name: job_name, success: false) end end @@ -74,15 +49,10 @@ let(:job_name) { nil } it "measures called job" do - expect { job.trigger_off_schedule }.to output( - /Warning: No name specified for the job/ - ).to_stderr - expect(Yabeda.schked.jobs_executed_total.values).to include( - {name: "none", success: true} => 1 - ) - expect(Yabeda.schked.job_execution_runtime.values).to include( - {name: "none", success: true} => kind_of(Numeric) - ) + expect { job.trigger_off_schedule }.to \ + increment_yabeda_counter(Yabeda.schked.jobs_executed_total).with_tags(name: "none", success: true).and \ + measure_yabeda_histogram(Yabeda.schked.job_execution_runtime).with_tags(name: "none", success: true).and \ + output(/Warning: No name specified for the job/).to_stderr end end end