faker 0.9.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +27 -0
 - data/README.md +0 -13
 - data/lib/extensions/array.rb +5 -3
 - data/lib/faker.rb +55 -9
 - data/lib/faker/address.rb +14 -24
 - data/lib/faker/company.rb +6 -19
 - data/lib/faker/internet.rb +33 -10
 - data/lib/faker/lorem.rb +18 -11
 - data/lib/faker/name.rb +8 -2
 - data/lib/faker/phone_number.rb +9 -1
 - data/lib/faker/version.rb +1 -1
 - data/lib/locales/de-ch.yml +7 -0
 - data/lib/locales/de.yml +47 -0
 - data/lib/locales/en-au.yml +21 -0
 - data/lib/locales/en-bork.yml +4 -0
 - data/lib/locales/en-ca.yml +13 -0
 - data/lib/locales/en.yml +42 -22
 - data/lib/locales/nl.yml +65 -0
 - data/lib/locales/no-nb.yml +51 -0
 - data/lib/locales/pt-br.yml +56 -0
 - data/test/test_faker.rb +8 -2
 - data/test/test_faker_city.rb +45 -0
 - data/test/test_faker_internet.rb +9 -1
 - data/test/test_faker_lorem.rb +23 -0
 - data/test/test_faker_name.rb +1 -1
 - data/test/test_faker_street.rb +38 -0
 - data/test/test_flexible.rb +56 -0
 - data/test/test_helper.rb +1 -1
 - data/test/test_locale.rb +35 -0
 - metadata +24 -7
 
    
        data/test/test_faker_name.rb
    CHANGED
    
    
| 
         @@ -0,0 +1,38 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/test_helper.rb'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class TestFakerStreet < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 5 
     | 
    
         
            +
                shire = {
         
     | 
| 
      
 6 
     | 
    
         
            +
                  :faker => {
         
     | 
| 
      
 7 
     | 
    
         
            +
                    :address => {
         
     | 
| 
      
 8 
     | 
    
         
            +
                      :street_name => ['#{street_prefix} #{street_root} #{street_suffix}'],
         
     | 
| 
      
 9 
     | 
    
         
            +
                      :street_prefix => ["Wide"],
         
     | 
| 
      
 10 
     | 
    
         
            +
                      :street_root => ["Cheerful"],
         
     | 
| 
      
 11 
     | 
    
         
            +
                      :street_suffix => ["Path"],
         
     | 
| 
      
 12 
     | 
    
         
            +
                      :secondary_address => ["(Green Door)"],
         
     | 
| 
      
 13 
     | 
    
         
            +
                      :street_address => ['#{street_name} #{building_number}'],
         
     | 
| 
      
 14 
     | 
    
         
            +
                      :building_number => ["#"],
         
     | 
| 
      
 15 
     | 
    
         
            +
                    }
         
     | 
| 
      
 16 
     | 
    
         
            +
                  }
         
     | 
| 
      
 17 
     | 
    
         
            +
                }
         
     | 
| 
      
 18 
     | 
    
         
            +
                I18n.backend.store_translations(:shire, shire)
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              def test_street_name_supports_flexible_formats
         
     | 
| 
      
 22 
     | 
    
         
            +
                I18n.with_locale(:shire) do
         
     | 
| 
      
 23 
     | 
    
         
            +
                  assert_equal "Wide Cheerful Path", Faker::Address.street_name
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              def test_street_address_supports_flexible_formats
         
     | 
| 
      
 28 
     | 
    
         
            +
                I18n.with_locale(:shire) do
         
     | 
| 
      
 29 
     | 
    
         
            +
                  assert_match(/Wide Cheerful Path \d/, Faker::Address.street_address)
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              def test_street_address_optionally_provides_secondary_address
         
     | 
| 
      
 34 
     | 
    
         
            +
                I18n.with_locale(:shire) do
         
     | 
