Commit a0265d4f authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'leaky-constant-fix-36' into 'master'

Fix leaky constant in diff collection spec

See merge request gitlab-org/gitlab!32163
parents 72d1ea6d f411b207
......@@ -351,7 +351,6 @@ RSpec/LeakyConstantDeclaration:
- 'spec/db/schema_spec.rb'
- 'spec/lib/feature_spec.rb'
- 'spec/lib/gitlab/config/entry/simplifiable_spec.rb'
- 'spec/lib/gitlab/git/diff_collection_spec.rb'
- 'spec/lib/gitlab/import_export/import_test_coverage_spec.rb'
- 'spec/lib/gitlab/quick_actions/dsl_spec.rb'
- 'spec/lib/marginalia_spec.rb'
......
---
title: Fix leaky constant issue in diff collection spec
merge_request: 32163
author: Rajendra Kadam
type: fixed
......@@ -3,6 +3,31 @@
require 'spec_helper'
describe Gitlab::Git::DiffCollection, :seed_helper do
before do
stub_const('MutatingConstantIterator', Class.new)
MutatingConstantIterator.class_eval do
include Enumerable
def initialize(count, value)
@count = count
@value = value
end
def each
return enum_for(:each) unless block_given?
loop do
break if @count.zero?
# It is critical to decrement before yielding. We may never reach the lines after 'yield'.
@count -= 1
yield @value
end
end
end
end
subject do
Gitlab::Git::DiffCollection.new(
iterator,
......@@ -659,25 +684,4 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
def fake_diff(line_length, line_count)
{ 'diff' => "#{'a' * line_length}\n" * line_count }
end
class MutatingConstantIterator
include Enumerable
def initialize(count, value)
@count = count
@value = value
end
def each
return enum_for(:each) unless block_given?
loop do
break if @count.zero?
# It is critical to decrement before yielding. We may never reach the lines after 'yield'.
@count -= 1
yield @value
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment