diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-09-20 08:47:36 +0300 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-09-20 10:53:14 +0300 |
commit | d0e101e997347b0b52d4ef3a945a0f26571546a2 (patch) | |
tree | 684b05bbd6f507e7cb90d8fec98a49b56975ed35 /spec/support | |
parent | cebfe053a85c8e376b35101686ba05225c6f4e65 (diff) |
Fix all cycle analytics specs.
A number of failures were introduced due to performance
improvements (like pre-calculating metrics).
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/cycle_analytics_helpers.rb | 15 | ||||
-rw-r--r-- | spec/support/cycle_analytics_helpers/test_generation.rb | 13 |
2 files changed, 21 insertions, 7 deletions
diff --git a/spec/support/cycle_analytics_helpers.rb b/spec/support/cycle_analytics_helpers.rb index ffd3eb60b80..e8e760a6187 100644 --- a/spec/support/cycle_analytics_helpers.rb +++ b/spec/support/cycle_analytics_helpers.rb @@ -1,12 +1,12 @@ module CycleAnalyticsHelpers - def create_commit_referencing_issue(issue) - branch_name = random_git_name + def create_commit_referencing_issue(issue, branch_name: random_git_name) project.repository.add_branch(user, branch_name, 'master') create_commit("Commit for ##{issue.iid}", issue.project, user, branch_name) end def create_commit(message, project, user, branch_name) filename = random_git_name + oldrev = project.repository.commit(branch_name).sha options = { committer: project.repository.user_to_committer(user), @@ -20,14 +20,17 @@ module CycleAnalyticsHelpers GitPushService.new(project, user, - oldrev: project.repository.commit(branch_name).sha, + oldrev: oldrev, newrev: commit_sha, ref: 'refs/heads/master').execute end - def create_merge_request_closing_issue(issue, message: nil) - source_branch = random_git_name - project.repository.add_branch(user, source_branch, 'master') + def create_merge_request_closing_issue(issue, message: nil, source_branch: nil) + if !source_branch || project.repository.commit(source_branch).blank? + source_branch = random_git_name + project.repository.add_branch(user, source_branch, 'master') + end + sha = project.repository.commit_file(user, random_git_name, "content", "commit message", source_branch, false) project.repository.commit(sha) diff --git a/spec/support/cycle_analytics_helpers/test_generation.rb b/spec/support/cycle_analytics_helpers/test_generation.rb index 52609524564..4d5ce86691f 100644 --- a/spec/support/cycle_analytics_helpers/test_generation.rb +++ b/spec/support/cycle_analytics_helpers/test_generation.rb @@ -18,8 +18,9 @@ module CycleAnalyticsHelpers # `context` (no lexical scope, so need to do `context.create` for factories, for example) and `data` (from the `data_fn`). # Each `condition_fn` is expected to implement a case which consitutes the end of the given cycle analytics phase. # before_end_fn: This function is run before calling the end time conditions. Used for setup that needs to be run between the start and end conditions. + # post_fn: Code that needs to be run after running the end time conditions. - def generate_cycle_analytics_spec(phase:, data_fn:, start_time_conditions:, end_time_conditions:, before_end_fn: nil) + def generate_cycle_analytics_spec(phase:, data_fn:, start_time_conditions:, end_time_conditions:, before_end_fn: nil, post_fn: nil) combinations_of_start_time_conditions = (1..start_time_conditions.size).flat_map { |size| start_time_conditions.combination(size).to_a } combinations_of_end_time_conditions = (1..end_time_conditions.size).flat_map { |size| end_time_conditions.combination(size).to_a } @@ -44,6 +45,8 @@ module CycleAnalyticsHelpers Timecop.freeze(end_time) { condition_fn[self, data] } end + Timecop.freeze(end_time + 1.day) { post_fn[self, data] } if post_fn + end_time - start_time end @@ -73,6 +76,8 @@ module CycleAnalyticsHelpers end_time_conditions.each do |condition_name, condition_fn| Timecop.freeze(end_time) { condition_fn[self, data] } end + + Timecop.freeze(end_time + 1.day) { post_fn[self, data] } if post_fn end # Turn off the stub before checking assertions @@ -99,6 +104,8 @@ module CycleAnalyticsHelpers Timecop.freeze(end_time) { condition_fn[self, data] } end + Timecop.freeze(end_time + 1.day) { post_fn[self, data] } if post_fn + expect(subject.send(phase)).to be_nil end end @@ -115,6 +122,8 @@ module CycleAnalyticsHelpers end_time_conditions.each_with_index do |(condition_name, condition_fn), index| Timecop.freeze(end_time + index.days) { condition_fn[self, data] } end + + Timecop.freeze(end_time + 1.day) { post_fn[self, data] } if post_fn end expect(subject.send(phase)).to be_nil @@ -132,6 +141,8 @@ module CycleAnalyticsHelpers start_time_conditions.each do |condition_name, condition_fn| Timecop.freeze(start_time) { condition_fn[self, data] } end + + post_fn[self, data] if post_fn end expect(subject.send(phase)).to be_nil |