forked from yabeda-rb/yabeda-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
128 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Lint | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- '**' | ||
tags-ignore: | ||
- 'v*' | ||
|
||
jobs: | ||
rubocop: | ||
# 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: RuboCop | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: "3.1" | ||
bundler-cache: true | ||
- name: Lint Ruby code with RuboCop | ||
run: | | ||
bundle exec rubocop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails" | ||
require "action_controller/railtie" | ||
require "active_support/railtie" | ||
|
||
class TestApplication < Rails::Application | ||
config.logger = Logger.new($stdout) | ||
config.log_level = :fatal | ||
config.consider_all_requests_local = true | ||
config.eager_load = true | ||
|
||
routes.append do | ||
get "/hello/world" => "hello#world" | ||
get "/hello/long" => "hello#long" | ||
end | ||
end | ||
|
||
class HelloController < ActionController::API | ||
def world | ||
render json: { hello: :world } | ||
end | ||
|
||
def long | ||
sleep(0.01) | ||
render json: { good: :morning } | ||
end | ||
end | ||
|
||
Rails.application = TestApplication | ||
|
||
TestApplication.initialize! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Yabeda::Rails do | ||
it "has a version number" do | ||
expect(Yabeda::Rails::VERSION).not_to be nil | ||
require "action_controller/test_case" | ||
|
||
RSpec.describe Yabeda::Rails, type: :integration do | ||
include ActionDispatch::Integration::Runner | ||
include ActionDispatch::IntegrationTest::Behavior | ||
|
||
def app | ||
TestApplication | ||
end | ||
|
||
it "increments counters for every request" do | ||
expect { get "/hello/world" }.to \ | ||
increment_yabeda_counter(Yabeda.rails.requests_total) | ||
.with_tags(controller: "hello", action: "world", status: 200, method: "get", format: :html) | ||
.by(1) | ||
end | ||
|
||
xit "does something useful" do | ||
# Nothing here | ||
it "measure action runtime for every request" do | ||
expect { get "/hello/long" }.to \ | ||
measure_yabeda_histogram(Yabeda.rails.request_duration) | ||
.with_tags(controller: "hello", action: "long", status: 200, method: "get", format: :html) | ||
.with(be_between(0.005, 0.05)) | ||
end | ||
end |