diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-02 00:13:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-02 00:13:36 +0300 |
commit | e415571a6e766e961cd49a0ac92576c460a49e4d (patch) | |
tree | ac24a689ea599cb1ef4ff2dcea38984e8b5502c8 /spec/tooling/lib | |
parent | 68ce709bef9bc89bbb9869e24508777bbe0a1a1d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/tooling/lib')
-rw-r--r-- | spec/tooling/lib/tooling/find_changes_spec.rb | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/spec/tooling/lib/tooling/find_changes_spec.rb b/spec/tooling/lib/tooling/find_changes_spec.rb index fef29ad3f2c..85e3eadac6f 100644 --- a/spec/tooling/lib/tooling/find_changes_spec.rb +++ b/spec/tooling/lib/tooling/find_changes_spec.rb @@ -15,7 +15,8 @@ RSpec.describe Tooling::FindChanges, feature_category: :tooling do changed_files_pathname: changed_files_pathname, predictive_tests_pathname: predictive_tests_pathname, frontend_fixtures_mapping_pathname: frontend_fixtures_mapping_pathname, - from: from) + from: from, + file_filter: file_filter) end let(:changed_files_pathname) { changed_files_file.path } @@ -23,6 +24,7 @@ RSpec.describe Tooling::FindChanges, feature_category: :tooling do let(:frontend_fixtures_mapping_pathname) { frontend_fixtures_mapping_file.path } let(:from) { :api } let(:gitlab_client) { double('GitLab') } # rubocop:disable RSpec/VerifiedDoubles + let(:file_filter) { ->(_) { true } } around do |example| self.changed_files_file = Tempfile.new('changed_files_file') @@ -89,6 +91,37 @@ RSpec.describe Tooling::FindChanges, feature_category: :tooling do subject end + + context 'when used with file_filter' do + let(:file_filter) { ->(file) { file['new_path'] =~ %r{doc/.*} } } + + let(:mr_changes_array) do + [ + { + "new_path" => "scripts/test.js", + "old_path" => "scripts/test.js" + }, + { + "new_path" => "doc/index.md", + "old_path" => "doc/index.md" + } + ] + end + + before do + # rubocop:disable RSpec/VerifiedDoubles -- The class from the GitLab gem isn't public, so we cannot use verified doubles for it. + allow(gitlab_client).to receive(:merge_request_changes) + .with('dummy-project', '1234') + .and_return(double(changes: mr_changes_array)) + # rubocop:enable RSpec/VerifiedDoubles + end + + it 'only writes matching files to output' do + subject + + expect(File.read(changed_files_file)).to eq('doc/index.md') + end + end end context 'when fetching changes from changed files' do |