| 
      
 35 
     | 
    
         
            +
                  assert_match(/Wide Cheerful Path \d \(Green Door\)/, Faker::Address.street_address(:include_secondary))
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,56 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/test_helper.rb'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Faker
         
     | 
| 
      
 4 
     | 
    
         
            +
              class Foodie < Base
         
     | 
| 
      
 5 
     | 
    
         
            +
                flexible :chow
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
            end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            class TestFlexible < Test::Unit::TestCase
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 12 
     | 
    
         
            +
                I18n.backend.store_translations(:xx, :faker => {:chow => {:yummie => [:fudge, :chocolate, :caramel], :taste => "delicious"}})
         
     | 
| 
      
 13 
     | 
    
         
            +
                I18n.backend.store_translations(:home, :faker => {:address => {:birthplace => [:bed, :hospital, :airplane]}})
         
     | 
| 
      
 14 
     | 
    
         
            +
                I18n.backend.store_translations(:kindergarden, :faker => {:name => {:girls_name => [:alice, :cheryl, :tatiana]}})
         
     | 
| 
      
 15 
     | 
    
         
            +
                I18n.backend.store_translations(:work, :faker => {:company => {:do_stuff => [:work, :work, :work]}})
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              def test_flexible_multiple_values
         
     | 
| 
      
 19 
     | 
    
         
            +
                I18n.with_locale(:xx) do
         
     | 
| 
      
 20 
     | 
    
         
            +
                  actual = Faker::Foodie.yummie
         
     | 
| 
      
 21 
     | 
    
         
            +
                  assert [:fudge, :chocolate, :caramel].include? actual
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              def test_flexible_single_value
         
     | 
| 
      
 26 
     | 
    
         
            +
                I18n.with_locale(:xx) do
         
     | 
| 
      
 27 
     | 
    
         
            +
                  assert_equal "delicious", Faker::Foodie.taste
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              def test_raises_no_method_error
         
     | 
| 
      
 32 
     | 
    
         
            +
                I18n.with_locale(:xx) do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  assert_raise(NoMethodError) do
         
     | 
| 
      
 34 
     | 
    
         
            +
                    Faker::Foodie.eeew
         
     | 
| 
      
 35 
     | 
    
         
            +
                  end
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
              
         
     | 
| 
      
 39 
     | 
    
         
            +
              def test_address_is_flexible
         
     | 
| 
      
 40 
     | 
    
         
            +
                I18n.with_locale(:home) do
         
     | 
| 
      
 41 
     | 
    
         
            +
                  assert [:bed, :hospital, :airplane].include? Faker::Address.birthplace
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              def test_name_is_flexible
         
     | 
| 
      
 46 
     | 
    
         
            +
                I18n.with_locale(:kindergarden) do
         
     | 
| 
      
 47 
     | 
    
         
            +
                  assert [:alice, :cheryl, :tatiana].include? Faker::Name.girls_name
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              def test_company_is_flexible
         
     | 
| 
      
 52 
     | 
    
         
            +
                I18n.with_locale(:work) do
         
     | 
| 
      
 53 
     | 
    
         
            +
                  assert Faker::Company.do_stuff == :work
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
            end
         
     | 
    
        data/test/test_helper.rb
    CHANGED
    
    
    
        data/test/test_locale.rb
    ADDED
    
    | 
         @@ -0,0 +1,35 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            LoadedYaml = ['en', 'en-bork'].inject({}) do |h, locale|
         
     | 
| 
      
 4 
     | 
    
         
            +
              h[locale] = YAML.load_file(File.expand_path(File.dirname(__FILE__) + "/../lib/locales/#{locale}.yml"))[locale]['faker']
         
     | 
| 
      
 5 
     | 
    
         
            +
              h
         
     | 
| 
      
 6 
     | 
    
         
            +
            end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            class TestLocale < Test::Unit::TestCase
         
     | 
