Skip to content

Commit

Permalink
Update specs to use Yabeda RSpec matchers, refresh CI setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Envek committed Apr 5, 2024
1 parent 53c56f6 commit b9713ad
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 79 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run lint
name: Lint

on:
push:
Expand All @@ -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
42 changes: 16 additions & 26 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

require "yabeda/schked"

require "yabeda/rspec"
require_relative "support/schked"

RSpec.configure do |config|
Expand All @@ -18,7 +19,6 @@
end

config.before(:all) do
Yabeda.configure!
Schked.config.logger = Logger.new(nil)
end
end
62 changes: 16 additions & 46 deletions spec/yabeda/schked_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -35,54 +25,34 @@
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

context "when job is failed" do
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

context "when job has no name" do
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
Expand Down

0 comments on commit b9713ad

Please sign in to comment.