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
f5114783
Commit
f5114783
authored
Jan 22, 2018
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use define_method to define devine_metric_method. (couldn't resist)
parent
a760445f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
15 deletions
+12
-15
spec/lib/gitlab/metrics/concern_spec.rb
spec/lib/gitlab/metrics/concern_spec.rb
+12
-15
No files found.
spec/lib/gitlab/metrics/concern_spec.rb
View file @
f5114783
...
...
@@ -8,17 +8,15 @@ describe Gitlab::Metrics::Concern do
let
(
:metric_name
)
{
:sample_metric
}
describe
"#define_
#{
metric_type
}
"
do
let
(
:_metric_type
)
{
metric_type
}
def
define_metric_method
(
**
args
)
subject
.
send
(
"define_
#{
_metric_type
}
"
,
metric_name
,
**
args
)
define_method
(
:call_define_metric_method
)
do
|**
args
|
subject
.
__send__
(
"define_
#{
metric_type
}
"
,
metric_name
,
**
args
)
end
context
'metrics access method not defined'
do
it
"defines metrics accessing method"
do
expect
(
subject
).
not_to
respond_to
(
metric_name
)
define_metric_method
(
docstring:
docstring
)
call_
define_metric_method
(
docstring:
docstring
)
expect
(
subject
).
to
respond_to
(
metric_name
)
end
...
...
@@ -26,11 +24,11 @@ describe Gitlab::Metrics::Concern do
context
'metrics access method defined'
do
before
do
define_metric_method
(
docstring:
docstring
)
call_
define_metric_method
(
docstring:
docstring
)
end
it
'raises error when trying to redefine method'
do
expect
{
define_metric_method
(
docstring:
docstring
)
}.
to
raise_error
(
ArgumentError
)
expect
{
call_
define_metric_method
(
docstring:
docstring
)
}.
to
raise_error
(
ArgumentError
)
end
context
'metric is not cached'
do
...
...
@@ -56,18 +54,17 @@ describe Gitlab::Metrics::Concern do
end
describe
"#fetch_
#{
metric_type
}
"
do
let
(
:_metric_type
)
{
metric_type
}
let
(
:null_metric
)
{
Gitlab
::
Metrics
::
NullMetric
.
instance
}
def
fetch_metric_method
(
**
args
)
subject
.
send
(
"fetch_
#{
_
metric_type
}
"
,
metric_name
,
**
args
)
def
ine_method
(
:call_fetch_metric_method
)
do
|**
args
|
subject
.
__send__
(
"fetch_
#{
metric_type
}
"
,
metric_name
,
**
args
)
end
context
"when
#{
metric_type
}
is not cached"
do
it
'initializes counter metric'
do
allow
(
Gitlab
::
Metrics
).
to
receive
(
metric_type
).
and_return
(
null_metric
)
fetch_metric_method
(
docstring:
docstring
)
call_
fetch_metric_method
(
docstring:
docstring
)
expect
(
Gitlab
::
Metrics
).
to
have_received
(
metric_type
).
with
(
metric_name
,
docstring
,
*
args
)
end
...
...
@@ -75,13 +72,13 @@ describe Gitlab::Metrics::Concern do
context
"when
#{
metric_type
}
is cached"
do
before
do
fetch_metric_method
(
docstring:
docstring
)
call_
fetch_metric_method
(
docstring:
docstring
)
end
it
'uses class metric cache'
do
expect
(
Gitlab
::
Metrics
).
not_to
receive
(
metric_type
)
fetch_metric_method
(
docstring:
docstring
)
call_
fetch_metric_method
(
docstring:
docstring
)
end
context
'when metric is reloaded'
do
...
...
@@ -92,7 +89,7 @@ describe Gitlab::Metrics::Concern do
it
"initializes
#{
metric_type
}
metric"
do
allow
(
Gitlab
::
Metrics
).
to
receive
(
metric_type
).
and_return
(
null_metric
)
fetch_metric_method
(
docstring:
docstring
)
call_
fetch_metric_method
(
docstring:
docstring
)
expect
(
Gitlab
::
Metrics
).
to
have_received
(
metric_type
).
with
(
metric_name
,
docstring
,
*
args
)
end
...
...
@@ -101,7 +98,7 @@ describe Gitlab::Metrics::Concern do
context
'when metric is configured with feature'
do
let
(
:feature_name
)
{
:some_metric_feature
}
let
(
:metric
)
{
fetch_metric_method
(
docstring:
docstring
,
with_feature:
feature_name
)
}
let
(
:metric
)
{
call_
fetch_metric_method
(
docstring:
docstring
,
with_feature:
feature_name
)
}
context
'when feature is enabled'
do
before
do
...
...
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