Skip to content

Commit

Permalink
Refresh tests: new Rubies in CI matrix, use Yabeda RSpec matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
Envek committed Dec 14, 2023
1 parent 1da5f8c commit 717b615
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 45 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Lint

on:
push:
branches:
- master
paths:
- "gemfiles/*"
- "Gemfile"
- "**/*.rb"
- "**/*.gemspec"
- ".github/workflows/lint.yml"
pull_request:
paths:
- "gemfiles/*"
- "Gemfile"
- "**/*.rb"
- "**/*.gemspec"
- ".github/workflows/lint.yml"

jobs:
rubocop:
name: "RuboCop"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
bundler-cache: true
- name: Lint Ruby code with RuboCop
run: |
bundle exec rubocop
41 changes: 13 additions & 28 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run tests
name: Tests

on:
pull_request:
Expand All @@ -10,38 +10,23 @@ on:

jobs:
test:
name: "Run tests"
if: "! contains(toJSON(github.event.commits.latest.message), '[ci skip]')"
# 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
name: 'Ruby ${{ matrix.ruby }}'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- ruby: 3.0
- ruby: 2.7
- ruby: 2.6
- ruby: 2.5
container:
image: ruby:${{ matrix.ruby }}
env:
CI: true
ruby:
- '2.7'
- '3.0'
- '3.1'
- '3.2'
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
path: vendor/bundle
key: bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
restore-keys: |
bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
bundle-${{ matrix.ruby }}-
- name: Upgrade Bundler to 2.0 (for older Rubies)
run: gem install bundler -v '~> 2.0'
- name: Bundle install
run: |
bundle config path vendor/bundle
bundle install
bundle update
- name: Run Rubocop
run: bundle exec rubocop
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run RSpec
run: bundle exec rspec
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
AllCops:
TargetRubyVersion: "2.5"

Style/Documentation:
Exclude:
- 'example/**/*'
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'yabeda/http_requests'
require 'faraday'
require 'byebug'
require 'yabeda/rspec'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down
28 changes: 11 additions & 17 deletions spec/yabeda/http_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,18 @@
end

describe 'metrics' do
before do
Yabeda.configure!
Faraday.get 'http://sushi.com/nigiri/sake.json'
end

# rubocop: disable Layout/MultilineMethodCallIndentation
it 'holds the proper data' do
expect(Yabeda.http_request_total.values).to(
eq({ host: 'sushi.com', method: 'GET', port: 80 } => 1)
)
expect(Yabeda.http_response_total.values.keys.first).to(
include({
host: 'sushi.com', method: 'GET', port: 80,
status: 301
})
)
expect(Yabeda.http_response_duration.values.keys.first).to(
eq(host: 'sushi.com', port: 80, method: 'GET', status: 301)
)
expect { Faraday.get 'https://example.net/' }.to \
increment_yabeda_counter(Yabeda.http_request_total).by(1)
.with_tags(method: 'GET', host: 'example.net', port: 443)
.and \
increment_yabeda_counter(Yabeda.http_response_total).by(1)
.with_tags(method: 'GET', host: 'example.net', port: 443, status: 200)
.and \
measure_yabeda_histogram(Yabeda.http_response_duration)
.with_tags(method: 'GET', host: 'example.net', port: 443, status: 200)
end
# rubocop: enable Layout/MultilineMethodCallIndentation
end
end

0 comments on commit 717b615

Please sign in to comment.