File tree Expand file tree Collapse file tree 5 files changed +52
-6
lines changed Expand file tree Collapse file tree 5 files changed +52
-6
lines changed Original file line number Diff line number Diff line change 19
19
ast (~> 2.4.1 )
20
20
racc
21
21
racc (1.7.3 )
22
+ rack (3.1.8 )
23
+ rack-test (2.1.0 )
24
+ rack (>= 1.3 )
22
25
rainbow (3.1.1 )
23
26
rake (13.0.6 )
24
27
regexp_parser (2.9.0 )
@@ -72,6 +75,7 @@ PLATFORMS
72
75
ruby
73
76
74
77
DEPENDENCIES
78
+ rack-test
75
79
rake (~> 13.0 )
76
80
rspec
77
81
singed !
Original file line number Diff line number Diff line change @@ -9,15 +9,11 @@ def initialize(app)
9
9
end
10
10
11
11
def call ( env )
12
- status , headers , body = if capture_flamegraph? ( env )
13
- flamegraph do
14
- @app . call ( env )
15
- end
12
+ if capture_flamegraph? ( env )
13
+ flamegraph { @app . call ( env ) }
16
14
else
17
15
@app . call ( env )
18
16
end
19
-
20
- [ status , headers , body ]
21
17
end
22
18
23
19
def capture_flamegraph? ( env )
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
spec . add_dependency "colorize"
25
25
spec . add_dependency "stackprof" , ">= 0.2.13"
26
26
27
+ spec . add_development_dependency "rack-test"
27
28
spec . add_development_dependency "rake" , "~> 13.0"
28
29
spec . add_development_dependency "rspec"
29
30
end
Original file line number Diff line number Diff line change
1
+ describe Singed ::RackMiddleware do
2
+ subject do
3
+ instance . call ( env )
4
+ end
5
+
6
+ let ( :app ) { -> ( *) { [ 200 , { 'Content-Type' => 'text/plain' } , [ 'OK' ] ] } }
7
+ let ( :instance ) { described_class . new ( app ) }
8
+ let ( :env ) { Rack ::MockRequest . env_for ( '/' , headers ) }
9
+ let ( :headers ) { { } }
10
+
11
+ it 'returns a proper rack response' do
12
+ status , _ = subject
13
+ expect ( status ) . to eq 200
14
+ end
15
+
16
+ it 'does not capture a flamegraph by default' do
17
+ expect_any_instance_of ( Object ) . not_to receive ( :flamegraph )
18
+ subject
19
+ end
20
+
21
+ context 'when enabled' do
22
+ before { allow ( instance ) . to receive ( :capture_flamegraph? ) . and_return ( true ) }
23
+
24
+ it 'captures a flamegraph' do
25
+ expect_any_instance_of ( Object ) . to receive ( :flamegraph )
26
+ subject
27
+ end
28
+ end
29
+
30
+ describe '.capture_flamegraph?' do
31
+ subject { instance . capture_flamegraph? ( env ) }
32
+
33
+ it { is_expected . to be false }
34
+
35
+ context 'when HTTP_X_SINGED is true' do
36
+ let ( :headers ) { { 'HTTP_X_SINGED' => 'true' } }
37
+
38
+ it { is_expected . to be true }
39
+ end
40
+ end
41
+ end
Original file line number Diff line number Diff line change 96
96
# # test failures related to randomization by passing the same `--seed` value
97
97
# # as the one that triggered the failure.
98
98
# Kernel.srand config.seed
99
+
100
+ config . before do
101
+ Singed . output_directory = '/tmp/speedscope'
102
+ end
99
103
end
You can’t perform that action at this time.
0 commit comments