Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky spec on TestFakerFile#test_file_name #2867

Closed
thdaraujo opened this issue Dec 12, 2023 · 6 comments · Fixed by #2868
Closed

Fix flaky spec on TestFakerFile#test_file_name #2867

thdaraujo opened this issue Dec 12, 2023 · 6 comments · Fixed by #2868

Comments

@thdaraujo
Copy link
Contributor

Describe the bug

There is a flaky spec on

===============================================================================
Failure: test_file_name(TestFakerFile):
  </^([a-z\-_.]+)(\\|\/)([a-z\-_]+)\.([a-z]+)$/> was expected to be =~
  <"whole-bless/cupiditate.mp3">.
/home/runner/work/faker/faker/test/faker/default/test_faker_file.rb:25:in `test_file_name'
     22:   end
     23: 
     24:   def test_file_name
  => 25:     assert_match %r{^([a-z\-_.]+)(\\|/)([a-z\-_]+)\.([a-z]+)$}, @tester
     26:       .file_name
     27:   end
     28: 
===============================================================================

Failed run

Maybe caused by the latest Rubocop version bump?
#2864

@thdaraujo thdaraujo changed the title Flaky spec Fix flaky spec on TestFakerFile#test_file_name Dec 12, 2023
@keshavbiswa
Copy link
Contributor

I'd like to give this a shot 🤚

@thdaraujo
Copy link
Contributor Author

thdaraujo commented Dec 12, 2023

sounds good, thank you @keshavbiswa !

@keshavbiswa
Copy link
Contributor

This seems like an issue with regexp_parser version bump.

It for some reason matches everystring but "whole-bless/cupiditate.mp3".

matcher = %r{^([a-z\-_.]+)(\\|/)([a-z\-_]+)\.([a-z]+)$}
matcher = Regexp.new Regexp.escape matcher if String === matcher

obj= "cutting-minister/qui.numbers"
matcher =~ obj

Regexp.last_match # => #<MatchData "cutting-minister/qui.numbers" 1:"cutting-minister" 2:"/" 3:"qui" 4:"numbers">

obj = "appointment-notebook/occaecati.bmp"
matcher =~ obj
Regexp.last_match # => #<MatchData "appointment-notebook/occaecati.bmp" 1:"appointment-notebook" 2:"/" 3:"occaecati" 4:"bmp">

# For some reason this doesn't work
obj = "whole-bless/cupiditate.mp3"
matcher =~ obj
Regexp.last_match # => Returns nil

I'm not a Regex expert, could someone help me understand what is the problem here?

@keshavbiswa
Copy link
Contributor

I think I got it, it's not matching the number (.mp3) as the extension. So updating the last part in the regex to assert for alphanumeric should do the job.

@keshavbiswa
Copy link
Contributor

Screenshot 2023-12-13 at 2 01 18 PM
This works!

@thdaraujo
Copy link
Contributor Author

yep, you got it! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants