|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Fastlane::Actions::IosGetBuildNumberAction do |
| 4 | + describe 'getting the build number from the provided .xcconfig file' do |
| 5 | + it 'parses an xcconfig file with keys without spacing and returns the correct build number' do |
| 6 | + xcconfig_mock_content = <<~CONTENT |
| 7 | + // a comment |
| 8 | + VERSION_SHORT=6 |
| 9 | + VERSION_LONG=6.30.0 |
| 10 | + BUILD_NUMBER=1940 |
| 11 | + CONTENT |
| 12 | + |
| 13 | + expect_build_number(xcconfig_mock_content: xcconfig_mock_content, expected_build_number: '1940') |
| 14 | + end |
| 15 | + |
| 16 | + it 'parses an xcconfig file with keys with spaces and returns a nil build number' do |
| 17 | + xcconfig_mock_content = <<~CONTENT |
| 18 | + VERSION_SHORT = 6 |
| 19 | + VERSION_LONG = 6.30.1 |
| 20 | + BUILD_NUMBER = 1940 |
| 21 | + CONTENT |
| 22 | + |
| 23 | + expect_build_number(xcconfig_mock_content: xcconfig_mock_content, expected_build_number: nil) |
| 24 | + end |
| 25 | + |
| 26 | + it 'parses an xcconfig file with an invalid format and returns a nil build number' do |
| 27 | + xcconfig_mock_content = <<~CONTENT |
| 28 | + VERSION_SHORT = 6 |
| 29 | + VERSION_LONG = 6.30.1 |
| 30 | + BUILD_NUMBER 1940 |
| 31 | + CONTENT |
| 32 | + |
| 33 | + expect_build_number(xcconfig_mock_content: xcconfig_mock_content, expected_build_number: nil) |
| 34 | + end |
| 35 | + |
| 36 | + it 'parses an xcconfig file with no build number and returns a nil build number' do |
| 37 | + xcconfig_mock_content = <<~CONTENT |
| 38 | + VERSION_SHORT = 6 |
| 39 | + // a comment |
| 40 | + CONTENT |
| 41 | + |
| 42 | + expect_build_number(xcconfig_mock_content: xcconfig_mock_content, expected_build_number: nil) |
| 43 | + end |
| 44 | + |
| 45 | + it 'throws an error when the xcconfig file does not exist' do |
| 46 | + file_path = 'file/not/found' |
| 47 | + |
| 48 | + expect do |
| 49 | + run_described_fastlane_action( |
| 50 | + xcconfig_file_path: file_path |
| 51 | + ) |
| 52 | + # Ruby error for 'No such file or directory': https://ruby-doc.org/core-2.7.4/SystemCallError.html |
| 53 | + end.to raise_error(Errno::ENOENT) |
| 54 | + end |
| 55 | + |
| 56 | + def expect_build_number(xcconfig_mock_content:, expected_build_number:) |
| 57 | + with_tmp_file(named: 'mock_xcconfig.xcconfig', content: xcconfig_mock_content) do |tmp_file_path| |
| 58 | + build_number_result = run_described_fastlane_action( |
| 59 | + xcconfig_file_path: tmp_file_path |
| 60 | + ) |
| 61 | + |
| 62 | + expect(build_number_result).to eq(expected_build_number) |
| 63 | + end |
| 64 | + end |
| 65 | + end |
| 66 | +end |
0 commit comments