Skip to content
Snippets Groups Projects
Commit 7894077b authored by Robert Speicher's avatar Robert Speicher
Browse files

Clean up Diff spec

parent 992c4e40
No related branches found
No related tags found
1 merge request!136Prepare for absorb
Loading
Loading
@@ -31,10 +31,10 @@ EOT
[".gitmodules"]).patches.first
end
 
describe :new do
describe '.new' do
context 'using a Hash' do
context 'with a small diff' do
let(:diff) { Gitlab::Git::Diff.new(@raw_diff_hash) }
let(:diff) { described_class.new(@raw_diff_hash) }
 
it 'initializes the diff' do
expect(diff.to_hash).to eq(@raw_diff_hash)
Loading
Loading
@@ -47,7 +47,7 @@ EOT
 
context 'using a diff that is too large' do
it 'prunes the diff' do
diff = Gitlab::Git::Diff.new(diff: 'a' * 204800)
diff = described_class.new(diff: 'a' * 204800)
 
expect(diff.diff).to be_empty
expect(diff).to be_too_large
Loading
Loading
@@ -57,7 +57,7 @@ EOT
 
context 'using a Rugged::Patch' do
context 'with a small diff' do
let(:diff) { Gitlab::Git::Diff.new(@rugged_diff) }
let(:diff) { described_class.new(@rugged_diff) }
 
it 'initializes the diff' do
expect(diff.to_hash).to eq(@raw_diff_hash.merge(too_large: nil))
Loading
Loading
@@ -73,7 +73,7 @@ EOT
expect_any_instance_of(String).to receive(:bytesize).
and_return(1024 * 1024 * 1024)
 
diff = Gitlab::Git::Diff.new(@rugged_diff)
diff = described_class.new(@rugged_diff)
 
expect(diff.diff).to be_empty
expect(diff).to be_too_large
Loading
Loading
@@ -85,12 +85,12 @@ EOT
# The patch total size is 200, with lines between 21 and 54.
# This is a quick-and-dirty way to test this. Ideally, a new patch is
# added to the test repo with a size that falls between the real limits.
stub_const('Gitlab::Git::Diff::DIFF_SIZE_LIMIT', 150)
stub_const('Gitlab::Git::Diff::DIFF_COLLAPSE_LIMIT', 100)
stub_const("#{described_class}::DIFF_SIZE_LIMIT", 150)
stub_const("#{described_class}::DIFF_COLLAPSE_LIMIT", 100)
end
 
it 'prunes the diff as a large diff instead of as a collapsed diff' do
diff = Gitlab::Git::Diff.new(@rugged_diff, collapse: true)
diff = described_class.new(@rugged_diff, collapse: true)
 
expect(diff.diff).to be_empty
expect(diff).to be_too_large
Loading
Loading
@@ -103,7 +103,7 @@ EOT
expect_any_instance_of(Rugged::Diff::Delta).to receive(:binary?).
and_return(true)
 
diff = Gitlab::Git::Diff.new(@rugged_diff)
diff = described_class.new(@rugged_diff)
 
expect(diff.diff).not_to be_empty
end
Loading
Loading
@@ -113,26 +113,29 @@ EOT
 
describe 'straight diffs' do
let(:options) { { straight: true } }
let(:diffs) { Gitlab::Git::Diff.between(repository, 'feature', 'master', options) }
subject { diffs }
let(:diffs) { described_class.between(repository, 'feature', 'master', options) }
 
describe '#size' do
subject { super().size }
it { is_expected.to eq(24) }
it 'has the correct size' do
expect(diffs.size).to eq(24)
end
 
context :diff do
subject { diffs.first }
context 'diff' do
it 'is an instance of Diff' do
expect(diffs.first).to be_kind_of(described_class)
end
it 'has the correct new_path' do
expect(diffs.first.new_path).to eq('.DS_Store')
end
 
it { is_expected.to be_kind_of Gitlab::Git::Diff }
its(:new_path) { is_expected.to == '.DS_Store' }
its(:diff) { is_expected.to include 'Binary files /dev/null and b/.DS_Store differ' }
it 'has the correct diff' do
expect(diffs.first.diff).to include('Binary files /dev/null and b/.DS_Store differ')
end
end
end
 
describe :between do
let(:diffs) { Gitlab::Git::Diff.between(repository, 'feature', 'master') }
describe '.between' do
let(:diffs) { described_class.between(repository, 'feature', 'master') }
subject { diffs }
 
it { is_expected.to be_kind_of Gitlab::Git::DiffCollection }
Loading
Loading
@@ -143,10 +146,10 @@ EOT
it { is_expected.to eq(1) }
end
 
context :diff do
context 'diff' do
subject { diffs.first }
 
