rails-response-dumper 6.2.0 → 8.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails_response_dumper/option_parser.rb +4 -0
- data/lib/rails_response_dumper/runner.rb +40 -15
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0440c636303c8b08698e78f7e8de3dbc5815aa0112f1af94195c233c072a8115
|
4
|
+
data.tar.gz: 2f71c8824b9c3ec3324ad3df89ff7b7d1d57df1614161ee2cb4d7159ae9466bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cd987f5bc5274530b1ae896bb1917b21dcd1804858cf7f243df285b605b67f936c8614747873d5a2c5c719e2da79a9189ecef0b628cd08ecbbedeb391d4a479
|
7
|
+
data.tar.gz: 424fb1aede5523cd47a17ceaca8b254c9ccef0413f8a32c44cbd6b1f73bdfcd755814e67c50a88d28a5d2242981f1c0322aba57f54480acad694cc1a791d87f4
|
@@ -29,6 +29,10 @@ module RailsResponseDumper
|
|
29
29
|
options[:verbose] = v
|
30
30
|
end
|
31
31
|
|
32
|
+
opts.on('--profile', 'Enable profiling of dumps and list the slowest.') do |v|
|
33
|
+
options[:profile] = v
|
34
|
+
end
|
35
|
+
|
32
36
|
opts.on('--order TYPE', 'Run dumps by the specified order type.') do |v|
|
33
37
|
options[:order] = v
|
34
38
|
end
|
@@ -17,7 +17,7 @@ module RailsResponseDumper
|
|
17
17
|
if options[:filenames].present?
|
18
18
|
globs = options[:filenames]
|
19
19
|
else
|
20
|
-
globs = ['dumpers
|
20
|
+
globs = ['dumpers/**/*_dumper.rb']
|
21
21
|
FileUtils.rm_rf dumps_dir
|
22
22
|
end
|
23
23
|
|
@@ -53,6 +53,8 @@ module RailsResponseDumper
|
|
53
53
|
dumper_blocks.shuffle!(random: random)
|
54
54
|
end
|
55
55
|
|
56
|
+
profile = {}
|
57
|
+
|
56
58
|
catch :fail_fast do
|
57
59
|
dumper_blocks.each do |(defined, dump_block)|
|
58
60
|
name = "#{defined.name}.#{dump_block.name}"
|
@@ -64,12 +66,14 @@ module RailsResponseDumper
|
|
64
66
|
dumper.mock_setup
|
65
67
|
begin
|
66
68
|
rollback_after do
|
69
|
+
t0 = Time.now
|
67
70
|
dumper.instance_eval(&defined.before_block) if defined.before_block
|
68
71
|
begin
|
69
72
|
dumper.instance_eval(&dump_block.block)
|
70
73
|
ensure
|
71
74
|
dumper.instance_eval(&defined.after_block) if defined.after_block
|
72
75
|
end
|
76
|
+
profile[name] = Time.now - t0
|
73
77
|
end
|
74
78
|
ensure
|
75
79
|
dumper.mock_teardown
|
@@ -98,23 +102,29 @@ module RailsResponseDumper
|
|
98
102
|
|
99
103
|
dump = {
|
100
104
|
request: {
|
101
|
-
method: request.method,
|
102
105
|
url: request.url,
|
103
|
-
|
106
|
+
env: request.headers.to_h
|
104
107
|
},
|
105
108
|
response: {
|
106
109
|
status: response.status,
|
107
110
|
statusText: response.status_message,
|
108
|
-
headers: response.headers
|
109
|
-
body: response.body
|
111
|
+
headers: response.headers
|
110
112
|
}
|
111
113
|
}
|
112
114
|
|
115
|
+
# request.headers includes nonstandard internal data, some of which also lacks default deterministic
|
116
|
+
# serialization. Here we only want CGI standard and HTTP variables.
|
117
|
+
dump[:request][:env].filter! do |key|
|
118
|
+
key.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || key.start_with?('HTTP_')
|
119
|
+
end
|
120
|
+
|
113
121
|
dump[:response].delete(:headers) if options[:exclude_response_headers]
|
114
122
|
|
115
123
|
dump[:timestamp] = timestamp.iso8601 unless options[:exclude_timestamp]
|
116
124
|
|
117
125
|
File.write("#{dumper_dir}/#{index}.json", JSON.pretty_generate(dump))
|
126
|
+
File.write("#{dumper_dir}/#{index}.request_body", request.body.string, mode: 'wb')
|
127
|
+
File.write("#{dumper_dir}/#{index}.response_body", response.body, mode: 'wb')
|
118
128
|
end
|
119
129
|
|
120
130
|
RailsResponseDumper.print_color('.', :green)
|
@@ -134,21 +144,36 @@ module RailsResponseDumper
|
|
134
144
|
end
|
135
145
|
|
136
146
|
puts
|
137
|
-
return if errors.blank?
|
138
147
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
148
|
+
unless errors.blank?
|
149
|
+
puts
|
150
|
+
|
151
|
+
errors.each do |error|
|
152
|
+
RailsResponseDumper.print_color(
|
153
|
+
"#{error[:dumper_location]} #{error[:name]} received #{error[:exception]}\n",
|
154
|
+
:red
|
155
|
+
)
|
156
|
+
error[:exception].full_message(highlight: RailsResponseDumper::COLORIZE).lines do |line|
|
157
|
+
RailsResponseDumper.print_color(line, :cyan)
|
158
|
+
end
|
159
|
+
puts
|
147
160
|
end
|
161
|
+
end
|
162
|
+
|
163
|
+
if options.include?(:profile)
|
164
|
+
puts
|
165
|
+
|
166
|
+
# Sort in descending order to obtain the 10 slowest dumps.
|
167
|
+
timings = profile.to_a.sort_by { |(_key, value)| -value }
|
168
|
+
timings.first(10).each do |(dump, time)|
|
169
|
+
formatted_time = format('%.2f', time)
|
170
|
+
puts "#{dump} #{formatted_time} s"
|
171
|
+
end
|
172
|
+
|
148
173
|
puts
|
149
174
|
end
|
150
175
|
|
151
|
-
exit(
|
176
|
+
exit(errors.blank?)
|
152
177
|
end
|
153
178
|
|
154
179
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-response-dumper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 8.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pioneer Valley Books
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -48,7 +48,7 @@ description: |
|
|
48
48
|
Rails Response Dumper is a library and command line tool to dump HTTP
|
49
49
|
responses from a Rails application to the file system. These responses can
|
50
50
|
then be consumed by other tools for testing and verification purposes.
|
51
|
-
email:
|
51
|
+
email:
|
52
52
|
executables:
|
53
53
|
- rails-response-dumper
|
54
54
|
extensions: []
|
@@ -67,7 +67,7 @@ licenses:
|
|
67
67
|
- MIT
|
68
68
|
metadata:
|
69
69
|
rubygems_mfa_required: 'true'
|
70
|
-
post_install_message:
|
70
|
+
post_install_message:
|
71
71
|
rdoc_options: []
|
72
72
|
require_paths:
|
73
73
|
- lib
|
@@ -82,8 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
|
-
rubygems_version: 3.3
|
86
|
-
signing_key:
|
85
|
+
rubygems_version: 3.5.3
|
86
|
+
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: Dump HTTP responses from a Rails application to the file system
|
89
89
|
test_files: []
|