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
032ebec0
Commit
032ebec0
authored
Nov 03, 2021
by
Dallas Reedy
Committed by
David Fernandez
Nov 03, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add RSpec metadata tags for time traveling around specs
parent
0634b222
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
69 additions
and
23 deletions
+69
-23
ee/spec/graphql/resolvers/dora_metrics_resolver_spec.rb
ee/spec/graphql/resolvers/dora_metrics_resolver_spec.rb
+1
-7
ee/spec/helpers/trial_status_widget_helper_spec.rb
ee/spec/helpers/trial_status_widget_helper_spec.rb
+1
-7
ee/spec/lib/gitlab/analytics/cycle_analytics/request_params_spec.rb
...b/gitlab/analytics/cycle_analytics/request_params_spec.rb
+2
-4
ee/spec/models/gitlab_subscription_spec.rb
ee/spec/models/gitlab_subscription_spec.rb
+3
-5
spec/support/time_travel.rb
spec/support/time_travel.rb
+29
-0
spec/support_specs/time_travel_spec.rb
spec/support_specs/time_travel_spec.rb
+33
-0
No files found.
ee/spec/graphql/resolvers/dora_metrics_resolver_spec.rb
View file @
032ebec0
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
RSpec
.
describe
Resolvers
::
DoraMetricsResolver
do
RSpec
.
describe
Resolvers
::
DoraMetricsResolver
,
time_travel_to:
'2021-05-01'
do
include
GraphqlHelpers
let_it_be
(
:guest
)
{
create
(
:user
)
}
...
...
@@ -15,12 +15,6 @@ RSpec.describe Resolvers::DoraMetricsResolver do
let
(
:current_user
)
{
reporter
}
let
(
:args
)
{
{
metric:
'deployment_frequency'
}
}
around
do
|
example
|
travel_to
'2021-05-01'
.
to_time
do
example
.
run
end
end
before_all
do
group
.
add_guest
(
guest
)
group
.
add_reporter
(
reporter
)
...
...
ee/spec/helpers/trial_status_widget_helper_spec.rb
View file @
032ebec0
...
...
@@ -3,9 +3,8 @@
require
'spec_helper'
RSpec
.
describe
TrialStatusWidgetHelper
,
:saas
do
describe
'data attributes for mounting Vue components'
do
describe
'data attributes for mounting Vue components'
,
:freeze_time
do
let
(
:trial_length
)
{
30
}
# days
let
(
:today_for_specs
)
{
Date
.
parse
(
'2021-01-15'
)
}
let
(
:trial_days_remaining
)
{
18
}
let
(
:trial_end_date
)
{
Date
.
current
.
advance
(
days:
trial_days_remaining
)
}
let
(
:trial_start_date
)
{
Date
.
current
.
advance
(
days:
trial_days_remaining
-
trial_length
)
}
...
...
@@ -23,7 +22,6 @@ RSpec.describe TrialStatusWidgetHelper, :saas do
end
before
do
travel_to
today_for_specs
build
(
:gitlab_subscription
,
:active_trial
,
namespace:
group
,
trial_starts_on:
trial_start_date
,
...
...
@@ -37,10 +35,6 @@ RSpec.describe TrialStatusWidgetHelper, :saas do
end
end
after
do
travel_back
end
describe
'#trial_status_popover_data_attrs'
do
using
RSpec
::
Parameterized
::
TableSyntax
...
...
ee/spec/lib/gitlab/analytics/cycle_analytics/request_params_spec.rb
View file @
032ebec0
...
...
@@ -41,10 +41,8 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::RequestParams do
params
[
:created_before
]
=
nil
end
it
'is valid'
do
travel_to
'2019-03-01'
do
expect
(
subject
).
to
be_valid
end
it
'is valid'
,
time_travel_to:
'2019-03-01'
do
expect
(
subject
).
to
be_valid
end
end
...
...
ee/spec/models/gitlab_subscription_spec.rb
View file @
032ebec0
...
...
@@ -9,11 +9,9 @@ RSpec.describe GitlabSubscription, :saas do
let_it_be
(
plan
)
{
create
(
plan
)
}
end
describe
'default values'
do
it
do
travel_to
(
Date
.
today
+
30
)
do
expect
(
subject
.
start_date
).
to
eq
(
Date
.
today
)
end
describe
'default values'
,
time_travel:
30
.
days
do
specify
do
expect
(
subject
.
start_date
).
to
eq
(
Date
.
today
)
end
end
...
...
spec/support/time_travel.rb
0 → 100644
View file @
032ebec0
# frozen_string_literal: true
require
'active_support/testing/time_helpers'
RSpec
.
configure
do
|
config
|
config
.
include
ActiveSupport
::
Testing
::
TimeHelpers
config
.
around
(
:example
,
:freeze_time
)
do
|
example
|
freeze_time
{
example
.
run
}
end
config
.
around
(
:example
,
:time_travel
)
do
|
example
|
duration
=
example
.
metadata
[
:time_travel
]
raise
'The time_travel RSpec metadata must have an ActiveSupport::Duration value (such as `30.days`).'
unless
duration
.
is_a?
(
ActiveSupport
::
Duration
)
travel
(
duration
)
{
example
.
run
}
end
config
.
around
(
:example
,
:time_travel_to
)
do
|
example
|
date_or_time
=
example
.
metadata
[
:time_travel_to
]
unless
date_or_time
.
respond_to?
(
:to_time
)
&&
date_or_time
.
to_time
.
present?
raise
'The time_travel_to RSpec metadata must have a Date or Time value.'
end
travel_to
(
date_or_time
)
{
example
.
run
}
end
end
spec/support_specs/time_travel_spec.rb
0 → 100644
View file @
032ebec0
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'time travel'
do
describe
':freeze_time'
do
it
'freezes time around a spec example'
,
:freeze_time
do
expect
{
sleep
0.1
}.
not_to
change
{
Time
.
now
.
to_f
}
end
end
describe
':time_travel'
do
today
=
Date
.
current
it
'time-travels by the given duration'
,
time_travel:
3
.
days
do
expect
(
Date
.
current
).
to
eq
(
today
+
3
.
days
)
end
it
'works with negative durations'
,
time_travel:
-
5
.
days
do
expect
(
Date
.
current
).
to
eq
(
today
-
5
.
days
)
end
end
describe
':time_travel_to'
do
it
'time-travels to the specified date'
,
time_travel_to:
'2020-01-01'
do
expect
(
Date
.
current
).
to
eq
(
Date
.
new
(
2020
,
1
,
1
))
end
it
'time-travels to the specified date & time'
,
time_travel_to:
'2020-02-02 10:30:45 -0700'
do
expect
(
Time
.
current
).
to
eq
(
Time
.
new
(
2020
,
2
,
2
,
17
,
30
,
45
,
'+00:00'
))
end
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