From 164c6374a708754086a1bca1033c46c01503056d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D=C3=A1vila?= Date: Fri, 8 Jan 2016 19:57:51 -0500 Subject: [PATCH] Fix broken specs. #3945 --- spec/fixtures/parallel_diff_result.yml | 156 ++++++++++++------------- spec/helpers/diff_helper_spec.rb | 17 +-- 2 files changed, 86 insertions(+), 87 deletions(-) diff --git a/spec/fixtures/parallel_diff_result.yml b/spec/fixtures/parallel_diff_result.yml index 16c4bac96df..020c1817226 100644 --- a/spec/fixtures/parallel_diff_result.yml +++ b/spec/fixtures/parallel_diff_result.yml @@ -1,86 +1,86 @@ --- - - match - 6 - - '@@ -6,12 +6,18 @@ module Popen' + - "@@ -6,12 +6,18 @@ module Popen" - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6 - match - 6 - - '@@ -6,12 +6,18 @@ module Popen' + - "@@ -6,12 +6,18 @@ module Popen" - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6 - - - 6 - - | - + - |2 + - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6 - - 6 - - | - + - |2 + - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6 - - - 7 - - | - def popen(cmd, path=nil) + - |2 + def popen(cmd, path=nil) - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7 - - 7 - - | - def popen(cmd, path=nil) + - |2 + def popen(cmd, path=nil) - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7 - - - 8 - - | - unless cmd.is_a?(Array) + - |2 + unless cmd.is_a?(Array) - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_8_8 - - 8 - - | - unless cmd.is_a?(Array) + - |2 + unless cmd.is_a?(Array) - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_8_8 - - old - 9 - | - - raise "System commands must be given as an array of strings" + - raise "System commands must be given as an array of strings" - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9 - new - 9 - | - + raise RuntimeError, "System commands must be given as an array of strings" + + raise RuntimeError, "System commands must be given as an array of strings" - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9 - - - 10 - - | - end + - |2 + end - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_10 - - 10 - - | - end + - |2 + end - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_10 - - - 11 - - | - + - |2 + - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_11_11 - - 11 - - | - + - |2 + - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_11_11 - - - 12 - - | - path ||= Dir.pwd + - |2 + path ||= Dir.pwd - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_12_12 - - 12 - - | - path ||= Dir.pwd + - |2 + path ||= Dir.pwd - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_12_12 - - old - 13 - | - - vars = { "PWD" => path } + - vars = { "PWD" => path } - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_13_13 - old - @@ -89,12 +89,12 @@ - - old - 14 - | - - options = { chdir: path } + - options = { chdir: path } - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_14_13 - new - 13 - | - + + + - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_13 - - - @@ -103,7 +103,7 @@ - new - 14 - | - + vars = { + + vars = { - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14 - - - @@ -112,7 +112,7 @@ - new - 15 - | - + "PWD" => path + + "PWD" => path - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15 - - - @@ -121,7 +121,7 @@ - new - 16 - | - + } + + } - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_16 - - - @@ -130,7 +130,7 @@ - new - 17 - | - + + + - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_17 - - - @@ -139,7 +139,7 @@ - new - 18 - | - + options = { + + options = { - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_18 - - - @@ -148,7 +148,7 @@ - new - 19 - | - + chdir: path + + chdir: path - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_19 - - - @@ -157,75 +157,75 @@ - new - 20 - | - + } + + } - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_20 - - - 15 - - | - + - |2 + - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_21 - - 21 - - | - + - |2 + - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_21 - - - 16 - - | - unless File.directory?(path) + - |2 + unless File.directory?(path) - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_16_22 - - 22 - - | - unless File.directory?(path) + - |2 + unless File.directory?(path) - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_16_22 - - - 17 - - | - FileUtils.mkdir_p(path) + - |2 + FileUtils.mkdir_p(path) - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_17_23 - - 23 - - | - FileUtils.mkdir_p(path) + - |2 + FileUtils.mkdir_p(path) - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_17_23 - - match - 19 - - '@@ -19,6 +25,7 @@ module Popen' + - "@@ -19,6 +25,7 @@ module Popen" - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25 - match - 25 - - '@@ -19,6 +25,7 @@ module Popen' + - "@@ -19,6 +25,7 @@ module Popen" - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25 - - - 19 - - | - + - |2 + - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25 - - 25 - - | - + - |2 + - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25 - - - 20 - - | - @cmd_output = "" + - |2 + @cmd_output = "" - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_20_26 - - 26 - - | - @cmd_output = "" + - |2 + @cmd_output = "" - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_20_26 - - - 21 - - | - @cmd_status = 0 + - |2 + @cmd_status = 0 - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_21_27 - - 27 - - | - @cmd_status = 0 + - |2 + @cmd_status = 0 - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_21_27 - - - @@ -234,37 +234,35 @@ - new - 28 - | - + + + - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_28 - - - 22 - - | - Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr| + - |2 + Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr| - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_29 - - 29 - - | - Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr| + - |2 + Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr| - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_29 - - - 23 - - | - @cmd_output << stdout.read + - |2 + @cmd_output << stdout.read - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_23_30 - - 30 - - | - @cmd_output << stdout.read + - |2 + @cmd_output << stdout.read - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_23_30 - - - 24 - - @cmd_output << stderr.read + - |2 + @cmd_output << stderr.read - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_24_31 - - 31 - - @cmd_output << stderr.read + - |2 + @cmd_output << stderr.read - 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_24_31 diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb index 84b8f4d1679..4b10ee3d33c 100644 --- a/spec/helpers/diff_helper_spec.rb +++ b/spec/helpers/diff_helper_spec.rb @@ -4,11 +4,12 @@ describe DiffHelper do include RepoHelpers let(:project) { create(:project) } + let(:repository) { project.repository } let(:commit) { project.commit(sample_commit.id) } let(:diffs) { commit.diffs } let(:diff) { diffs.first } let(:diff_refs) { [commit.parent.id, commit.id] } - let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs, project.repository) } + let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs, repository) } describe 'diff_hard_limit_enabled?' do it 'should return true if param is provided' do @@ -45,41 +46,41 @@ describe DiffHelper do describe 'safe_diff_files' do it 'should return all files from a commit that is smaller than safe limits' do - expect(safe_diff_files(diffs).length).to eq(2) + expect(safe_diff_files(diffs, diff_refs, repository).length).to eq(2) end it 'should return only the first file if the diff line count in the 2nd file takes the total beyond safe limits' do allow(diffs[1].diff).to receive(:lines).and_return([""] * 4999) #simulate 4999 lines - expect(safe_diff_files(diffs).length).to eq(1) + expect(safe_diff_files(diffs, diff_refs, repository).length).to eq(1) end it 'should return all files from a commit that is beyond safe limit for numbers of lines if force diff is true' do allow(controller).to receive(:params) { { force_show_diff: true } } allow(diffs[1].diff).to receive(:lines).and_return([""] * 4999) #simulate 4999 lines - expect(safe_diff_files(diffs).length).to eq(2) + expect(safe_diff_files(diffs, diff_refs, repository).length).to eq(2) end it 'should return only the first file if the diff line count in the 2nd file takes the total beyond hard limits' do allow(controller).to receive(:params) { { force_show_diff: true } } allow(diffs[1].diff).to receive(:lines).and_return([""] * 49999) #simulate 49999 lines - expect(safe_diff_files(diffs).length).to eq(1) + expect(safe_diff_files(diffs, diff_refs, repository).length).to eq(1) end it 'should return only a safe number of file diffs if a commit touches more files than the safe limits' do large_diffs = diffs * 100 #simulate 200 diffs - expect(safe_diff_files(large_diffs).length).to eq(100) + expect(safe_diff_files(large_diffs, diff_refs, repository).length).to eq(100) end it 'should return all file diffs if a commit touches more files than the safe limits but force diff is true' do allow(controller).to receive(:params) { { force_show_diff: true } } large_diffs = diffs * 100 #simulate 200 diffs - expect(safe_diff_files(large_diffs).length).to eq(200) + expect(safe_diff_files(large_diffs, diff_refs, repository).length).to eq(200) end it 'should return a limited file diffs if a commit touches more files than the hard limits and force diff is true' do allow(controller).to receive(:params) { { force_show_diff: true } } very_large_diffs = diffs * 1000 #simulate 2000 diffs - expect(safe_diff_files(very_large_diffs).length).to eq(1000) + expect(safe_diff_files(very_large_diffs, diff_refs, repository).length).to eq(1000) end end