|
3 | 3 | describe Fastlane::Actions::IosGetAppVersionAction do
|
4 | 4 | describe 'getting the public app version from the provided .xcconfig file' do
|
5 | 5 | it 'parses the xcconfig file format correctly and gets the public version' do
|
| 6 | + xcconfig_mock_content = <<~CONTENT |
| 7 | + // a comment |
| 8 | + VERSION_SHORT = 6 |
| 9 | + VERSION_LONG = 6.30.0 |
| 10 | + CONTENT |
| 11 | + |
| 12 | + expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: '6.30') |
| 13 | + end |
| 14 | + |
| 15 | + it 'parses the xcconfig file format correctly and gets the public hotfix version' do |
| 16 | + xcconfig_mock_content = <<~CONTENT |
| 17 | + VERSION_SHORT = 6 |
| 18 | + // a comment |
| 19 | + VERSION_LONG = 6.30.1 |
| 20 | + CONTENT |
| 21 | + |
| 22 | + expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: '6.30.1') |
| 23 | + end |
| 24 | + |
| 25 | + it 'parses the xcconfig with keys without spacing and gets the public version' do |
6 | 26 | xcconfig_mock_content = <<~CONTENT
|
7 | 27 | // a comment
|
8 | 28 | VERSION_SHORT=6
|
9 | 29 | VERSION_LONG=6.30.0
|
10 | 30 | CONTENT
|
11 | 31 |
|
12 |
| - allow(File).to receive(:exist?).and_return(true) |
13 |
| - |
14 | 32 | expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: '6.30')
|
15 | 33 | end
|
16 | 34 |
|
17 |
| - it 'parses the xcconfig file format correctly and gets the public hotfix version' do |
| 35 | + it 'parses the xcconfig with keys without spacing and gets the public hotfix version' do |
18 | 36 | xcconfig_mock_content = <<~CONTENT
|
19 | 37 | VERSION_SHORT=6
|
20 | 38 | // a comment
|
21 | 39 | VERSION_LONG=6.30.1
|
22 | 40 | CONTENT
|
23 | 41 |
|
24 |
| - allow(File).to receive(:exist?).and_return(true) |
25 |
| - |
26 | 42 | expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: '6.30.1')
|
27 | 43 | end
|
28 | 44 |
|
29 |
| - def expect_version(xcconfig_mock_content:, expected_version:) |
30 |
| - xcconfig_mock_file_path = File.join('mock', 'file', 'path') |
| 45 | + it 'fails to extract the version from an xcconfig file with an invalid format' do |
| 46 | + xcconfig_mock_content = <<~CONTENT |
| 47 | + VERSION_SHORT = 6 |
| 48 | + VERSION_LONG 6.30.1 |
| 49 | + CONTENT |
| 50 | + |
| 51 | + expect do |
| 52 | + expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: 'n/a') |
| 53 | + end.to raise_error(FastlaneCore::Interface::FastlaneError) |
| 54 | + end |
| 55 | + |
| 56 | + it 'throws an error when the file is not found' do |
| 57 | + file_path = 'file/not/found' |
31 | 58 |
|
32 |
| - allow(File).to receive(:open).with(xcconfig_mock_file_path, 'r').and_yield(StringIO.new(xcconfig_mock_content)) |
| 59 | + expect do |
| 60 | + run_described_fastlane_action( |
| 61 | + public_version_xcconfig_file: file_path |
| 62 | + ) |
| 63 | + end.to raise_error(FastlaneCore::Interface::FastlaneError) |
| 64 | + end |
| 65 | + |
| 66 | + it "throws an error when there isn't a version configured in the .xcconfig file" do |
| 67 | + xcconfig_mock_content = <<~CONTENT |
| 68 | + VERSION_SHORT = 6 |
| 69 | + // a comment |
| 70 | + CONTENT |
| 71 | + |
| 72 | + expect do |
| 73 | + expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: 'n/a') |
| 74 | + end.to raise_error(FastlaneCore::Interface::FastlaneError) |
| 75 | + end |
33 | 76 |
|
34 |
| - version_result = run_described_fastlane_action( |
35 |
| - public_version_xcconfig_file: xcconfig_mock_file_path |
36 |
| - ) |
| 77 | + def expect_version(xcconfig_mock_content:, expected_version:) |
| 78 | + with_tmp_file(named: 'mock_xcconfig.xcconfig', content: xcconfig_mock_content) do |tmp_file_path| |
| 79 | + version_result = run_described_fastlane_action( |
| 80 | + public_version_xcconfig_file: tmp_file_path |
| 81 | + ) |
37 | 82 |
|
38 |
| - expect(version_result).to eq(expected_version) |
| 83 | + expect(version_result).to eq(expected_version) |
| 84 | + end |
39 | 85 | end
|
40 | 86 | end
|
41 | 87 | end
|
0 commit comments