Giter Site home page Giter Site logo

faker's Introduction

Faker

build Version Hex Docs License Issues Downloads Gitter Last Updated

Faker is a pure Elixir library for generating fake data.

Quickstart

  • add {:faker, "~> 0.18"} to your deps in mix.exs:

    defp deps do
      [
        {:faker, "~> 0.18", only: :test}
      ]
    end
  • run:

    mix deps.get
    
  • add Faker.start() to test/test_helper.exs:

    ExUnit.start()
    Faker.start()
  • jump to usage examples.

Requirements

  • OTP 19+
  • Elixir 1.6+

Usage

See documentation and usage examples.

Troubleshooting

  • If you get a message like the one below when you call Faker.Address.city/0, you need to add :faker to your application's mix file, in the applications function, as above.

    ** (FunctionClauseError) no function clause matching in Faker.Address.city_count/1
    lib/faker/address.ex:48: Faker.Address.city_count(nil)
    lib/faker/address.ex:41: Faker.Address.city/0
    

Tools

Faker was designed as a lightweight library, that's why it can be easily used with other tools.

Templating

You can build templates for testing purposes with the Blacksmith project. See the Blacksmith readme for details.

Team

Faker was originally written by Igor Kapkov.

Current list of maintainers:

Contributing

Do you want to become a maintainer?

See our CONTRIBUTING.md and start contributing today. We usually elect new maintainers based on contributions.

Thanks

Sponsored by Evil Martians

Released under the MIT License.

faker's People

Contributors

anthonator avatar bcat-eu avatar brunohkbx avatar crbelaus avatar daytonn avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar devshane avatar f-francine avatar fusillicode avatar gitter-badger avatar gmile avatar hovikman avatar igas avatar jalcine avatar johnhamelink avatar kevindasilvas avatar lowks avatar orieken avatar pmontrasio avatar renovate[bot] avatar rodrigues avatar saulecabrera avatar stfnsr avatar thomascharbonnel avatar tobyhinloopen avatar vboivin avatar vbrazo avatar whatyouhide avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

faker's Issues

Argument error in Faker.format/2

Hi! I have some strange problem with Faker.format when i run it with hashtag string:

iex> Faker.format("#")
** (ArgumentError) argument error
    (faker) lib/faker.ex:35: Faker.format/2

I think problem may be with new OTP 19 version.
I have this environment:

Erlang/OTP 19 [erts-8.1] [source-77fb4f8] [64-bit]
Elixir 1.4.0-dev (f7c699f)

Calling Faker into spawn

I'm using Faker to generate my seeds into a Phoenix project. I'm using spawn_link to improve speed, but, for any reason, Faker stops working into the new processes.

What could be happening?

function Faker.Date.date_of_birth/1 is undefined

I don't know what is happening but I can't use the all the Faker.Date methods.

iex(5)> Faker.Date.date_of_birth(10..19)
** (UndefinedFunctionError) function Faker.Date.date_of_birth/1 is undefined (module Faker.Date is not available)
    Faker.Date.date_of_birth(10..19)

does anyone have some idea why?

Semversion faker sometimes generating invalid version

** (Version.InvalidVersionError) invalid version: "9.48.05"
    (elixir) lib/version.ex:287: Version.parse!/1
    test/test_helper.exs:11: anonymous fn/2 in :elixir_compiler_37.__FILE__/1
    (elixir) lib/enum.ex:1856: Enum.reduce_range_inc/4
    test/test_helper.exs:10: (file)
    (elixir) lib/code.ex:376: Code.require_file/2

Pass all random number generation through a single function

I often want random, but deterministic fake data for seeds. This is great because the generated data is always the same on all machines that run the seeds.

If all random number generation uses a single function, library users could swap :crypto.rand_uniform with a seeded RNG.

@igas does this sound like a good idea?

No function clause matching in Faker.Internet.email_count/1

Hello, this is the error which I get with 0.5.1

** (FunctionClauseError) no function clause matching in Faker.Internet.email_count/1
    lib/faker/internet.ex:31: Faker.Internet.email_count(nil)
    lib/faker/internet.ex:24: Faker.Internet.email/0

Deprecated random module

Since Elixir 1.3 (I guess) the random module has been deprecated. Hence we get these warning when compiling Faker.

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/avatar.ex:43
...

Would it be helpful if I make PR to replace random module with rand module? Or is there any concern?

Add generate random characters

I normally use this

def get_random_string(length \\ 5) do
    :crypto.strong_rand_bytes(length)
    |> Base.encode64
  end

Is there any way to do this right now?
If no, should I create a PR for add it?

Add a user-agent generator

It appears we don't have a Faker.Internet.user_agent - could be handy.

Example:

Faker.Internet.user_agent #=> "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"

