Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
4ad59b22
Commit
4ad59b22
authored
Apr 19, 2021
by
Alex Kalderimis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Aggregate failures in complex test
Also some style changes for clarity
parent
49e58954
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
spec/support_specs/helpers/active_record/query_recorder_spec.rb
...upport_specs/helpers/active_record/query_recorder_spec.rb
+11
-5
No files found.
spec/support_specs/helpers/active_record/query_recorder_spec.rb
View file @
4ad59b22
...
...
@@ -15,10 +15,16 @@ RSpec.describe ActiveRecord::QueryRecorder do
let
(
:backtrace
)
{
%r{QueryRecorder backtrace: --> (
\w
+/)*
\w
+
\.
rb:
\d
+:in `.*'}
}
let
(
:duration_line
)
{
%r{QueryRecorder DURATION: -->
\d
+
\.\d
+}
}
def
match
_section
(
query
,
lines
)
def
expect
_section
(
query
,
lines
)
query_lines
=
lines
.
take
(
query
.
size
)
# the query comes first
expect
(
query_lines
).
to
match
(
query
)
# followed by the duration
expect
(
lines
[
query
.
size
]).
to
match
(
duration_line
)
# and then one or more lines of backtrace
backtrace_lines
=
lines
.
drop
(
query
.
size
+
1
).
take_while
{
|
line
|
line
.
match
(
backtrace
)
}
expect
(
backtrace_lines
).
not_to
be_empty
...
...
@@ -26,7 +32,7 @@ RSpec.describe ActiveRecord::QueryRecorder do
lines
.
drop
(
query
.
size
+
1
+
backtrace_lines
.
size
)
end
it
'prints SQL, duration and backtrace, all prefixed with QueryRecorder'
do
it
'prints SQL, duration and backtrace, all prefixed with QueryRecorder'
,
:aggregate_failures
do
io
=
StringIO
.
new
control
=
ActiveRecord
::
QueryRecorder
.
new
(
log_file:
io
,
query_recorder_debug:
true
)
do
...
...
@@ -53,9 +59,9 @@ RSpec.describe ActiveRecord::QueryRecorder do
lines
=
io
.
string
.
lines
.
map
(
&
:chomp
)
expect
(
lines
).
to
all
(
start_with
(
'QueryRecorder'
))
lines
=
match
_section
([
query_a
],
lines
)
lines
=
match
_section
([
query_b
],
lines
)
lines
=
match
_section
([
query_c_a
,
query_c_b
,
query_c_c
,
query_c_d
],
lines
)
lines
=
expect
_section
([
query_a
],
lines
)
lines
=
expect
_section
([
query_b
],
lines
)
lines
=
expect
_section
([
query_c_a
,
query_c_b
,
query_c_c
,
query_c_d
],
lines
)
expect
(
lines
).
to
be_empty
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment