Skip to content

Commit a12af1e

Browse files
committed
Spec: move helper function into spec scope
It's better practice to declare helper methods that are dedicated to a specific `describe` or `context` scope inside said scope, instead of declaring the helper functions at the global namespace, otherwise that helper could accidentally shadow another helper of the same name for another spec doing the same.
1 parent 05fb0c6 commit a12af1e

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

spec/ios_lint_localizations_spec.rb

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,34 @@
5454
end
5555

5656
context 'Linter' do
57+
def run_l10n_linter_test(data_file)
58+
# Arrange: Prepare test files
59+
test_file = File.join(File.dirname(__FILE__), 'test-data', 'translations', "test-lint-ios-#{data_file}.yaml")
60+
yml = YAML.load_file(test_file)
61+
62+
files = yml['test_data']
63+
FileUtils.mkdir_p(@test_data_dir)
64+
files.each do |lang, content|
65+
lproj = File.join(@test_data_dir, "#{lang}.lproj")
66+
FileUtils.mkdir_p(lproj)
67+
File.write(File.join(lproj, 'Localizable.strings'), content) unless content.nil?
68+
end
69+
70+
# Act
71+
# Note: We will install SwiftGen in vendor/swiftgen if it's not already installed yet, and intentionally won't
72+
# remove this after the test ends, so that further executions of the test run faster.
73+
# Only the first execution of the tests might take longer if it needs to install SwiftGen first to be able to run the tests.
74+
install_dir = "vendor/swiftgen/#{Fastlane::Helper::Ios::L10nLinterHelper::SWIFTGEN_VERSION}"
75+
result = run_described_fastlane_action(
76+
install_path: install_dir,
77+
input_dir: @test_data_dir,
78+
base_lang: 'en'
79+
)
80+
81+
# Assert
82+
expect(result).to eq(yml['result'])
83+
end
84+
5785
before(:each) do
5886
@test_data_dir = Dir.mktmpdir('a8c-lint-l10n-tests-data-')
5987
allow(FastlaneCore::UI).to receive(:abort_with_message!)
@@ -84,31 +112,3 @@
84112
end
85113
end
86114
end
87-
88-
def run_l10n_linter_test(data_file)
89-
# Arrange: Prepare test files
90-
test_file = File.join(File.dirname(__FILE__), 'test-data', 'translations', "test-lint-ios-#{data_file}.yaml")
91-
yml = YAML.load_file(test_file)
92-
93-
files = yml['test_data']
94-
FileUtils.mkdir_p(@test_data_dir)
95-
files.each do |lang, content|
96-
lproj = File.join(@test_data_dir, "#{lang}.lproj")
97-
FileUtils.mkdir_p(lproj)
98-
File.write(File.join(lproj, 'Localizable.strings'), content) unless content.nil?
99-
end
100-
101-
# Act
102-
# Note: We will install SwiftGen in vendor/swiftgen if it's not already installed yet, and intentionally won't
103-
# remove this after the test ends, so that further executions of the test run faster.
104-
# Only the first execution of the tests might take longer if it needs to install SwiftGen first to be able to run the tests.
105-
install_dir = "vendor/swiftgen/#{Fastlane::Helper::Ios::L10nLinterHelper::SWIFTGEN_VERSION}"
106-
result = run_described_fastlane_action(
107-
install_path: install_dir,
108-
input_dir: @test_data_dir,
109-
base_lang: 'en'
110-
)
111-
112-
# Assert
113-
expect(result).to eq(yml['result'])
114-
end

0 commit comments

Comments
 (0)