Commit f411b207 authored by Rajendra Kadam's avatar Rajendra Kadam Committed by Peter Leitzen

Fix leaky constant in diff collection spec

parent f9bc8d20
......@@ -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