File tree Expand file tree Collapse file tree 4 files changed +48
-6
lines changed Expand file tree Collapse file tree 4 files changed +48
-6
lines changed Original file line number Diff line number Diff line change 1919 ast (~> 2.4.1 )
2020 racc
2121 racc (1.7.3 )
22+ rack (3.1.8 )
23+ rack-test (2.1.0 )
24+ rack (>= 1.3 )
2225 rainbow (3.1.1 )
2326 rake (13.0.6 )
2427 regexp_parser (2.9.0 )
@@ -72,6 +75,7 @@ PLATFORMS
7275 ruby
7376
7477DEPENDENCIES
78+ rack-test
7579 rake (~> 13.0 )
7680 rspec
7781 singed !
Original file line number Diff line number Diff line change @@ -9,15 +9,11 @@ def initialize(app)
99 end
1010
1111 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 ) }
1614 else
1715 @app . call ( env )
1816 end
19-
20- [ status , headers , body ]
2117 end
2218
2319 def capture_flamegraph? ( env )
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
2424 spec . add_dependency "colorize"
2525 spec . add_dependency "stackprof" , ">= 0.2.13"
2626
27+ spec . add_development_dependency "rack-test"
2728 spec . add_development_dependency "rake" , "~> 13.0"
2829 spec . add_development_dependency "rspec"
2930end
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 ( instance ) . 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 ( instance ) . 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
You can’t perform that action at this time.
0 commit comments