Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
Add more tests for FastfilePeeker
Browse files Browse the repository at this point in the history
  • Loading branch information
adellibovi committed Apr 13, 2018
1 parent f60f60d commit c60ab34
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/shared/fastfile_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
61 changes: 60 additions & 1 deletion spec/shared/fastfile_peeker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

0 comments on commit c60ab34

Please sign in to comment.