Skip to content

Commit 345ea83

Browse files
committed
Make ios_get_app_version_spec unit tests to work with an actual file to avoid relying on implementation details
1 parent 0d3621a commit 345ea83

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

spec/ios_get_app_version_spec.rb

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
VERSION_LONG = 6.30.0
1010
CONTENT
1111

12-
allow(File).to receive(:exist?).and_return(true)
13-
1412
expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: '6.30')
1513
end
1614

@@ -21,8 +19,6 @@
2119
VERSION_LONG = 6.30.1
2220
CONTENT
2321

24-
allow(File).to receive(:exist?).and_return(true)
25-
2622
expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: '6.30.1')
2723
end
2824

@@ -42,23 +38,21 @@
4238
// a comment
4339
CONTENT
4440

45-
allow(File).to receive(:exist?).and_return(true)
46-
4741
expect do
4842
expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: 'n/a')
4943
end.to raise_error(FastlaneCore::Interface::FastlaneError)
5044
end
5145

5246
def expect_version(xcconfig_mock_content:, expected_version:)
53-
xcconfig_mock_file_path = File.join('mock', 'file', 'path')
54-
55-
allow(File).to receive(:open).with(xcconfig_mock_file_path, 'r').and_yield(StringIO.new(xcconfig_mock_content))
47+
allow(File).to receive(:exist?).and_return(true)
5648

57-
version_result = run_described_fastlane_action(
58-
public_version_xcconfig_file: xcconfig_mock_file_path
59-
)
49+
with_tmp_file(named: 'mock_xcconfig.xcconfig', content: xcconfig_mock_content) do |tmp_file_path|
50+
version_result = run_described_fastlane_action(
51+
public_version_xcconfig_file: tmp_file_path
52+
)
6053

61-
expect(version_result).to eq(expected_version)
54+
expect(version_result).to eq(expected_version)
55+
end
6256
end
6357
end
6458
end

0 commit comments

Comments
 (0)