Faker: fetch_all raises error

Created on 3 May 2018  路  7Comments  路  Source: faker-ruby/faker

I'm trying to determine the total number of possible entries for Faker::Name.first_name. Running the following:

bin/rails console
require 'faker'
Faker::Name.fetch_all :first_name

yields the following error:

[17] pry(main)> Faker::Name.fetch_all 'first_name'
I18n::MissingTranslationData: translation missing: en.faker.first_name
from /Users/kevin.burke/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/i18n-0.8.6/lib/i18n.rb:311:in `handle_exception'

Per https://github.com/stympy/faker/pull/811, I tried I18n.reload!, but that had no effect. I also tried hardcoding the locale to en and that did not work either.

I'm using Faker 1.7.3 and Ruby 2.4.3, on a Mac. I can provide more debugging information as necessary, but I am not sure what I am looking for.

If there is a different way to compute the total number of possibilities for a value, let me know.

BuFixes

Most helpful comment

@kevinburkeomg Give this a shot:

Faker::Base.fetch_all("name.first_name")

I don't have enough knowledge of the library to know if the syntax you posted above _should_ work (it's certainly a nice way to write things though). It failed on a few other classes I tried, so maybe it's just not supported. I would be happy to work on a PR to fix/add that behavior if that's wanted by the maintainers though.

All 7 comments

@kevinburkeomg Give this a shot:

Faker::Base.fetch_all("name.first_name")

I don't have enough knowledge of the library to know if the syntax you posted above _should_ work (it's certainly a nice way to write things though). It failed on a few other classes I tried, so maybe it's just not supported. I would be happy to work on a PR to fix/add that behavior if that's wanted by the maintainers though.

@JonathanWThom exactly. You could do:

Faker::Base.fetch_all("name.first_name") or Faker::Name.fetch_all("name.first_name").

I personally prefer to use the Base class.

It seems at the very least like the error message could be clearer.

Wanna work on this improvement? @kevinburkeomg

I don't think there's anything to work on here... we don't advertise fetch_all as a public API.

Maybe then documenting how to retrieve all of the options for a given function, besides in a comment to a closed issue

Ok, well, if a PR shows up, we'll review it. :)

I'd need to see a compelling argument, though, if a PR encouraged the use of internal functions like fetch_all for public consumption.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tagliala picture tagliala  路  5Comments

neutralino1 picture neutralino1  路  3Comments

zyrthofar picture zyrthofar  路  6Comments

kevgathuku picture kevgathuku  路  4Comments

mhutter picture mhutter  路  5Comments