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
2132a863
Commit
2132a863
authored
Feb 20, 2019
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix and document an RSpec::Parameterized::TableSyntax edge-case
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
1abf34cb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
17 deletions
+16
-17
doc/development/testing_guide/best_practices.md
doc/development/testing_guide/best_practices.md
+5
-5
ee/spec/models/vulnerabilities/occurrence_spec.rb
ee/spec/models/vulnerabilities/occurrence_spec.rb
+5
-5
spec/models/prometheus_metric_spec.rb
spec/models/prometheus_metric_spec.rb
+6
-7
No files found.
doc/development/testing_guide/best_practices.md
View file @
2132a863
...
...
@@ -358,16 +358,11 @@ range of inputs, might look like this:
describe
"#=="
do
using
RSpec
::
Parameterized
::
TableSyntax
let
(
:project1
)
{
create
(
:project
)
}
let
(
:project2
)
{
create
(
:project
)
}
where
(
:a
,
:b
,
:result
)
do
1
|
1
|
true
1
|
2
|
false
true
|
true
|
true
true
|
false
|
false
project1
|
project1
|
true
project2
|
project2
|
true
project
1
|
project2
|
false
end
with_them
do
...
...
@@ -380,6 +375,11 @@ describe "#==" do
end
```
CAUTION:
**Caution:**
Only use simple values as input in the
`where`
block. Using procs, stateful
objects, FactoryBot-created objects etc. can lead to
[
unexpected results
](
https://github.com/tomykaira/rspec-parameterized/issues/8
)
.
### Prometheus tests
Prometheus metrics may be preserved from one test run to another. To ensure that metrics are
...
...
ee/spec/models/vulnerabilities/occurrence_spec.rb
View file @
2132a863
...
...
@@ -46,15 +46,15 @@ describe Vulnerabilities::Occurrence do
using
RSpec
::
Parameterized
::
TableSyntax
# we use block to delay object creations
where
(
:key
,
:
value_block
)
do
:primary_identifier
|
->
{
create
(
:vulnerabilities_identifier
)
}
:scanner
|
->
{
create
(
:vulnerabilities_scanner
)
}
:project
|
->
{
create
(
:project
)
}
where
(
:key
,
:
factory_name
)
do
:primary_identifier
|
:vulnerabilities_identifier
:scanner
|
:vulnerabilities_scanner
:project
|
:project
end
with_them
do
it
"is valid"
do
expect
{
new_occurrence
.
update!
({
key
=>
value_block
.
call
})
}.
not_to
raise_error
expect
{
new_occurrence
.
update!
({
key
=>
create
(
factory_name
)
})
}.
not_to
raise_error
end
end
end
...
...
spec/models/prometheus_metric_spec.rb
View file @
2132a863
...
...
@@ -4,7 +4,6 @@ require 'spec_helper'
describe
PrometheusMetric
do
subject
{
build
(
:prometheus_metric
)
}
let
(
:other_project
)
{
build
(
:project
)
}
it_behaves_like
'having unique enum values'
...
...
@@ -16,17 +15,17 @@ describe PrometheusMetric do
describe
'common metrics'
do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:common
,
:project
,
:result
)
do
false
|
other_project
|
true
false
|
nil
|
false
true
|
other_project
|
false
true
|
nil
|
true
where
(
:common
,
:
with_
project
,
:result
)
do
false
|
true
|
true
false
|
false
|
false
true
|
true
|
false
true
|
false
|
true
end
with_them
do
before
do
subject
.
common
=
common
subject
.
project
=
project
subject
.
project
=
with_project
?
build
(
:project
)
:
nil
end
it
{
expect
(
subject
.
valid?
).
to
eq
(
result
)
}
...
...
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