Skip to content
This repository was archived by the owner on Jun 19, 2026. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: Prepared sample xcode projects and use them in specs
  • Loading branch information
jmatsu committed Jan 19, 2024
commit c7475b50f4b3dd93235ca7a20ff6dcc49400d092
1 change: 1 addition & 0 deletions deploygate.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ POST_INSTALL_MESSAGE
spec.add_development_dependency 'rspec', '~> 3.5'
spec.add_development_dependency 'webmock', '~> 2.3'
spec.add_development_dependency 'i18n-tasks', '~> 0.9'
spec.add_development_dependency 'debug', '>= 1.0.0'

spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
Expand Down
19 changes: 5 additions & 14 deletions lib/deploygate/xcode/analyze.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ def initialize(
# scheme, project/workspace, configuration, export_team_id would be resolved
Gym.config = options

options[:export_team_id] = Gym.project.build_settings[DEVELOPMENT_TEAM_KEY]
options[:codesigning_identity] = Gym.project.build_settings[CODE_SIGN_IDENTITY_KEY] if Gym.project.build_settings[CODE_SIGN_STYLE_KEY] == PROVISIONING_STYLE_MANUAL
options[:export_team_id] = Gym.project.build_settings(key: DEVELOPMENT_TEAM_KEY, optional: false)
options[:codesigning_identity] = Gym.project.build_settings(key: CODE_SIGN_IDENTITY_KEY, optional: false) if Gym.project.build_settings(key: CODE_SIGN_STYLE_KEY) == PROVISIONING_STYLE_MANUAL

# TODO: Need to support UDID additions for watchOS and App Extension

if (profiles = Gym.config.dig(:export_options, :provisioningProfiles)).present?
if (profiles = Gym.config.values.dig(:export_options, :provisioningProfiles)).present?
target_provisioning_profile = ::DeployGate::Xcode::Export.provisioning_profile(
bundle_identifier,
uuid = nil,
Expand All @@ -81,16 +81,7 @@ def xcodeproj_path
available_schemes = fastlane_project.workspace.schemes.reject { |_, v| v.include?("Pods/Pods.xcodeproj") }
available_schemes[self.scheme]
else
fastlane_project.path
end
end

# @return [String, nil] nil if it's a workspace
def workspace_path
if fastlane_project.workspace?
fastlane_project.options[:workspace]
else
nil
fastlane_project.project.path&.to_s
end
end

Expand All @@ -107,7 +98,7 @@ def export_method
end

def bundle_identifier
Gym.project.build_settings[PRODUCT_BUNDLE_IDENTIFIER_KEY]
Gym.project.build_settings(key: PRODUCT_BUNDLE_IDENTIFIER_KEY, optional: false)
end

# @return [Hash, FastlaneCore::Configuration]
Expand Down
108 changes: 62 additions & 46 deletions spec/deploygate/xcode/analyze_spec.rb
Original file line number Diff line number Diff line change
@@ -1,67 +1,83 @@
require 'spec_helper'

describe DeployGate::Xcode::Analyze do
describe '#new' do
subject { described_class.new(workspaces, build_configuration, target_scheme, xcodeproj) }
subject(:analyze) do
described_class.new(
xcodeproj_path: xcodeproj_path,
workspace_path: workspace_path,
build_configuration: build_configuration,
target_scheme: target_scheme
)
end

let(:xcodeproj_path) { nil }
let(:workspace_path) { nil }
let(:build_configuration) { nil }
let(:target_scheme) { nil }
let(:xcodeproj) { nil }

describe 'detect scheme workspace and build workspace' do
before do
allow(FastlaneCore::Configuration).to receive(:create)
project = instance_double(FastlaneCore::Project)
allow(project).to receive(:select_scheme)
allow(project).to receive(:schemes).and_return([])
allow(project).to receive(:options).and_return({})
allow(FastlaneCore::Project).to receive(:new).and_return(project)
allow(Gym).to receive(:config=)
end
describe '#initialize' do
context 'if the project is the single xcodeproject' do
let(:expected_xcodeproj_path) { test_file_path("xcodeProjects", "Projects", "SingleProject", "SingleProject.xcodeproj") }

context 'exists single xcodeproj files' do
let(:workspaces) do
%w[
/base_dir/Test/Test/Test.xcodeproj/project.xcworkspace
]
around(:each) do |example|
Dir.chdir(test_file_path("xcodeProjects", "Projects", "SingleProject")) do
example.run
end
end

context 'without scheme workspace arg' do
it 'build_workspace and xcodeproj is same' do
is_expected.to have_attributes(
build_workspace: '/base_dir/Test/Test/Test.xcodeproj/project.xcworkspace',
xcodeproj: '/base_dir/Test/Test/Test.xcodeproj'
)
end
it 'can find a project and get attributes' do
analyze

expect(Gym.project.project).not_to be_nil
expect(Gym.config[:workspace]).to be_nil
expect(analyze.xcodeproj_path).to eq(expected_xcodeproj_path)
expect(analyze.scheme).to eq("SingleProject")
expect(analyze.bundle_identifier).to eq("com.deploygate.example.SingleProject")
end
end

context 'exists multiple xcodeproj files' do
let(:workspaces) do
%w[
/base_dir/Test/ALib/ALib.xcodeproj/project.xcworkspace
/base_dir/Test/Hoge/Hoge.xcodeproj/project.xcworkspace
/base_dir/Test/Test/Test.xcodeproj/project.xcworkspace
/base_dir/Test/Test.xcworkspace
/base_dir/Test/ZLib/ZLib.xcodeproj/project.xcworkspace
]
context 'if the project is the single xcworkspace' do
let(:expected_xcodeproj_path) { test_file_path("xcodeProjects", "Workspaces", "Single", "SingleWorkspace", "SingleWorkspace.xcodeproj") }

around(:each) do |example|
Dir.chdir(test_file_path("xcodeProjects", "Workspaces", "Single")) do
example.run
end
end

context 'without scheme workspace arg' do
it 'scheme workspace is last workspace has project.xcworkspace' do
is_expected.to have_attributes(
build_workspace: '/base_dir/Test/Test.xcworkspace',
xcodeproj: '/base_dir/Test/ZLib/ZLib.xcodeproj'
)
it 'can find a project and get attributes' do
analyze

expect(Gym.project.project).to be_nil
expect(Gym.project.workspace).not_to be_nil
expect(Gym.config[:workspace]).to eq("./SingleWorkspace.xcworkspace")
expect(analyze.xcodeproj_path).to eq(expected_xcodeproj_path)
expect(analyze.scheme).to eq("SingleWorkspace")
expect(analyze.bundle_identifier).to eq("com.deploygate.example.SingleWorkspace")
end
end

context 'if detection is nondeterministic' do
around(:each) do |example|
Dir.chdir(test_file_path("xcodeProjects")) do
example.run
end
end

context 'with scheme workspace arg' do
let(:xcodeproj) { './ZLib.xcodeproj' }
it 'cannot choose any project' do
expect { analyze }.to raise_error(FastlaneCore::Interface::FastlaneCrash)
end

context 'if the project is in multi-xcodeproject' do
around(:each) do |example|
Dir.chdir(test_file_path("xcodeProjects", "Projects", "Multi")) do
example.run
end
end

it 'scheme workspace is last workspace has project.xcworkspace' do
is_expected.to have_attributes(
build_workspace: '/base_dir/Test/Test.xcworkspace',
xcodeproj: './ZLib.xcodeproj'
)
it 'cannot choose any project' do
expect { analyze }.to raise_error(FastlaneCore::Interface::FastlaneCrash)
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

require "deploygate"

ENV["CI"] = "true"

RSpec.configure do |config|
config.before :each do
# config file mock
Expand All @@ -13,6 +15,6 @@
API_ENDPOINT = "https://deploygate.com/api"
SPEC_FILE_PATH = File.dirname(__FILE__)

def test_file_path
File.join(SPEC_FILE_PATH, 'test_files/DeployGateSample.apk')
def test_file_path(*paths)
File.join(SPEC_FILE_PATH, 'test_files', *paths)
end
Loading