@@ -33,7 +33,6 @@ class CodegenUtilsTests < Test::Unit::TestCase
3333
3434 def setup
3535 CodegenUtils . set_react_codegen_discovery_done ( false )
36- CodegenUtils . set_react_codegen_podspec_generated ( false )
3736 Pod ::Config . reset ( )
3837 @base_path = "~/app/ios"
3938 Pathname . pwd! ( @base_path )
@@ -62,8 +61,8 @@ def testUseReactCodegenDiscovery_whenCodegenDisabled_doNothing
6261
6362 # Assert
6463 assert_false ( CodegenUtils . react_codegen_discovery_done ( ) )
65- assert_equal ( Pod ::UI . collected_messages , [ ] )
66- assert_equal ( Pod ::UI . collected_warns , [ ] )
64+ assert_equal ( [ ] , Pod ::UI . collected_messages )
65+ assert_equal ( [ ] , Pod ::UI . collected_warns )
6766 end
6867
6968 def testUseReactCodegenDiscovery_whenDiscoveryDone_doNothing
@@ -75,8 +74,8 @@ def testUseReactCodegenDiscovery_whenDiscoveryDone_doNothing
7574
7675 # Assert
7776 assert_true ( CodegenUtils . react_codegen_discovery_done ( ) )
78- assert_equal ( Pod :: UI . collected_messages , [ "Skipping use_react_native_codegen_discovery." ] )
79- assert_equal ( Pod ::UI . collected_warns , [ ] )
77+ assert_equal ( [ "Skipping use_react_native_codegen_discovery." ] , Pod :: UI . collected_messages )
78+ assert_equal ( [ ] , Pod ::UI . collected_warns )
8079 end
8180
8281 def testUseReactCodegenDiscovery_whenAppPathUndefined_abort
@@ -89,16 +88,16 @@ def testUseReactCodegenDiscovery_whenAppPathUndefined_abort
8988
9089 # Assert
9190 assert_false ( CodegenUtils . react_codegen_discovery_done ( ) )
92- assert_equal ( Pod ::UI . collected_messages , [ ] )
93- assert_equal ( Pod :: UI . collected_warns , [
91+ assert_equal ( [ ] , Pod ::UI . collected_messages )
92+ assert_equal ( [
9493 'Error: app_path is required for use_react_native_codegen_discovery.' ,
9594 'If you are calling use_react_native_codegen_discovery! in your Podfile, please remove the call and pass `app_path` and/or `config_file_dir` to `use_react_native!`.'
96- ] )
95+ ] , Pod :: UI . collected_warns )
9796 end
9897
99- # ============================= #
98+ # =========================== #
10099 # Test - CleanUpCodegenFolder #
101- # ============================= #
100+ # =========================== #
102101
103102 def testCleanUpCodegenFolder_whenCleanupDone_doNothing
104103 # Arrange
@@ -110,9 +109,9 @@ def testCleanUpCodegenFolder_whenCleanupDone_doNothing
110109 CodegenUtils . clean_up_build_folder ( rn_path , codegen_dir , dir_manager : DirMock , file_manager : FileMock )
111110
112111 # Assert
113- assert_equal ( FileUtils ::FileUtilsStorage . rmrf_invocation_count , 0 )
114- assert_equal ( FileUtils ::FileUtilsStorage . rmrf_paths , [ ] )
115- assert_equal ( CodegenUtils . cleanup_done ( ) , true )
112+ assert_equal ( 0 , FileUtils ::FileUtilsStorage . rmrf_invocation_count )
113+ assert_equal ( [ ] , FileUtils ::FileUtilsStorage . rmrf_paths )
114+ assert_equal ( true , CodegenUtils . cleanup_done ( ) )
116115 end
117116
118117 def testCleanUpCodegenFolder_whenFolderDoesNotExists_markAsCleanupDone
@@ -125,10 +124,10 @@ def testCleanUpCodegenFolder_whenFolderDoesNotExists_markAsCleanupDone
125124 CodegenUtils . clean_up_build_folder ( rn_path , codegen_dir , dir_manager : DirMock , file_manager : FileMock )
126125
127126 # Assert
128- assert_equal ( FileUtils ::FileUtilsStorage . rmrf_invocation_count , 0 )
129- assert_equal ( FileUtils ::FileUtilsStorage . rmrf_paths , [ ] )
130- assert_equal ( DirMock . glob_invocation , [ ] )
131- assert_equal ( CodegenUtils . cleanup_done ( ) , true )
127+ assert_equal ( 0 , FileUtils ::FileUtilsStorage . rmrf_invocation_count )
128+ assert_equal ( [ ] , FileUtils ::FileUtilsStorage . rmrf_paths )
129+ assert_equal ( [ ] , DirMock . glob_invocation )
130+ assert_equal ( true , CodegenUtils . cleanup_done ( ) )
132131 end
133132
134133 def testCleanUpCodegenFolder_whenFolderExists_deleteItAndSetCleanupDone
@@ -137,29 +136,33 @@ def testCleanUpCodegenFolder_whenFolderExists_deleteItAndSetCleanupDone
137136 codegen_dir = "build/generated/ios"
138137 codegen_path = "#{ @base_path } /#{ codegen_dir } "
139138 globs = [
140- "/MyModuleSpecs/MyModule.h" ,
141- "#{ codegen_path } /MyModuleSpecs/MyModule.mm" ,
142- "#{ codegen_path } /react/components/MyComponent/ShadowNode.h" ,
143- "#{ codegen_path } /react/components/MyComponent/ShadowNode.mm" ,
139+ codegen_path
144140 ]
145141 rn_path = '../node_modules/react-native'
146142
147143 DirMock . mocked_existing_dirs ( codegen_path )
148144 DirMock . mocked_existing_globs ( globs , "#{ codegen_path } /*" )
149145
146+ original_define_singleton_method = CodegenUtils . method ( :assert_codegen_folder_is_empty )
147+ CodegenUtils . define_singleton_method ( :assert_codegen_folder_is_empty ) do |*args , **kwargs |
148+ # no-op
149+ end
150+
150151 # Act
151152 CodegenUtils . clean_up_build_folder ( rn_path , codegen_dir , dir_manager : DirMock , file_manager : FileMock )
152153
153154 # Assert
154- assert_equal ( DirMock . exist_invocation_params , [ codegen_path , codegen_path ] )
155- assert_equal ( DirMock . glob_invocation , [ "#{ codegen_path } /*" , "#{ codegen_path } /*" ] )
156- assert_equal ( FileUtils ::FileUtilsStorage . rmrf_invocation_count , 3 )
157- assert_equal ( FileUtils ::FileUtilsStorage . rmrf_paths , [
158- globs ,
155+ assert_equal ( [ codegen_path ] , DirMock . exist_invocation_params )
156+ assert_equal ( 3 , FileUtils ::FileUtilsStorage . rmrf_invocation_count )
157+ assert_equal ( [
158+ *globs ,
159159 "#{ rn_path } /React/Fabric/RCTThirdPartyFabricComponentsProvider.h" ,
160160 "#{ rn_path } /React/Fabric/RCTThirdPartyFabricComponentsProvider.mm" ,
161- ] )
162- assert_equal ( CodegenUtils . cleanup_done ( ) , true )
161+ ] , FileUtils ::FileUtilsStorage . rmrf_paths )
162+ assert_equal ( true , CodegenUtils . cleanup_done ( ) )
163+ ensure
164+ # Restore original method so other tests are not affected
165+ CodegenUtils . define_singleton_method ( :assert_codegen_folder_is_empty , original_define_singleton_method )
163166 end
164167
165168 # ===================================== #
@@ -175,7 +178,7 @@ def test_assertCodegenFolderIsEmpty_whenItDoesNotExists_doesNotAbort
175178 CodegenUtils . assert_codegen_folder_is_empty ( codegen_path , dir_manager : DirMock )
176179
177180 # Assert
178- assert_equal ( Pod ::UI . collected_warns , [ ] )
181+ assert_equal ( [ ] , Pod ::UI . collected_warns )
179182 end
180183
181184 def test_assertCodegenFolderIsEmpty_whenItExistsAndIsEmpty_doesNotAbort
@@ -189,7 +192,7 @@ def test_assertCodegenFolderIsEmpty_whenItExistsAndIsEmpty_doesNotAbort
189192 CodegenUtils . assert_codegen_folder_is_empty ( codegen_path , dir_manager : DirMock )
190193
191194 # Assert
192- assert_equal ( Pod ::UI . collected_warns , [ ] )
195+ assert_equal ( [ ] , Pod ::UI . collected_warns )
193196 end
194197
195198 def test_assertCodegenFolderIsEmpty_whenItIsNotEmpty_itAborts
@@ -205,9 +208,9 @@ def test_assertCodegenFolderIsEmpty_whenItIsNotEmpty_itAborts
205208 }
206209
207210 # Assert
208- assert_equal ( Pod :: UI . collected_warns , [
211+ assert_equal ( [
209212 "Unable to remove the content of ~/app/ios/./build/generated/ios folder. Please run rm -rf ~/app/ios/./build/generated/ios and try again."
210- ] )
213+ ] , Pod :: UI . collected_warns )
211214 end
212215
213216 private
0 commit comments