-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathrails_spec.rb
75 lines (63 loc) · 2.38 KB
/
rails_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: true
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
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
it "returns internal_server_error status code" do
expect { get "/hello/internal_server_error" }.to \
increment_yabeda_counter(Yabeda.rails.requests_total)
.with_tags(controller: "hello", action: "internal_server_error", status: 500, method: "get", format: :html)
end
context "with changed controller name case config tp camel case" do
around do |example|
original_case = described_class.config.controller_name_case
described_class.config.controller_name_case = :camel
example.call
ensure
described_class.config.controller_name_case = original_case
end
it "reports controller tag in camel case" do
expect { get "/hello/world" }.to \
increment_yabeda_counter(Yabeda.rails.requests_total)
.with_tags(controller: "HelloController", action: "world", status: 200, method: "get", format: :html)
.by(1)
end
end
context "with default_tags set" do
before do
Yabeda.default_tag :custom_tag, nil
end
it "increments counters for every request" do
expect { get "/hello/world" }.to \
increment_yabeda_counter(Yabeda.rails.requests_total)
.with_tags(custom_tag: "hello-world")
.by(1)
end
end
context "with ':rails' default_tags set" do
before do
Yabeda.default_tag :custom_tag_from_rails, nil, group: :rails
end
it "increments counters for every request" do
expect { get "/hello/world" }.to \
increment_yabeda_counter(Yabeda.rails.requests_total)
.with_tags(custom_tag_from_rails: "hello-world-from-rails")
.by(1)
end
end
end