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
Hide 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
...
@@ -15,10 +15,16 @@ RSpec.describe ActiveRecord::QueryRecorder do
let
(
:backtrace
)
{
%r{QueryRecorder backtrace: --> (
\w
+/)*
\w
+
\.
rb:
\d
+:in `.*'}
}
let
(
:backtrace
)
{
%r{QueryRecorder backtrace: --> (
\w
+/)*
\w
+
\.
rb:
\d
+:in `.*'}
}
let
(
:duration_line
)
{
%r{QueryRecorder DURATION: -->
\d
+
\.\d
+}
}
let
(
:duration_line
)
{
%r{QueryRecorder DURATION: -->
\d
+
\.\d
+}
}
def
match
_section
(
query
,
lines
)
def
expect
_section
(
query
,
lines
)
query_lines
=
lines
.
take
(
query
.
size
)
query_lines
=
lines
.
take
(
query
.
size
)
# the query comes first
expect
(
query_lines
).
to
match
(
query
)
expect
(
query_lines
).
to
match
(
query
)
# followed by the duration
expect
(
lines
[
query
.
size
]).
to
match
(
duration_line
)
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
)
}
backtrace_lines
=
lines
.
drop
(
query
.
size
+
1
).
take_while
{
|
line
|
line
.
match
(
backtrace
)
}
expect
(
backtrace_lines
).
not_to
be_empty
expect
(
backtrace_lines
).
not_to
be_empty
...
@@ -26,7 +32,7 @@ RSpec.describe ActiveRecord::QueryRecorder do
...
@@ -26,7 +32,7 @@ RSpec.describe ActiveRecord::QueryRecorder do
lines
.
drop
(
query
.
size
+
1
+
backtrace_lines
.
size
)
lines
.
drop
(
query
.
size
+
1
+
backtrace_lines
.
size
)
end
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
io
=
StringIO
.
new
control
=
ActiveRecord
::
QueryRecorder
.
new
(
log_file:
io
,
query_recorder_debug:
true
)
do
control
=
ActiveRecord
::
QueryRecorder
.
new
(
log_file:
io
,
query_recorder_debug:
true
)
do
...
@@ -53,9 +59,9 @@ RSpec.describe ActiveRecord::QueryRecorder do
...
@@ -53,9 +59,9 @@ RSpec.describe ActiveRecord::QueryRecorder do
lines
=
io
.
string
.
lines
.
map
(
&
:chomp
)
lines
=
io
.
string
.
lines
.
map
(
&
:chomp
)
expect
(
lines
).
to
all
(
start_with
(
'QueryRecorder'
))
expect
(
lines
).
to
all
(
start_with
(
'QueryRecorder'
))
lines
=
match
_section
([
query_a
],
lines
)
lines
=
expect
_section
([
query_a
],
lines
)
lines
=
match
_section
([
query_b
],
lines
)
lines
=
expect
_section
([
query_b
],
lines
)
lines
=
match
_section
([
query_c_a
,
query_c_b
,
query_c_c
,
query_c_d
],
lines
)
lines
=
expect
_section
([
query_c_a
,
query_c_b
,
query_c_c
,
query_c_d
],
lines
)
expect
(
lines
).
to
be_empty
expect
(
lines
).
to
be_empty
end
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