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 random error in music tests #2050

Merged

Conversation

martinjaimem
Copy link
Contributor

@martinjaimem martinjaimem commented Jun 10, 2020

Resolves #2049

A test that seems to be failing randomly. The test is:
faker/test/faker/music/test_faker_rush.rb

The error is: NoMethodError: undefined method 'match' for 2112:Integer

It comes from the fetch method in the Faker::Base, when it does:

sample(translate("faker.#{key}"))

where translate("faker.#{key}") returns:

["Rush", "Fly by Night", "Caress of Steel", 2112, "A Farewell to Kings", "Hemispheres", "Permanent Waves", "Moving Pictures", "Signals", "Grace Under Pressure", "Power Windows", "Hold Your Fire", "Presto", "Roll the Bones", "Counterparts", "Test for Echo", "Vapor Trails", "Snakes & Arrows", "Clockwork Angels", "All the World's a Stage", "Exit...Stage Left", "A Show of Hands", "Different Stages"]
So when the sample is 2112, it tries to do 2112.match(%r{^/})


I solved this by changing the input of the YAML to a string. Another way of solving this could be in
the fetch method of faker make this change:

add a fetched.respond_to?(:match) check in the fetch method:

def fetch(key)
  fetched = sample(translate("faker.#{key}"))
  if fetched.respond_to?(:match) && fetched.match(%r{^\/}) && fetched.match(%r{\/$}) # A regex
    regexify(fetched)
  else
    fetched
  end
end

I am open to any suggestions or changes

@koic koic merged commit 77a39a0 into faker-ruby:master Jun 11, 2020
@koic
Copy link
Member

koic commented Jun 11, 2020

Good catch!

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

Successfully merging this pull request may close these issues.

Random test fails in faker/music
3 participants