Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-10-18 14:47:04 +0300
committerDouwe Maan <douwe@gitlab.com>2016-10-18 14:47:04 +0300
commitb56f093c2ba4739b9d6cec595b8af3ee61a0d12b (patch)
tree94d3189225642dc39b09e189a00edcceecd8d3a6
parentc9d7ba4d696bfd0198ac75db6e1b2a08b4517f82 (diff)
parentbfb20200e9d1e7edd82a27d18d849ffba043845a (diff)
Merge branch 'looser-time-in-specs' into 'master'
Add a be_like_time matcher and use it in specs ## What does this MR do? Introduces a be_like_time matcher and refactors existing code to use it ## Are there points in the code the reviewer needs to double check? A few sites use be_within(2.seconds) or 5.minutes - I didn't change those ## Why was this MR needed? A custom matcher helps to document that we need to compare times loosely, and keeps the fudge factor from being declared in multiple places. ## Screenshots (if relevant) ## Does this MR meet the acceptance criteria? - [ ] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added - [ ] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md) - [ ] API support added - Tests - [ ] Added for this feature/bug - [ ] All builds are passing - [ ] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html) - [ ] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [ ] Branch has no merge conflicts with `master` (if it does - rebase it please) - [ ] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) ## What are the relevant issue numbers? Related to !6935 See merge request !6936
-rw-r--r--spec/models/issue/metrics_spec.rb8
-rw-r--r--spec/models/merge_request/metrics_spec.rb2
-rw-r--r--spec/requests/api/issues_spec.rb4
-rw-r--r--spec/requests/api/notes_spec.rb2
-rw-r--r--spec/services/create_deployment_service_spec.rb6
-rw-r--r--spec/services/git_push_service_spec.rb2
-rw-r--r--spec/support/matchers/be_like_time.rb13
-rw-r--r--spec/workers/pipeline_metrics_worker_spec.rb4
8 files changed, 27 insertions, 14 deletions
diff --git a/spec/models/issue/metrics_spec.rb b/spec/models/issue/metrics_spec.rb
index e170b087ebc..2459a49f095 100644
--- a/spec/models/issue/metrics_spec.rb
+++ b/spec/models/issue/metrics_spec.rb
@@ -13,7 +13,7 @@ describe Issue::Metrics, models: true do
metrics = subject.metrics
expect(metrics).to be_present
- expect(metrics.first_associated_with_milestone_at).to be_within(1.second).of(time)
+ expect(metrics.first_associated_with_milestone_at).to be_like_time(time)
end
it "does not record the second time an issue is associated with a milestone" do
@@ -24,7 +24,7 @@ describe Issue::Metrics, models: true do
metrics = subject.metrics
expect(metrics).to be_present
- expect(metrics.first_associated_with_milestone_at).to be_within(1.second).of(time)
+ expect(metrics.first_associated_with_milestone_at).to be_like_time(time)
end
end
@@ -36,7 +36,7 @@ describe Issue::Metrics, models: true do
metrics = subject.metrics
expect(metrics).to be_present
- expect(metrics.first_added_to_board_at).to be_within(1.second).of(time)
+ expect(metrics.first_added_to_board_at).to be_like_time(time)
end
it "does not record the second time an issue is associated with a list label" do
@@ -48,7 +48,7 @@ describe Issue::Metrics, models: true do
metrics = subject.metrics
expect(metrics).to be_present
- expect(metrics.first_added_to_board_at).to be_within(1.second).of(time)
+ expect(metrics.first_added_to_board_at).to be_like_time(time)
end
end
end
diff --git a/spec/models/merge_request/metrics_spec.rb b/spec/models/merge_request/metrics_spec.rb
index a79dd215d41..255db41cb19 100644
--- a/spec/models/merge_request/metrics_spec.rb
+++ b/spec/models/merge_request/metrics_spec.rb
@@ -12,7 +12,7 @@ describe MergeRequest::Metrics, models: true do
metrics = subject.metrics
expect(metrics).to be_present
- expect(metrics.merged_at).to be_within(1.second).of(time)
+ expect(metrics.merged_at).to be_like_time(time)
end
end
end
diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb
index f840778ae9b..beed53d1e5c 100644
--- a/spec/requests/api/issues_spec.rb
+++ b/spec/requests/api/issues_spec.rb
@@ -694,7 +694,7 @@ describe API::API, api: true do
title: 'new issue', labels: 'label, label2', created_at: creation_time
expect(response).to have_http_status(201)
- expect(Time.parse(json_response['created_at'])).to be_within(1.second).of(creation_time)
+ expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time)
end
end
end
@@ -895,7 +895,7 @@ describe API::API, api: true do
expect(response).to have_http_status(200)
expect(json_response['labels']).to include 'label3'
- expect(Time.parse(json_response['updated_at'])).to be_within(1.second).of(update_time)
+ expect(Time.parse(json_response['updated_at'])).to be_like_time(update_time)
end
end
end
diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb
index 063a8706e76..d58bedc3bf7 100644
--- a/spec/requests/api/notes_spec.rb
+++ b/spec/requests/api/notes_spec.rb
@@ -217,7 +217,7 @@ describe API::API, api: true do
expect(response).to have_http_status(201)
expect(json_response['body']).to eq('hi!')
expect(json_response['author']['username']).to eq(user.username)
- expect(Time.parse(json_response['created_at'])).to be_within(1.second).of(creation_time)
+ expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time)
end
end
diff --git a/spec/services/create_deployment_service_spec.rb b/spec/services/create_deployment_service_spec.rb
index 5fe56e7725f..0b84c7262c3 100644
--- a/spec/services/create_deployment_service_spec.rb
+++ b/spec/services/create_deployment_service_spec.rb
@@ -201,7 +201,7 @@ describe CreateDeploymentService, services: true do
time = Time.now
Timecop.freeze(time) { service.execute }
- expect(merge_request.reload.metrics.first_deployed_to_production_at).to be_within(1.second).of(time)
+ expect(merge_request.reload.metrics.first_deployed_to_production_at).to be_like_time(time)
end
it "doesn't set the time if the deploy's environment is not 'production'" do
@@ -227,13 +227,13 @@ describe CreateDeploymentService, services: true do
time = Time.now
Timecop.freeze(time) { service.execute }
- expect(merge_request.reload.metrics.first_deployed_to_production_at).to be_within(1.second).of(time)
+ expect(merge_request.reload.metrics.first_deployed_to_production_at).to be_like_time(time)
# Current deploy
service = described_class.new(project, user, params)
Timecop.freeze(time + 12.hours) { service.execute }
- expect(merge_request.reload.metrics.first_deployed_to_production_at).to be_within(1.second).of(time)
+ expect(merge_request.reload.metrics.first_deployed_to_production_at).to be_like_time(time)
end
end
diff --git a/spec/services/git_push_service_spec.rb b/spec/services/git_push_service_spec.rb
index dd2a9e9903a..8dda34c7a03 100644
--- a/spec/services/git_push_service_spec.rb
+++ b/spec/services/git_push_service_spec.rb
@@ -364,7 +364,7 @@ describe GitPushService, services: true do
it 'sets the metric for referenced issues' do
execute_service(project, user, @oldrev, @newrev, @ref)
- expect(issue.reload.metrics.first_mentioned_in_commit_at).to be_within(1.second).of(commit_time)
+ expect(issue.reload.metrics.first_mentioned_in_commit_at).to be_like_time(commit_time)
end
it 'does not set the metric for non-referenced issues' do
diff --git a/spec/support/matchers/be_like_time.rb b/spec/support/matchers/be_like_time.rb
new file mode 100644
index 00000000000..1f27390eab7
--- /dev/null
+++ b/spec/support/matchers/be_like_time.rb
@@ -0,0 +1,13 @@
+RSpec::Matchers.define :be_like_time do |expected|
+ match do |actual|
+ expect(actual).to be_within(1.second).of(expected)
+ end
+
+ description do
+ "within one second of #{expected}"
+ end
+
+ failure_message do |actual|
+ "expected #{actual} to be within one second of #{expected}"
+ end
+end
diff --git a/spec/workers/pipeline_metrics_worker_spec.rb b/spec/workers/pipeline_metrics_worker_spec.rb
index 232478c9735..2c9e7c2cd02 100644
--- a/spec/workers/pipeline_metrics_worker_spec.rb
+++ b/spec/workers/pipeline_metrics_worker_spec.rb
@@ -23,7 +23,7 @@ describe PipelineMetricsWorker do
it 'records the build start time' do
subject
- expect(merge_request.reload.metrics.latest_build_started_at).to be_within(1.second).of(pipeline.started_at)
+ expect(merge_request.reload.metrics.latest_build_started_at).to be_like_time(pipeline.started_at)
end
it 'clears the build end time' do
@@ -39,7 +39,7 @@ describe PipelineMetricsWorker do
it 'records the build end time' do
subject
- expect(merge_request.reload.metrics.latest_build_finished_at).to be_within(1.second).of(pipeline.finished_at)
+ expect(merge_request.reload.metrics.latest_build_finished_at).to be_like_time(pipeline.finished_at)
end
end
end