It could either return a predefined set of real user-agents or could generate fake ones based on common keywords, browser names, OS names and random digits, consisting of N samples joined with (space) from patterns like below:

$vendor_name/$version
($vendor_name $version)
($keyword, like $keyword)

Add "sku()" to Commerce (or Code?) module

When dealing with e-commerce, it's almost frequent to need unique sku. So it might be a good idea to add it to Commerce or Code modules. I'd put them on the former, but I saw you used the latter for stuff like isbns.

Add slug generator

Generate a URL safe slug. I think this could fall under the Internet namespace.

Example: this-is-a-slug

I'd be happy to tackle this if you think it would be valuable.

Fake.Internet.email() is not working.

I think faker is giving me non valid emails..

ryann_o'[email protected] is not a valid email format. (I think, tested with my regex and some online email validators)

The Faker.Internet.email() function should not provide me with wrong data. My tests are crying. ๐Ÿ˜ฅ

What about an Helper module ?

It would be awesome to have an Helper module:

Faker.Helper.pick ~w(jeremie peter laurent) #=> "peter"

Internally we have an awesome macro :sampler, I think it will be useful to provide an api for the developers ?!

I really liked another feature from Mirage (it's an npm / ember module to fake a REST API into the client):

Faker.Helper.cycle ~w(jeremie peter laurent henry frank zombie) 

#=> Everytime the function is called, it returns the next value in the list, 
#=> when it reachs the end, you just loop again the cycle.
#=> Really awesome when you seed a database

Remove JSON programming

As mentioned in #9, it's probably better to entirely remove JSON programming and only use JSON in order to store data.

My main concern is this: are fake data structures similar in all languages? I see you created a "team" object, which has the form [state] [creature]. In Italian for example, that would be [creature] [state].

What I would do is create a module for each fake data type (e.g., Faker.Team) to act as a namespace, and then create submodules of that namespace for each locale (e.g., Faker.Team.En). Then we could just delegate the functions to the right locale from Faker.Team (I think this could be done at compile-time, actually). This as the advantage of keeping everything separate, with a directory structure like this:

lib/
|-- en/
    |-- team.ex
|-- it/
    |-- team.ex
team.ex

or

lib
|-- team.ex
|-- team/
    |-- en.ex
    |-- it.ex

I'm pretty sure this solution would still need to start a :faker application though; this is mentioned as something to remove (and I agree!) on #9 again.

Did you have something in mind?

Warnings during compilation

I am getting multiple warnings when compiling Faker under Elixir 1.3.1:

==> faker
Compiling 22 files (.ex)
warning: crypto:rand_bytes/1 is deprecated and will be removed in a future release; use crypto:strong_rand_bytes/1
  lib/faker/bitcoin.ex:13

warning: crypto:rand_bytes/1 is deprecated and will be removed in a future release; use crypto:strong_rand_bytes/1
  lib/faker/bitcoin.ex:17

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/avatar.ex:43

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/avatar.ex:48

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/code.ex:5

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/code.ex:11

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/code.ex:17

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/internet.ex:31

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/internet.ex:61

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/address.ex:60

warning: random:uniform/0: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/address.ex:61

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/address.ex:69

warning: random:uniform/0: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/address.ex:70

Generated faker app

Documentation summary README removed

Can you explain me why you just removed the whole documentation I did ?

59e2bb4

I wanted to use the library to create some factories in my current application today.

The documentation we have is quite poor (we don't see the ouput of the different methods), that's why I spent 1hour 1 month ago to do this tiny documentation in the README. Nobody want to overthink, they just want a brief in the README what they can use and what it outputs.

Anyway, I'm really sad and I'm waiting for your reply.

Write small section README.md for contributors

Write a small section in README.md for contributors mentioning things like:

  • Use Faker.*/* functions as a source for randomness, instead of using Elixir/Erlang random functions.
  • conventions about locales & countries, writing tests, docs & examples
  • adding dependencies

Publish Hex version?

Hey folks, there is some commits that can be push to Hex. I am wondering if you could help with that. I know that you could probably arguing that you want to wait for X versioning but people like me needs some features and it's the point of versioning ๐Ÿ˜„

Faker.Internet.email does not work

iex(1)> Faker.Internet.email
** (UndefinedFunctionError) function :"Elixir.Faker.Name.".first_name/0 is undefined (module :"Elixir.Faker.Name." is not available)
    :"Elixir.Faker.Name.".first_name()
    lib/faker/internet.ex:31: Faker.Internet.user_name/1
    lib/faker/internet.ex:45: Faker.Internet.email/0

Make Faker.Date.date_of_birth/1 with valid dates

Right now dob can't be on 30 or 31. Suggestion is to introduce private function to_valid_day(date, month, year) and return maximum possible date, for example:

to_valid_day(31, 9, 2017) # => 30

In case of February we'll need to check for leap year.

Faker.Phone API

Hey folks,

I thinking about API for phones, here is my thoughts:

  • number/0 as general entry for mobile/landline numbers;
  • cell_number/0 & mobile_number/0;
  • landline_number/0;
  • area_code/0
  • exchange_code/0
  • subscriber_number/0
  • extension/0

In some cases arity can be 1 cause of rules length of subscriber_number based on area_code etc

Reasons behind separation is sometimes number split in db or UI.

I prefer to use Faker.format/1 there it is possible, because ideas of faker is to provide wide range of real world data (see Russian example below), so phone numbers is not just sequence of number and rules, but also style of formatting. Here is an example of code https://github.com/igas/faker/blob/0eb4aa3334e97e8a9ce41207934d1d631c92cc51/lib/faker/phone/en_gb.ex#L48-L55

And here is example from St. Petersburg, Russia of the same number how it can be written:

  • 8 812 123 45 67
  • 8 (812) 123 45 67
  • 8 812 1234567
  • 8 (812) 1234567
  • 8 (812) 123-45-67
  • 88121234567
  • 8812 1234567
  • 8-812-123-45-67
  • for every example on top first 8 can be replaced by +7
  • 1234567
  • 123 45 67
  • 123-45-67
  • etc

I'll be glad to discuss this before 0.7 release and decide API. Any thoughts, suggestions? Pros/cons?

/cc @vforvova @johnhamelink @devshane @efexen @saulecabrera @awanninger

Remove warnings on compilation

I guess it would be nice to remove all warnings from a console:

warning: crypto:rand_bytes/1 is deprecated and will be removed in a future release; use crypto:strong_rand_bytes/1
  lib/faker/bitcoin.ex:13

warning: crypto:rand_bytes/1 is deprecated and will be removed in a future release; use crypto:strong_rand_bytes/1
  lib/faker/bitcoin.ex:17

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/code.ex:5

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/code.ex:11

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/code.ex:17

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/avatar.ex:43

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/avatar.ex:48

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/internet.ex:31

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/internet.ex:61

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/address.ex:60

warning: random:uniform/0: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/address.ex:61

warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/address.ex:69

warning: random:uniform/0: the 'random' module is deprecated; use the 'rand' module instead
  lib/faker/address.ex:70

crypto:rand_uniform/2 is deprecated

Fyi, when compiling under Elixir 1.5.3, I'm seeing this warning quite frequently from lib/faker.

warning: crypto:rand_uniform/2 is deprecated and will be removed in a future release; use rand:uniform/1

Update hex.pm version

I just installed faker: 0.7.0 which I couldn't use Faker.Date because it wasn't there.

@igas could you please publish some new version of Faker to hex.pm ๐Ÿ‘

Should not try to randomly access a list

It seems like the core mechanism is this library is to use the sampler macro to define a function that access a giant _list_ at a random index. Lists are not meant for random access, they are slow and your access time is linear.

Keeping inline with the current mechanism, the sampler macro should be provided a giant tuple instead of a list. The macro itself would need to use elem to access the tuple instead of [].

Not working with Elixir 1.2

$ mix test
lib/faker/code.ex:1: warning: redefining module Faker.Code
lib/faker.ex:1: warning: redefining module Faker
lib/faker/avatar.ex:1: warning: redefining module Faker.Avatar
lib/faker/commerce.ex:1: warning: redefining module Faker.Commerce

== Compilation error on file lib/faker/app.ex ==
lib/faker/address.ex:1: warning: redefining module Faker.Address
** (CompileError) lib/faker/app.ex:2: cannot import Faker.sampler/2 because it doesn't exist
    (elixir) src/elixir_import.erl:68: :elixir_import.calculate/6
    (elixir) src/elixir_import.erl:18: :elixir_import.import/4

==> faker
could not compile dependency :faker, "mix compile" failed. You can recompile this dependency with "mix deps.compile faker", update it with "mix deps.update faker" or clean it with "mix deps.clean faker"

Are there changes in the works to get Faker working with Elixir 1.2?

Roadmap

  • Add elixir first class docs
  • Remove json programming
  • Remove application
  • Add different modules to different langs

Incorrect date generated by Faker.Date.date_of_birth

Hi folks,

I have a problem with Faker generating an incorrect date, making our tests randomly failed.

Let's say today is 2017-06-27.

Then Faker.Date.date_of_birth(17) should return only dates with month & day ranging up to 2000-06-26. Anything after that is below 17 years old.

A 2000-10-15 means that person is roughly 16 years 8 months old, not 17.

I will later have a PR to fix this problem.

I'm using YYYY-MM-DD as the date format

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.