Skip to content

Commit

Permalink
[Spec] Ensure fallback if Xcode path is unknown.
Browse files Browse the repository at this point in the history
Possible cases:
- Xcode is not installed at all
- User hasn't agreed to the license
  • Loading branch information
neonichu committed Jan 25, 2015
1 parent 1fd9cbb commit 9669942
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions spec/plist_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,25 @@ def o.to_hash
describe 'Xcode frameworks resilience' do
extend SpecHelper::TemporaryDirectory

after do
if @original_xcode_path
DevToolsCore.send(:remove_const, :XCODE_PATH)
DevToolsCore.const_set(:XCODE_PATH, @original_xcode_path)
end
end

def read_sample
dir = 'Sample Project/Cocoa Application.xcodeproj/'
path = fixture_path(dir + 'project.pbxproj')
Xcodeproj.read_plist(path)
end

def stub_xcode_path(stubbed_path)
@original_xcode_path = DevToolsCore::XCODE_PATH
DevToolsCore.send(:remove_const, :XCODE_PATH)
DevToolsCore.const_set(:XCODE_PATH, stubbed_path)
end

def write_temp_file_and_compare(sample)
temp_file = File.join(SpecHelper.temporary_directory, 'out.pbxproj')
Xcodeproj.write_plist(sample, temp_file)
Expand All @@ -175,6 +188,19 @@ def write_temp_file_and_compare(sample)
File.new(temp_file).read.start_with?('<?xml').should == true
end

it 'will fallback to XML encoding if Xcode is not installed' do
# Simulate this by calling `xcrun` with a non-existing tool
stub_xcode_path(Pathname.new(`xcrun lol 2>/dev/null`))

write_temp_file_and_compare(read_sample)
end

it 'will fallback to XML encoding if the user has not agreed to the Xcode license' do
stub_xcode_path(Pathname.new('Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.'))

write_temp_file_and_compare(read_sample)
end

it 'will fallback to XML encoding if Xcode functions cannot be found' do
DevToolsCore.stubs(:load_xcode_frameworks).returns(Fiddle::Handle.new)

Expand Down

0 comments on commit 9669942

Please sign in to comment.