| 
      
 9 
     | 
    
         
            +
              def teardown
         
     | 
| 
      
 10 
     | 
    
         
            +
                Faker::Config.locale = nil
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              def test_locale_separate_from_i18n
         
     | 
| 
      
 14 
     | 
    
         
            +
                I18n.locale = :en
         
     | 
| 
      
 15 
     | 
    
         
            +
                Faker::Config.locale = :de
         
     | 
| 
      
 16 
     | 
    
         
            +
                assert Faker::PhoneNumber.phone_number.match(/\(0\d+\) \d+|\+49-\d+-\d+/)
         
     | 
| 
      
 17 
     | 
    
         
            +
                assert Faker::Address.street_name.match(//)
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
              
         
     | 
| 
      
 20 
     | 
    
         
            +
              def test_configured_locale_translation
         
     | 
| 
      
 21 
     | 
    
         
            +
                Faker::Config.locale = 'en-bork'
         
     | 
| 
      
 22 
     | 
    
         
            +
                assert_equal Faker::Base.translate('faker.lorem.words').first, LoadedYaml['en-bork']['lorem']['words'].first
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
              
         
     | 
| 
      
 25 
     | 
    
         
            +
              def test_locale_override_when_calling_translate
         
     | 
| 
      
 26 
     | 
    
         
            +
                Faker::Config.locale = 'en-bork'
         
     | 
| 
      
 27 
     | 
    
         
            +
                assert_equal Faker::Base.translate('faker.lorem.words', :locale => :en).first, LoadedYaml['en']['lorem']['words'].first
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
              
         
     | 
| 
      
 30 
     | 
    
         
            +
              def test_translation_fallback
         
     | 
| 
      
 31 
     | 
    
         
            +
                Faker::Config.locale = 'en-bork'
         
     | 
| 
      
 32 
     | 
    
         
            +
                assert_nil LoadedYaml['en-bork']['name']
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_equal Faker::Base.translate('faker.name.first_name').first, LoadedYaml['en']['name']['first_name'].first
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: faker
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              hash:  
     | 
| 
       5 
     | 
    
         
            -
              prerelease:  
     | 
| 
      
 4 
     | 
    
         
            +
              hash: 23
         
     | 
| 
      
 5 
     | 
    
         
            +
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              segments: 
         
     | 
| 
      
 7 
     | 
    
         
            +
              - 1
         
     | 
| 
      
 8 
     | 
    
         
            +
              - 0
         
     | 
| 
       7 
9 
     | 
    
         
             
              - 0
         
     | 
| 
       8 
     | 
    
         
            -
               
     | 
| 
       9 
     | 
    
         
            -
              - 5
         
     | 
| 
       10 
     | 
    
         
            -
              version: 0.9.5
         
     | 
| 
      
 10 
     | 
    
         
            +
              version: 1.0.0
         
     | 
| 
       11 
11 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
12 
     | 
    
         
             
            authors: 
         
     | 
| 
       13 
13 
     | 
    
         
             
            - Benjamin Curtis
         
     | 
| 
         @@ -15,7 +15,7 @@ autorequire: 
     | 
|
| 
       15 
15 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       16 
16 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
            date: 2011- 
     | 
| 
      
 18 
     | 
    
         
            +
            date: 2011-09-08 00:00:00 -07:00
         
     | 
| 
       19 
19 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       20 
20 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       21 
21 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -53,16 +53,28 @@ files: 
     | 
|
| 
       53 
53 
     | 
    
         
             
            - lib/faker/phone_number.rb
         
     | 
| 
       54 
54 
     | 
    
         
             
            - lib/faker/version.rb
         
     | 
| 
       55 
55 
     | 
    
         
             
            - lib/locales/de-ch.yml
         
     | 
| 
      
 56 
     | 
    
         
            +
            - lib/locales/de.yml
         
     | 
| 
      
 57 
     | 
    
         
            +
            - lib/locales/en-au.yml
         
     | 
| 
      
 58 
     | 
    
         
            +
            - lib/locales/en-bork.yml
         
     | 
| 
      
 59 
     | 
    
         
            +
            - lib/locales/en-ca.yml
         
     | 
| 
       56 
60 
     | 
    
         
             
            - lib/locales/en-gb.yml
         
     | 
| 
       57 
61 
     | 
    
         
             
            - lib/locales/en-us.yml
         
     | 
| 
       58 
62 
     | 
    
         
             
            - lib/locales/en.yml
         
     | 
| 
      
 63 
     | 
    
         
            +
            - lib/locales/nl.yml
         
     | 
| 
      
 64 
     | 
    
         
            +
            - lib/locales/no-nb.yml
         
     | 
| 
      
 65 
     | 
    
         
            +
            - lib/locales/pt-br.yml
         
     | 
| 
       59 
66 
     | 
    
         
             
            - History.txt
         
     | 
| 
       60 
67 
     | 
    
         
             
            - License.txt
         
     | 
| 
       61 
68 
     | 
    
         
             
            - README.md
         
     | 
| 
       62 
69 
     | 
    
         
             
            - test/test_faker.rb
         
     | 
| 
      
 70 
     | 
    
         
            +
            - test/test_faker_city.rb
         
     | 
| 
       63 
71 
     | 
    
         
             
            - test/test_faker_internet.rb
         
     | 
| 
      
 72 
     | 
    
         
            +
            - test/test_faker_lorem.rb
         
     | 
| 
       64 
73 
     | 
    
         
             
            - test/test_faker_name.rb
         
     | 
| 
      
 74 
     | 
    
         
            +
            - test/test_faker_street.rb
         
     | 
| 
      
 75 
     | 
    
         
            +
            - test/test_flexible.rb
         
     | 
| 
       65 
76 
     | 
    
         
             
            - test/test_helper.rb
         
     | 
| 
      
 77 
     | 
    
         
            +
            - test/test_locale.rb
         
     | 
| 
       66 
78 
     | 
    
         
             
            has_rdoc: true
         
     | 
| 
       67 
79 
     | 
    
         
             
            homepage: http://faker.rubyforge.org
         
     | 
| 
       68 
80 
     | 
    
         
             
            licenses: []
         
     | 
| 
         @@ -93,12 +105,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       93 
105 
     | 
    
         
             
            requirements: []
         
     | 
| 
       94 
106 
     | 
    
         | 
| 
       95 
107 
     | 
    
         
             
            rubyforge_project: faker
         
     | 
| 
       96 
     | 
    
         
            -
            rubygems_version: 1. 
     | 
| 
      
 108 
     | 
    
         
            +
            rubygems_version: 1.4.2
         
     | 
| 
       97 
109 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       98 
110 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       99 
111 
     | 
    
         
             
            summary: Easily generate fake data
         
     | 
| 
       100 
112 
     | 
    
         
             
            test_files: 
         
     | 
| 
       101 
113 
     | 
    
         
             
            - test/test_faker.rb
         
     | 
| 
      
 114 
     | 
    
         
            +
            - test/test_faker_city.rb
         
     | 
| 
       102 
115 
     | 
    
         
             
            - test/test_faker_internet.rb
         
     | 
| 
      
 116 
     | 
    
         
            +
            - test/test_faker_lorem.rb
         
     | 
| 
       103 
117 
     | 
    
         
             
            - test/test_faker_name.rb
         
     | 
| 
      
 118 
     | 
    
         
            +
            - test/test_faker_street.rb
         
     | 
| 
      
 119 
     | 
    
         
            +
            - test/test_flexible.rb
         
     | 
| 
       104 
120 
     | 
    
         
             
            - test/test_helper.rb
         
     | 
| 
      
 121 
     | 
    
         
            +
            - test/test_locale.rb
         
     |