it { is_expected.to be_kind_of Gitlab::Git::Diff }
it { is_expected.to be_kind_of described_class }
 
describe '#new_path' do
subject { super().new_path }
Loading
Loading
@@ -162,11 +165,11 @@ EOT
end
end
 
describe :filter_diff_options do
describe '.filter_diff_options' do
let(:options) { { max_size: 100, invalid_opt: true } }
 
context "without default options" do
let(:filtered_options) { Gitlab::Git::Diff.filter_diff_options(options) }
let(:filtered_options) { described_class.filter_diff_options(options) }
 
it "should filter invalid options" do
expect(filtered_options).not_to have_key(:invalid_opt)
Loading
Loading
@@ -176,7 +179,7 @@ EOT
context "with default options" do
let(:filtered_options) do
default_options = { max_size: 5, bad_opt: 1, ignore_whitespace: true }
Gitlab::Git::Diff.filter_diff_options(options, default_options)
described_class.filter_diff_options(options, default_options)
end
 
it "should filter invalid options" do
Loading
Loading
@@ -195,42 +198,39 @@ EOT
end
end
 
describe :submodule? do
describe '#submodule?' do
before do
commit = repository.lookup('5937ac0a7beb003549fc5fd26fc247adbce4a52e')
@diffs = commit.parents[0].diff(commit).patches
end
 
it { expect(Gitlab::Git::Diff.new(@diffs[0]).submodule?).to eq(false) }
it { expect(Gitlab::Git::Diff.new(@diffs[1]).submodule?).to eq(true) }
it { expect(described_class.new(@diffs[0]).submodule?).to eq(false) }
it { expect(described_class.new(@diffs[1]).submodule?).to eq(true) }
end
 
describe :line_count do
subject { Gitlab::Git::Diff.new(@rugged_diff) }
describe '#line_count' do
it 'returns the correct number of lines' do
diff = described_class.new(@rugged_diff)
 
describe '#line_count' do
subject { super().line_count }
it { is_expected.to eq(9) }
expect(diff.line_count).to eq(9)
end
its(:line_count) { is_expected.to eq(9) }
end
 
describe :too_large? do
describe '#too_large?' do
it 'returns true for a diff that is too large' do
diff = Gitlab::Git::Diff.new(diff: 'a' * 204800)
diff = described_class.new(diff: 'a' * 204800)
 
expect(diff.too_large?).to eq(true)
end
 
it 'returns false for a diff that is small enough' do
diff = Gitlab::Git::Diff.new(diff: 'a')
diff = described_class.new(diff: 'a')
 
expect(diff.too_large?).to eq(false)
end
 
it 'returns true for a diff that was explicitly marked as being too large' do
diff = Gitlab::Git::Diff.new(diff: 'a')
diff = described_class.new(diff: 'a')
 
diff.prune_large_diff!
 
Loading
Loading
@@ -238,45 +238,45 @@ EOT
end
end
 
describe :collapsed? do
describe '#collapsed?' do
it 'returns false by default even on quite big diff' do
diff = Gitlab::Git::Diff.new(diff: 'a' * 20480)
diff = described_class.new(diff: 'a' * 20480)
 
expect(diff.collapsed?).to eq(false)
expect(diff).not_to be_collapsed
end
 
it 'returns false by default for a diff that is small enough' do
diff = Gitlab::Git::Diff.new(diff: 'a')
diff = described_class.new(diff: 'a')
 
expect(diff.collapsed?).to eq(false)
expect(diff).not_to be_collapsed
end
 
it 'returns true for a diff that was explicitly marked as being collapsed' do
diff = Gitlab::Git::Diff.new(diff: 'a')
diff = described_class.new(diff: 'a')
 
diff.prune_collapsed_diff!
 
expect(diff.collapsed?).to eq(true)
expect(diff).to be_collapsed
end
end
 
describe :collapsible? do
describe '#collapsible?' do
it 'returns true for a diff that is quite large' do
diff = Gitlab::Git::Diff.new(diff: 'a' * 20480)
diff = described_class.new(diff: 'a' * 20480)
 
expect(diff.collapsible?).to eq(true)
expect(diff).to be_collapsible
end
 
it 'returns false for a diff that is small enough' do
diff = Gitlab::Git::Diff.new(diff: 'a')
diff = described_class.new(diff: 'a')
 
expect(diff.collapsible?).to eq(false)
expect(diff).not_to be_collapsible
end
end
 
describe :prune_collapsed_diff! do
describe '#prune_collapsed_diff!' do
it 'prunes the diff' do
diff = Gitlab::Git::Diff.new(diff: "foo\nbar")
diff = described_class.new(diff: "foo\nbar")
 
diff.prune_collapsed_diff!
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment