@@ -200,6 +200,58 @@ def test_new_lazy_load_test_helpers_env
200200 assert_equal [ "test/test_helper.rb" , "test/support/helper.rb" ] , config . lazy_load_test_helper_paths
201201 end
202202
203+ def test_flaky_without_normalizer
204+ config = Configuration . new ( flaky_tests : [ "ATest#test_foo" , "BTest#test_bar" ] )
205+
206+ test = Struct . new ( :id ) . new ( "ATest#test_foo" )
207+ assert config . flaky? ( test )
208+
209+ test = Struct . new ( :id ) . new ( "CTest#test_baz" )
210+ refute config . flaky? ( test )
211+ end
212+
213+ def test_flaky_with_normalizer
214+ config = Configuration . new ( flaky_tests : [ "./test/my_test.rb:ATest#test_foo" , "./test/my_test.rb:BTest#test_bar" ] )
215+ config . test_id_normalizer = Module . new {
216+ define_method ( :normalize ) { |id | id . sub ( %r{^\. /} , "" ) }
217+ } . instance_method ( :normalize )
218+
219+ test = Struct . new ( :id ) . new ( "test/my_test.rb:ATest#test_foo" )
220+ assert config . flaky? ( test )
221+
222+ test = Struct . new ( :id ) . new ( "test/my_test.rb:CTest#test_baz" )
223+ refute config . flaky? ( test )
224+ end
225+
226+ def test_flaky_with_method_normalizer
227+ config = Configuration . new ( flaky_tests : [ "./test/my_test.rb:ATest#test_foo" , "./test/my_test.rb:BTest#test_bar" ] )
228+ normalizer_mod = Module . new do
229+ def self . normalize ( id )
230+ id . sub ( %r{^\. /} , "" )
231+ end
232+ end
233+ config . test_id_normalizer = normalizer_mod . method ( :normalize )
234+
235+ test = Struct . new ( :id ) . new ( "test/my_test.rb:ATest#test_foo" )
236+ assert config . flaky? ( test )
237+
238+ test = Struct . new ( :id ) . new ( "test/my_test.rb:CTest#test_baz" )
239+ refute config . flaky? ( test )
240+ end
241+
242+ def test_flaky_normalizer_applied_to_both_sides
243+ config = Configuration . new ( flaky_tests : [ " ATest#test_foo " , "BTest#test_bar" ] )
244+ config . test_id_normalizer = Module . new {
245+ define_method ( :normalize ) { |id | id . strip }
246+ } . instance_method ( :normalize )
247+
248+ test = Struct . new ( :id ) . new ( "ATest#test_foo" )
249+ assert config . flaky? ( test )
250+
251+ test = Struct . new ( :id ) . new ( " ATest#test_foo " )
252+ assert config . flaky? ( test )
253+ end
254+
203255 def test_heartbeat_max_test_duration_defaults
204256 # defaults to timeout*10 when heartbeat is enabled
205257 config = Configuration . new ( timeout : 5 , max_missed_heartbeat_seconds : 1 )
0 commit comments