xcpretty / xcode-install

🔽 Install and update your Xcodes
https://fastlane.tools
MIT License
2.58k stars 237 forks source link

fix `.xcode-version` file read when it has whitespaces #423

Closed rogerluan closed 3 years ago

rogerluan commented 3 years ago

Resolves https://github.com/xcpretty/xcode-install/issues/421

This PR simply trims whitespaces around the file read.

I was misled by these docs https://github.com/fastlane/ci/blob/master/docs/xcode-version.md#file-content that xcode-install would strip whitespaces, but it actually doesn't (yet), and caused that very misleading behavior (which also happens to be extremely hard to debug or notice because visually - on Terminal - it never prints the trailing whitespaces 😬 ).

I tried adding a unit test to cover this case, but honestly I couldn't make it work. This is what I ended up with, in spec/install_spec.rb:

it 'reads .xcode-version and trim whitespaces if needed' do
  Installer.any_instance.expects(:download).with('6.3', true, nil, nil, 3).returns('/some/path')
  Installer.any_instance.expects(:install_dmg).with('/some/path', '-6.3', true, true)
  File.expects(:exist?).with('.xcode-version').returns(true)
  File.expects(:read).with('.xcode-version').returns('6.3\n')
  Command::Install.run([])
end
rogerluan commented 3 years ago

The CI failure seems to be unrelated (and present in master as well) 🤔