diff --git a/app/shared/fastfile_finder.rb b/app/shared/fastfile_finder.rb index 07ca9c72..9a60ec28 100644 --- a/app/shared/fastfile_finder.rb +++ b/app/shared/fastfile_finder.rb @@ -40,8 +40,8 @@ def self.search_path(path:, relative_path: false) def self.find_prioritary_fastfile_path(paths:, path: nil) path = path.nil? ? "" : "#{path}/" return paths - .select { |current_path| current_path.downcase.end_with?("/fastfile") || current_path.casecmp("fastfile").zero? } - .find { |current_path| current_path.downcase == "#{path}fastlane/fastfile" } || paths.first + .select { |current| current.downcase.end_with?("/fastfile") || current.casecmp("fastfile").zero? } + .find { |current| current.downcase == "#{path}fastlane/fastfile" } || paths.first end end end diff --git a/spec/shared/fastfile_peeker_spec.rb b/spec/shared/fastfile_peeker_spec.rb index 8ed3d7ca..2a0c9abd 100644 --- a/spec/shared/fastfile_peeker_spec.rb +++ b/spec/shared/fastfile_peeker_spec.rb @@ -15,7 +15,12 @@ module FastlaneCI end let(:repo_config) do - return "repo config" + return GitHubRepoConfig.new(id: nil, + git_url: nil, + description: nil, + name: "name", + full_name: "repo/user", + hidden: false) end let(:notification_service) do @@ -35,6 +40,10 @@ module FastlaneCI File.join(file_path, "fastfile_peeker", "repo_stub_1") end + let (:repo_1_fastfile_path) do + File.join(repo_1_file_path, "fastlane", "Fastfile") + end + describe "#fastfile_from_repo" do it "returns the Fastfile for a given repo" do allow_any_instance_of(FastlaneCI::GitRepo).to receive(:checkout_branch).with({ branch: "master" }).and_return(nil) @@ -54,5 +63,55 @@ module FastlaneCI ) end end + + describe "#fastfile" do + it "search Fastfile on GitHub, if found do not search Fastfile in local" do + peeker = FastlaneCI::FastfilePeeker.new(provider_credential: provider_credential, notification_service: notification_service) + allow(peeker).to receive(:fastfile_from_github).and_return(Fastlane::FastfileParser.new(path: repo_1_fastfile_path)) + allow(peeker).to receive(:fastfile_from_repo).and_return(nil) + + peeker.fastfile(repo_config: repo_config, sha_or_branch: "master") + expect(peeker).to have_received(:fastfile_from_github) + expect(peeker).not_to(have_received(:fastfile_from_repo)) + end + + it "search Fastfile on GitHub, if not found search Fastfile in local" do + peeker = FastlaneCI::FastfilePeeker.new(provider_credential: provider_credential, notification_service: notification_service) + allow(peeker).to receive(:fastfile_from_github).and_return(nil) + allow(peeker).to receive(:fastfile_from_repo).and_return(nil) + + peeker.fastfile(repo_config: repo_config, sha_or_branch: "master") + expect(peeker).to have_received(:fastfile_from_github) + expect(peeker).to have_received(:fastfile_from_repo) + end + + it "returns Fastlane/Fastfile path, if exists" do + fastfile_path = FastfileFinder.find_prioritary_fastfile_path(paths: + ["path/Fastlane/Fastfile", + "path/Fastlane/TestFastfile", + "fastfile", + "Fastlane/Fastfile"]) + + expect(fastfile_path).to eql("Fastlane/Fastfile") + end + + it "returns any Fastfile path if Fastlane/Fastfile does not exist" do + fastfile_path = FastfileFinder.find_prioritary_fastfile_path(paths: + ["path/Fastlane/Fastfile", + "path/Fastlane/TestFastfile", + "fastfile"]) + + expect(fastfile_path).not_to(be(nil)) + end + + it "returns nil if there are no Fastfile" do + fastfile_path = FastfileFinder.find_prioritary_fastfile_path(paths: + ["path/Fastlane/Fastfiles", + "path/Fastlane/TestFastfile", + "Fastlane/BackupFastlane"]) + + expect(fastfile_path).not_to(be(nil)) + end + end end end