0

I'm looking at this Gem: https://github.com/stympy/faker

I use it quite a lot, and it is very good, but I don't get why all of its methods are organised into modules:

Faker::Code.isbn #=> "759021701-8"
Faker::Address.longitude #=> "-156.65548382095133"
Faker::Bitcoin.address #=> "1HUoGjmgChmnxxYhz87YytV4gVjfPaExmh"

I have to do this in my factories:

factory :person, class: Person do
    name { Faker::Lorem.word }
    account { Faker::Bitcoin.address } 
    address { Faker::Address.longitude }
    favourite_book { Faker::Code.isbn }
end

Can I include all of the modules into my test suite so I just need to do this:

factory :person, class: Person do
    name { word }
    account { address } 
    address { longitude }
    favourite_book { isbn }
end

I'm using rspec:

RSpec.configure do |config|
  config.include FactoryGirl::Syntax::Methods
  # doesn't work: config.include Faker
end

Why have they bothered separating their methods into separate methods? To make it faster? Surely this is a negligible amount unless you've got an insanely complex project? Wouldn't a better gem just let you do BetterFaker.word, BetterFaker.address ect? Be easier to remember :)

Starkers
  • 10,273
  • 21
  • 95
  • 158
  • 1
    Why don't you ask them why they wrote it that way? I don't think SO is the right place to ask about this. – Ismail Badawi Jun 27 '14 at 20:05
  • Faker isn't meant to be included anyway, `Faker::Bitcoin.address` will collide with the method `address` of the factory. – ichigolas Jun 27 '14 at 20:40

1 Answers1

0

I am willing to venture that the authors of the gem like to organize their files in a logical manner, and keep methods that have different scopes in different places.

Sean
  • 983
  • 5
  • 13