-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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 user agent test #2530
Conversation
The previous test was matching against a fixed list of options. The problem arised when a new type of user agent was added to the locales. Because the generator randomly picks an user agent, the previous test was very flaky. The generator should return a string even if the vendor is not available or the argument is invalid. So we can simply verify that the agent is present. There's no need to validate it against a regex, because we would have to keep this regex updated whenever a new user agent is added to the locale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I agree that matching for strings here will always be prone to having those tests failing as it's easy to forget keeping them updated.
Have you considered adding the following scenario?
def test_bot_user_agent_with_no_argument
assert @tester.bot_user_agent(vendor: nil)
end
Even though is not invalid, I feel like it's a good documentation to keep here.
good idea! Added your suggestion to the list of valid argument tests. |
d771973
to
e1c1dce
Compare
e1c1dce
to
ec9136e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Issue#
Fixes #2521
Description:
Fixes some flaky tests on
test_faker_internet.rb
related to bot_user_agent generation.These previous test were matching against a fixed list of options for user agents and bot user agents.
The problem appeared when a new type of user agent was added to the locales. Because the generator randomly picks an user agent, the previous test would fail at random when the agent picked didn't match the regex.
But the generator should return a string even if the vendor is not available or the argument is invalid.
We can simply verify that the agent is present. Otherwise, we would have to keep the regex and these tests updated whenever a new user agent is added to the locale.