diff options
author | Douwe Maan <douwe@gitlab.com> | 2019-03-07 14:33:15 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2019-03-07 14:33:15 +0300 |
commit | 6cfa5ee536c30522241bcf09e805d7eb3adbf481 (patch) | |
tree | 89301502c5cc76bb11cba0ae29cc6df46c97277a /spec | |
parent | c45bb62c0ae36018891a343c7c820fc1a901e33e (diff) | |
parent | cea59dbe030bfde83247ef27c49ffd5267b194ea (diff) |
Merge branch 'expand-diff-to-full-file' into 'master'
Expand diff to entire file
Closes #19054
See merge request gitlab-org/gitlab-ce!24406
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/blob_controller_spec.rb | 58 | ||||
-rw-r--r-- | spec/features/merge_request/maintainer_edits_fork_spec.rb | 2 | ||||
-rw-r--r-- | spec/javascripts/diffs/components/diff_file_header_spec.js | 67 | ||||
-rw-r--r-- | spec/javascripts/diffs/mock_data/diff_discussions.js | 1 | ||||
-rw-r--r-- | spec/javascripts/diffs/store/actions_spec.js | 130 | ||||
-rw-r--r-- | spec/javascripts/diffs/store/mutations_spec.js | 62 | ||||
-rw-r--r-- | spec/javascripts/diffs/store/utils_spec.js | 45 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/file_spec.rb | 201 | ||||
-rw-r--r-- | spec/presenters/blobs/unfold_presenter_spec.rb | 159 |
9 files changed, 643 insertions, 82 deletions
diff --git a/spec/controllers/projects/blob_controller_spec.rb b/spec/controllers/projects/blob_controller_spec.rb index 38957e96798..3801fca09dc 100644 --- a/spec/controllers/projects/blob_controller_spec.rb +++ b/spec/controllers/projects/blob_controller_spec.rb @@ -144,54 +144,34 @@ describe Projects::BlobController do end context 'when rendering for merge request' do - it 'renders diff context lines Gitlab::Diff::Line array' do - do_get(since: 1, to: 5, offset: 10, from_merge_request: true) - - lines = JSON.parse(response.body) - - expect(lines.first).to have_key('type') - expect(lines.first).to have_key('rich_text') - expect(lines.first).to have_key('rich_text') + let(:presenter) { double(:presenter, diff_lines: diff_lines) } + let(:diff_lines) do + Array.new(3, Gitlab::Diff::Line.new('plain', nil, nil, nil, nil, rich_text: 'rich')) end - context 'when rendering match lines' do - it 'adds top match line when "since" is less than 1' do - do_get(since: 5, to: 10, offset: 10, from_merge_request: true) - - match_line = JSON.parse(response.body).first - - expect(match_line['type']).to eq('match') - expect(match_line['meta_data']).to have_key('old_pos') - expect(match_line['meta_data']).to have_key('new_pos') - end - - it 'does not add top match line when "since" is equal 1' do - do_get(since: 1, to: 10, offset: 10, from_merge_request: true) - - match_line = JSON.parse(response.body).first - - expect(match_line['type']).to be_nil - end + before do + allow(Blobs::UnfoldPresenter).to receive(:new).and_return(presenter) + end - it 'adds bottom match line when "t"o is less than blob size' do - do_get(since: 1, to: 5, offset: 10, from_merge_request: true, bottom: true) + it 'renders diff context lines Gitlab::Diff::Line array' do + do_get(since: 1, to: 2, offset: 0, from_merge_request: true) - match_line = JSON.parse(response.body).last + lines = JSON.parse(response.body) - expect(match_line['type']).to eq('match') - expect(match_line['meta_data']).to have_key('old_pos') - expect(match_line['meta_data']).to have_key('new_pos') + expect(lines.size).to eq(diff_lines.size) + lines.each do |line| + expect(line).to have_key('type') + expect(line['text']).to eq('plain') + expect(line['rich_text']).to eq('rich') end + end - it 'does not add bottom match line when "to" is less than blob size' do - commit_id = project.repository.commit('master').id - blob = project.repository.blob_at(commit_id, 'CHANGELOG') - do_get(since: 1, to: blob.lines.count, offset: 10, from_merge_request: true, bottom: true) + it 'handles full being true' do + do_get(full: true, from_merge_request: true) - match_line = JSON.parse(response.body).last + lines = JSON.parse(response.body) - expect(match_line['type']).to be_nil - end + expect(lines.size).to eq(diff_lines.size) end end end diff --git a/spec/features/merge_request/maintainer_edits_fork_spec.rb b/spec/features/merge_request/maintainer_edits_fork_spec.rb index aead98dae23..b35f985126c 100644 --- a/spec/features/merge_request/maintainer_edits_fork_spec.rb +++ b/spec/features/merge_request/maintainer_edits_fork_spec.rb @@ -26,7 +26,7 @@ describe 'a maintainer edits files on a source-branch of an MR from a fork', :js visit project_merge_request_path(target_project, merge_request) click_link 'Changes' wait_for_requests - first('.js-file-title').click_link 'Edit' + first('.js-file-title').find('.js-edit-blob').click wait_for_requests end diff --git a/spec/javascripts/diffs/components/diff_file_header_spec.js b/spec/javascripts/diffs/components/diff_file_header_spec.js index 1201f066d2f..66c5b17b825 100644 --- a/spec/javascripts/diffs/components/diff_file_header_spec.js +++ b/spec/javascripts/diffs/components/diff_file_header_spec.js @@ -23,6 +23,9 @@ describe('diff_file_header', () => { }); beforeEach(() => { + gon.features = { + expandDiffFullFile: true, + }; const diffFile = diffDiscussionMock.diff_file; diffFile.added_lines = 2; @@ -382,7 +385,7 @@ describe('diff_file_header', () => { props.diffFile.edit_path = '/'; vm = mountComponentWithStore(Component, { props, store }); - expect(vm.$el.querySelector('.js-edit-blob')).toContainText('Edit'); + expect(vm.$el.querySelector('.js-edit-blob')).not.toBe(null); }); it('should not show edit button when file is deleted', () => { @@ -576,4 +579,66 @@ describe('diff_file_header', () => { }); }); }); + + describe('expand full file button', () => { + beforeEach(() => { + props.addMergeRequestButtons = true; + props.diffFile.edit_path = '/'; + }); + + it('does not render button', () => { + vm = mountComponentWithStore(Component, { props, store }); + + expect(vm.$el.querySelector('.js-expand-file')).toBe(null); + }); + + it('renders button', () => { + props.diffFile.is_fully_expanded = false; + + vm = mountComponentWithStore(Component, { props, store }); + + expect(vm.$el.querySelector('.js-expand-file')).not.toBe(null); + }); + + it('shows fully expanded text', () => { + props.diffFile.is_fully_expanded = false; + props.diffFile.isShowingFullFile = true; + + vm = mountComponentWithStore(Component, { props, store }); + + expect(vm.$el.querySelector('.js-expand-file').textContent).toContain('Show changes only'); + }); + + it('shows expand text', () => { + props.diffFile.is_fully_expanded = false; + + vm = mountComponentWithStore(Component, { props, store }); + + expect(vm.$el.querySelector('.js-expand-file').textContent).toContain('Show full file'); + }); + + it('renders loading icon', () => { + props.diffFile.is_fully_expanded = false; + props.diffFile.isLoadingFullFile = true; + + vm = mountComponentWithStore(Component, { props, store }); + + expect(vm.$el.querySelector('.js-expand-file .loading-container')).not.toBe(null); + }); + + it('calls toggleFullDiff on click', () => { + props.diffFile.is_fully_expanded = false; + + vm = mountComponentWithStore(Component, { props, store }); + + spyOn(vm.$store, 'dispatch').and.stub(); + + vm.$el.querySelector('.js-expand-file').click(); + + expect(vm.$store.dispatch).toHaveBeenCalledWith( + 'diffs/toggleFullDiff', + props.diffFile.file_path, + ); + }); + }); }); diff --git a/spec/javascripts/diffs/mock_data/diff_discussions.js b/spec/javascripts/diffs/mock_data/diff_discussions.js index 4a091b4580b..fd5dd611383 100644 --- a/spec/javascripts/diffs/mock_data/diff_discussions.js +++ b/spec/javascripts/diffs/mock_data/diff_discussions.js @@ -288,6 +288,7 @@ export default { external_storage: null, old_path_html: 'CHANGELOG_OLD', new_path_html: 'CHANGELOG', + is_fully_expanded: true, context_lines_path: '/gitlab-org/gitlab-test/blob/c48ee0d1bf3b30453f5b32250ce03134beaa6d13/CHANGELOG/diff', highlighted_diff_lines: [ diff --git a/spec/javascripts/diffs/store/actions_spec.js b/spec/javascripts/diffs/store/actions_spec.js index e47c7906fcb..070bfb2ccd0 100644 --- a/spec/javascripts/diffs/store/actions_spec.js +++ b/spec/javascripts/diffs/store/actions_spec.js @@ -30,6 +30,11 @@ import actions, { setRenderTreeList, setShowWhitespace, setRenderIt, + requestFullDiff, + receiveFullDiffSucess, + receiveFullDiffError, + fetchFullDiff, + toggleFullDiff, } from '~/diffs/store/actions'; import eventHub from '~/notes/event_hub'; import * as types from '~/diffs/store/mutation_types'; @@ -847,4 +852,129 @@ describe('DiffsStoreActions', () => { testAction(setRenderIt, 'file', {}, [{ type: types.RENDER_FILE, payload: 'file' }], [], done); }); }); + + describe('requestFullDiff', () => { + it('commits REQUEST_FULL_DIFF', done => { + testAction( + requestFullDiff, + 'file', + {}, + [{ type: types.REQUEST_FULL_DIFF, payload: 'file' }], + [], + done, + ); + }); + }); + + describe('receiveFullDiffSucess', () => { + it('commits REQUEST_FULL_DIFF', done => { + testAction( + receiveFullDiffSucess, + { filePath: 'test', data: 'test' }, + {}, + [{ type: types.RECEIVE_FULL_DIFF_SUCCESS, payload: { filePath: 'test', data: 'test' } }], + [], + done, + ); + }); + }); + + describe('receiveFullDiffError', () => { + it('commits REQUEST_FULL_DIFF', done => { + testAction( + receiveFullDiffError, + 'file', + {}, + [{ type: types.RECEIVE_FULL_DIFF_ERROR, payload: 'file' }], + [], + done, + ); + }); + }); + + describe('fetchFullDiff', () => { + let mock; + let scrollToElementSpy; + + beforeEach(() => { + scrollToElementSpy = spyOnDependency(actions, 'scrollToElement').and.stub(); + + mock = new MockAdapter(axios); + }); + + afterEach(() => { + mock.restore(); + }); + + describe('success', () => { + beforeEach(() => { + mock.onGet(`${gl.TEST_HOST}/context`).replyOnce(200, ['test']); + }); + + it('dispatches receiveFullDiffSucess', done => { + testAction( + fetchFullDiff, + { context_lines_path: `${gl.TEST_HOST}/context`, file_path: 'test', file_hash: 'test' }, + null, + [], + [{ type: 'receiveFullDiffSucess', payload: { filePath: 'test', data: ['test'] } }], + done, + ); + }); + + it('scrolls to element', done => { + fetchFullDiff( + { dispatch() {} }, + { context_lines_path: `${gl.TEST_HOST}/context`, file_path: 'test', file_hash: 'test' }, + ) + .then(() => { + expect(scrollToElementSpy).toHaveBeenCalledWith('#test'); + + done(); + }) + .catch(done.fail); + }); + }); + + describe('error', () => { + beforeEach(() => { + mock.onGet(`${gl.TEST_HOST}/context`).replyOnce(500); + }); + + it('dispatches receiveFullDiffError', done => { + testAction( + fetchFullDiff, + { context_lines_path: `${gl.TEST_HOST}/context`, file_path: 'test', file_hash: 'test' }, + null, + [], + [{ type: 'receiveFullDiffError', payload: 'test' }], + done, + ); + }); + }); + }); + + describe('toggleFullDiff', () => { + let state; + + beforeEach(() => { + state = { + diffFiles: [{ file_path: 'test', isShowingFullFile: false }], + }; + }); + + it('dispatches fetchFullDiff when file is not expanded', done => { + testAction( + toggleFullDiff, + 'test', + state, + [], + [ + { type: 'requestFullDiff', payload: 'test' }, + { type: 'fetchFullDiff', payload: state.diffFiles[0] }, + ], + done, + ); + }); + }); }); diff --git a/spec/javascripts/diffs/store/mutations_spec.js b/spec/javascripts/diffs/store/mutations_spec.js index 09ee691b602..270e7d75666 100644 --- a/spec/javascripts/diffs/store/mutations_spec.js +++ b/spec/javascripts/diffs/store/mutations_spec.js @@ -680,4 +680,66 @@ describe('DiffsStoreMutations', () => { expect(state.showWhitespace).toBe(false); }); }); + + describe('REQUEST_FULL_DIFF', () => { + it('sets isLoadingFullFile to true', () => { + const state = { + diffFiles: [{ file_path: 'test', isLoadingFullFile: false }], + }; + + mutations[types.REQUEST_FULL_DIFF](state, 'test'); + + expect(state.diffFiles[0].isLoadingFullFile).toBe(true); + }); + }); + + describe('RECEIVE_FULL_DIFF_ERROR', () => { + it('sets isLoadingFullFile to false', () => { + const state = { + diffFiles: [{ file_path: 'test', isLoadingFullFile: true }], + }; + + mutations[types.RECEIVE_FULL_DIFF_ERROR](state, 'test'); + + expect(state.diffFiles[0].isLoadingFullFile).toBe(false); + }); + }); + + describe('RECEIVE_FULL_DIFF_SUCCESS', () => { + it('sets isLoadingFullFile to false', () => { + const state = { + diffFiles: [ + { + file_path: 'test', + isLoadingFullFile: true, + isShowingFullFile: false, + highlighted_diff_lines: [], + parallel_diff_lines: [], + }, + ], + }; + + mutations[types.RECEIVE_FULL_DIFF_SUCCESS](state, { filePath: 'test', data: [] }); + + expect(state.diffFiles[0].isLoadingFullFile).toBe(false); + }); + + it('sets isShowingFullFile to true', () => { + const state = { + diffFiles: [ + { + file_path: 'test', + isLoadingFullFile: true, + isShowingFullFile: false, + highlighted_diff_lines: [], + parallel_diff_lines: [], + }, + ], + }; + + mutations[types.RECEIVE_FULL_DIFF_SUCCESS](state, { filePath: 'test', data: [] }); + + expect(state.diffFiles[0].isShowingFullFile).toBe(true); + }); + }); }); diff --git a/spec/javascripts/diffs/store/utils_spec.js b/spec/javascripts/diffs/store/utils_spec.js index 599ea9cd420..1f877910125 100644 --- a/spec/javascripts/diffs/store/utils_spec.js +++ b/spec/javascripts/diffs/store/utils_spec.js @@ -781,4 +781,49 @@ describe('DiffsStoreUtils', () => { ]); }); }); + + describe('convertExpandLines', () => { + it('converts expanded lines to normal lines', () => { + const diffLines = [ + { + type: 'match', + old_line: 1, + new_line: 1, + }, + { + type: '', + old_line: 2, + new_line: 2, + }, + ]; + + const lines = utils.convertExpandLines({ + diffLines, + data: [{ text: 'expanded' }], + typeKey: 'type', + oldLineKey: 'old_line', + newLineKey: 'new_line', + mapLine: ({ line, oldLine, newLine }) => ({ + ...line, + old_line: oldLine, + new_line: newLine, + }), + }); + + expect(lines).toEqual([ + { + text: 'expanded', + new_line: 1, + old_line: 1, + discussions: [], + hasForm: false, + }, + { + type: '', + old_line: 2, + new_line: 2, + }, + ]); + }); + }); }); diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb index 862590268ca..611c3e946ed 100644 --- a/spec/lib/gitlab/diff/file_spec.rb +++ b/spec/lib/gitlab/diff/file_spec.rb @@ -8,6 +8,47 @@ describe Gitlab::Diff::File do let(:diff) { commit.raw_diffs.first } let(:diff_file) { described_class.new(diff, diff_refs: commit.diff_refs, repository: project.repository) } + def create_file(file_name, content) + Files::CreateService.new( + project, + project.owner, + commit_message: 'Update', + start_branch: branch_name, + branch_name: branch_name, + file_path: file_name, + file_content: content + ).execute + + project.commit(branch_name).diffs.diff_files.first + end + + def update_file(file_name, content) + Files::UpdateService.new( + project, + project.owner, + commit_message: 'Update', + start_branch: branch_name, + branch_name: branch_name, + file_path: file_name, + file_content: content + ).execute + + project.commit(branch_name).diffs.diff_files.first + end + + def delete_file(file_name) + Files::DeleteService.new( + project, + project.owner, + commit_message: 'Update', + start_branch: branch_name, + branch_name: branch_name, + file_path: file_name + ).execute + + project.commit(branch_name).diffs.diff_files.first + end + describe '#diff_lines' do let(:diff_lines) { diff_file.diff_lines } @@ -675,47 +716,6 @@ describe Gitlab::Diff::File do end let(:branch_name) { 'master' } - def create_file(file_name, content) - Files::CreateService.new( - project, - project.owner, - commit_message: 'Update', - start_branch: branch_name, - branch_name: branch_name, - file_path: file_name, - file_content: content - ).execute - - project.commit(branch_name).diffs.diff_files.first - end - - def update_file(file_name, content) - Files::UpdateService.new( - project, - project.owner, - commit_message: 'Update', - start_branch: branch_name, - branch_name: branch_name, - file_path: file_name, - file_content: content - ).execute - - project.commit(branch_name).diffs.diff_files.first - end - - def delete_file(file_name) - Files::DeleteService.new( - project, - project.owner, - commit_message: 'Update', - start_branch: branch_name, - branch_name: branch_name, - file_path: file_name - ).execute - - project.commit(branch_name).diffs.diff_files.first - end - context 'when empty file is created' do it 'returns true' do diff_file = create_file('empty.md', '') @@ -751,4 +751,123 @@ describe Gitlab::Diff::File do end end end + + describe '#fully_expanded?' do + let(:project) do + create(:project, :custom_repo, files: {}) + end + let(:branch_name) { 'master' } + + context 'when empty file is created' do + it 'returns true' do + diff_file = create_file('empty.md', '') + + expect(diff_file.fully_expanded?).to be_truthy + end + end + + context 'when empty file is deleted' do + it 'returns true' do + create_file('empty.md', '') + diff_file = delete_file('empty.md') + + expect(diff_file.fully_expanded?).to be_truthy + end + end + + context 'when short file with last line removed' do + it 'returns true' do + create_file('with-content.md', (1..3).to_a.join("\n")) + diff_file = update_file('with-content.md', (1..2).to_a.join("\n")) + + expect(diff_file.fully_expanded?).to be_truthy + end + end + + context 'when a single line is added to empty file' do + it 'returns true' do + create_file('empty.md', '') + diff_file = update_file('empty.md', 'new content') + + expect(diff_file.fully_expanded?).to be_truthy + end + end + + context 'when single line file is changed' do + it 'returns true' do + create_file('file.md', 'foo') + diff_file = update_file('file.md', 'bar') + + expect(diff_file.fully_expanded?).to be_truthy + end + end + + context 'when long file is changed' do + before do + create_file('file.md', (1..999).to_a.join("\n")) + end + + context 'when first line is removed' do + it 'returns true' do + diff_file = update_file('file.md', (2..999).to_a.join("\n")) + + expect(diff_file.fully_expanded?).to be_falsey + end + end + + context 'when last line is removed' do + it 'returns true' do + diff_file = update_file('file.md', (1..998).to_a.join("\n")) + + expect(diff_file.fully_expanded?).to be_falsey + end + end + + context 'when first and last lines are removed' do + it 'returns false' do + diff_file = update_file('file.md', (2..998).to_a.join("\n")) + + expect(diff_file.fully_expanded?).to be_falsey + end + end + + context 'when first and last lines are changed' do + it 'returns false' do + content = (2..998).to_a + content.prepend('a') + content.append('z') + content = content.join("\n") + + diff_file = update_file('file.md', content) + + expect(diff_file.fully_expanded?).to be_falsey + end + end + + context 'when every line are changed' do + it 'returns true' do + diff_file = update_file('file.md', "hi\n" * 999) + + expect(diff_file.fully_expanded?).to be_truthy + end + end + + context 'when all contents are cleared' do + it 'returns true' do + diff_file = update_file('file.md', "") + + expect(diff_file.fully_expanded?).to be_truthy + end + end + + context 'when file is binary' do + it 'returns true' do + diff_file = update_file('file.md', (1..998).to_a.join("\n")) + allow(diff_file).to receive(:binary?).and_return(true) + + expect(diff_file.fully_expanded?).to be_truthy + end + end + end + end end diff --git a/spec/presenters/blobs/unfold_presenter_spec.rb b/spec/presenters/blobs/unfold_presenter_spec.rb new file mode 100644 index 00000000000..7ece5f623ce --- /dev/null +++ b/spec/presenters/blobs/unfold_presenter_spec.rb @@ -0,0 +1,159 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Blobs::UnfoldPresenter do + include FakeBlobHelpers + + let(:project) { create(:project, :repository) } + let(:blob) { fake_blob(path: 'foo', data: "1\n2\n3") } + let(:subject) { described_class.new(blob, params) } + + describe '#initialize' do + context 'when full is false' do + let(:params) { { full: false, since: 2, to: 3, bottom: false, offset: 1, indent: 1 } } + + it 'sets attributes' do + result = subject + + expect(result.full?).to eq(false) + expect(result.since).to eq(2) + expect(result.to).to eq(3) + expect(result.bottom).to eq(false) + expect(result.offset).to eq(1) + expect(result.indent).to eq(1) + end + end + + context 'when full is true' do + let(:params) { { full: true, since: 2, to: 3, bottom: false, offset: 1, indent: 1 } } + + it 'sets other attributes' do + result = subject + + expect(result.full?).to eq(true) + expect(result.since).to eq(1) + expect(result.to).to eq(blob.lines.size) + expect(result.bottom).to eq(false) + expect(result.offset).to eq(0) + expect(result.indent).to eq(0) + end + end + end + + describe '#diff_lines' do + let(:total_lines) { 50 } + let(:blob) { fake_blob(path: 'foo', data: (1..total_lines).to_a.join("\n")) } + + context 'when "full" is true' do + let(:params) { { full: true } } + + it 'returns all lines' do + lines = subject.diff_lines + + expect(lines.size).to eq(total_lines) + + lines.each.with_index do |line, index| + expect(line.text).to include("LC#{index + 1}") + expect(line.text).to eq(line.rich_text) + expect(line.type).to be_nil + end + end + + context 'when last line is empty' do + let(:blob) { fake_blob(path: 'foo', data: "1\n2\n") } + + it 'disregards last line' do + lines = subject.diff_lines + + expect(lines.size).to eq(2) + end + end + end + + context 'when "since" is equal to 1' do + let(:params) { { since: 1, to: 10, offset: 10 } } + + it 'does not add top match line' do + line = subject.diff_lines.first + + expect(line.type).to be_nil + end + end + + context 'when since is greater than 1' do + let(:params) { { since: 5, to: 10, offset: 10 } } + + it 'adds top match line' do + line = subject.diff_lines.first + + expect(line.type).to eq('match') + expect(line.old_pos).to eq(5) + expect(line.new_pos).to eq(5) + end + end + + context 'when "to" is less than blob size' do + let(:params) { { since: 1, to: 5, offset: 10, bottom: true } } + + it 'adds bottom match line' do + line = subject.diff_lines.last + + expect(line.type).to eq('match') + expect(line.old_pos).to eq(-5) + expect(line.new_pos).to eq(5) + end + end + + context 'when "to" is equal to blob size' do + let(:params) { { since: 1, to: total_lines, offset: 10, bottom: true } } + + it 'does not add bottom match line' do + line = subject.diff_lines.last + + expect(line.type).to be_nil + end + end + end + + describe '#lines' do + context 'when scope is specified' do + let(:params) { { since: 2, to: 3 } } + + it 'returns lines cropped by params' do + expect(subject.lines.size).to eq(2) + expect(subject.lines[0]).to include('LC2') + expect(subject.lines[1]).to include('LC3') + end + end + + context 'when full is true' do + let(:params) { { full: true } } + + it 'returns all lines' do + expect(subject.lines.size).to eq(3) + expect(subject.lines[0]).to include('LC1') + expect(subject.lines[1]).to include('LC2') + expect(subject.lines[2]).to include('LC3') + end + end + end + + describe '#match_line_text' do + context 'when bottom is true' do + let(:params) { { since: 2, to: 3, bottom: true } } + + it 'returns empty string' do + expect(subject.match_line_text).to eq('') + end + end + + context 'when bottom is false' do + let(:params) { { since: 2, to: 3, bottom: false } } + + it 'returns match line string' do + expect(subject.match_line_text).to eq("@@ -2,1+2,1 @@") + end + end + end +end |