1
0
mirror of https://github.com/askn/faker.git synced 2023-08-10 21:13:01 +03:00

GH-2 Add ability to seed

All the random functions are now passed through Faker.rng, a random
number generator that is created by default, but can also be set with
`Faker.seed`.

The tests use all the examples in the README to ensure that everything
has been seeded properly.

The only module not updated is Finance, but that's because the file
itself did not seem to compile, and there weren't any examples of using
it in the README.
This commit is contained in:
Caroline Glassberg-Powell
2017-07-09 12:41:45 +01:00
parent 8610498397
commit 284782b26a
20 changed files with 228 additions and 52 deletions

24
spec/address_spec.cr Normal file
View File

@ -0,0 +1,24 @@
require "./spec_helper"
describe Faker::Address do
it "should return deterministic results when seeded" do
Faker.seed 123456
Faker::Address.city.should eq "North Mercedesmouth"
Faker::Address.street_name.should eq "Thalia Tunnel"
Faker::Address.street_address.should eq "33421 Kunde Mills"
Faker::Address.secondary_address.should eq "Apt. 475"
Faker::Address.building_number.should eq "4103"
Faker::Address.zip_code.should eq "32555"
Faker::Address.postcode.should eq "GX44 3IC"
Faker::Address.time_zone.should eq "Asia/Rangoon"
Faker::Address.street_suffix.should eq "Springs"
Faker::Address.city_suffix.should eq "town"
Faker::Address.city_prefix.should eq "North"
Faker::Address.state.should eq "Missouri"
Faker::Address.state_abbr.should eq "TN"
Faker::Address.country.should eq "Svalbard & Jan Mayen Islands"
Faker::Address.country_code.should eq "IS"
Faker::Address.latitude.should eq "15.393888556377334"
Faker::Address.longitude.should eq "-77.86301819889268"
end
end

10
spec/business_spec.cr Normal file
View File

@ -0,0 +1,10 @@
require "./spec_helper"
describe Faker::Business do
it "should return deterministic results when seeded" do
Faker.seed 123456
Faker::Business.credit_card_number.should eq "1234-2121-1221-1211"
Faker::Business.credit_card_expiry_date.should eq Time.new(2013, 9, 12)
Faker::Business.credit_card_type.should eq "diners_club"
end
end

View File

@ -52,4 +52,15 @@ describe Faker::Commerce do
it "price_is_float" do
Faker::Commerce.price.is_a?(Float).should be_true
end
it "should return deterministic results when seeded" do
Faker.seed 123456
Faker::Commerce.color.should eq "salmon"
Faker::Commerce.department.should eq "Home, Movies & Computers"
Faker::Commerce.department(5).should eq "Toys & Home"
Faker::Commerce.department(2, true).should eq "Electronics & Tools"
Faker::Commerce.product_name.should eq "Heavy Duty Copper Lamp"
Faker::Commerce.price.should eq 47.25
Faker::Commerce.material.should eq "Rubber"
end
end

View File

@ -5,4 +5,11 @@ describe Faker::Company do
it "logo" do
Faker::Company.logo.match(%r{https://pigment.github.io/fake-logos/logos/medium/color/\d+\.png}).should_not eq nil
end
it "should return deterministic results when seeded" do
Faker.seed 123456
Faker::Company.name.should eq "Larson-Altenwerth"
Faker::Company.suffix.should eq "Group"
Faker::Company.logo.should eq "https://pigment.github.io/fake-logos/logos/medium/color/12.png"
end
end

View File

@ -29,4 +29,14 @@ describe Faker::Hacker do
it "ingverb" do
Faker::Hacker.ingverb.match(/\w+/).should_not eq nil
end
it "should return deterministic results when seeded" do
Faker.seed 123456
Faker::Hacker.say_something_smart.should eq "You can't override the sensor without overriding the primary JBOD transmitter!"
Faker::Hacker.abbreviation.should eq "SCSI"
Faker::Hacker.adjective.should eq "primary"
Faker::Hacker.noun.should eq "pixel"
Faker::Hacker.verb.should eq "transmit"
Faker::Hacker.ingverb.should eq "calculating"
end
end

View File

@ -166,4 +166,35 @@ describe Faker::Internet do
it "device_token" do
# Faker::Internet.device_token.size.should eq 64
end
it "should return deterministic results when seeded" do
Faker.seed 123456
Faker::Internet.email.should eq "internet_faker@kirlinblock.biz"
Faker::Internet.email("Nancy").should eq "nancy@cremin.io"
Faker::Internet.free_email.should eq "faker.internet@gmail.com"
Faker::Internet.free_email("Nancy").should eq "nancy@hotmail.com"
Faker::Internet.safe_email.should eq "faker_internet@example.net"
Faker::Internet.safe_email("Nancy").should eq "nancy@example.net"
Faker::Internet.user_name.should eq "faker.internet"
Faker::Internet.user_name("Nancy").should eq "nancy"
Faker::Internet.user_name("Nancy Johnson", [".", "_", "-"] of ::String).should eq "johnson.nancy"
Faker::Internet.password.should eq "Tb34Ap05U"
Faker::Internet.password(8).should eq "BhI59sBo9"
Faker::Internet.password(10, 20).should eq "9r3b4iL8HeY"
Faker::Internet.password(10, 20, true).should eq "91JpPrF867Z"
Faker::Internet.password(10, 20, true, true).should eq "Pl5q3eOqZsK"
Faker::Internet.domain_name.should eq "ullrichklocko.biz"
Faker::Internet.domain_word.should eq "lockman"
Faker::Internet.domain_suffix.should eq "net"
Faker::Internet.ip_v4_address.should eq "6.70.63.244"
Faker::Internet.ip_v6_address.should eq "8a31:c21c:fb41:eea8:9df:aeab:9f78:5a49"
Faker::Internet.mac_address.should eq "00:4b:14:3d:24:55"
Faker::Internet.mac_address("55:44:33").should eq "55:44:33:36:0e:5d"
Faker::Internet.url.should eq "http://koelpin.biz/internet_faker"
Faker::Internet.url("example.com").should eq "http://example.com/faker_internet"
Faker::Internet.url("example.com", "/foobar.html").should eq "http://example.com/foobar.html"
Faker::Internet.slug.should eq "voluptatem.dicta"
Faker::Internet.slug("foo bar").should eq "foo.bar"
Faker::Internet.slug("foo bar", "-").should eq "foo-bar"
end
end

33
spec/lorem_spec.cr Normal file
View File

@ -0,0 +1,33 @@
require "./spec_helper"
describe Faker::Lorem do
it "should return deterministic results when seeded" do
Faker.seed 123456
Faker::Lorem.word.should eq "voluptatem"
Faker::Lorem.words.should eq ["quos", "recusandae", "sed"]
Faker::Lorem.words(4).should eq ["iusto", "quia", "placeat", "quia"]
Faker::Lorem.words(4, true).should eq ["vis", "ambulo", "vesica", "vivo"]
Faker::Lorem.characters.should eq "xk7jz4c7a0w5ceh9opz68kq3xzdt5d2rtu29ky6jlb1ltxk3xvqkp87o2c7bs070wggzuz78an6t4cg8fejvhskgfe6ry104yc7kam8p91oaf6bqb61tp84q4958om8glep3wjrl9no32fj1eoklww8bzhvzmdkyp1tn51zxpzm8eynd7mbix1rimwrpufnut2a58d76mwrn4epjao7pedef2roosl2simxsvi4lejwzrdojegew2csobpw2lym"
Faker::Lorem.characters(10).should eq "vp5j8u3r1l"
Faker::Lorem.sentence.should eq "Itaque quod aliquam veritatis nemo dolorum sequi."
Faker::Lorem.sentence(3).should eq "Accusantium dolores suscipit praesentium."
Faker::Lorem.sentence(3, true).should eq "Spiculum triumphus necessitatibus appono angulus aut cariosus."
Faker::Lorem.sentence(3, false, 4).should eq "Atque sed perferendis minus."
Faker::Lorem.sentence(3, true, 4).should eq "Cohors traho tamdiu alveus itaque."
Faker::Lorem.sentences.should eq ["Sed ab quia.",
"Consequatur doloremque dolores ratione voluptas esse aut vero.",
"Qui dicta est odit nihil exercitationem nesciunt."]
Faker::Lorem.sentences(1).should eq ["Reiciendis doloremque vero sequi et quia."]
Faker::Lorem.sentences(1, true).should eq ["Concido quisquam cerno vulpes maxime mollitia."]
Faker::Lorem.paragraph.should eq "Maxime magnam vel velit id. Sed cupiditate blanditiis. Cupiditate sit aliquam vero."
Faker::Lorem.paragraph(2).should eq "Nemo laboriosam quod accusamus ab modi excepturi. Eveniet rerum quasi quia culpa. Vero quis aut. A assumenda tenetur."
Faker::Lorem.paragraph(2, true).should eq "Pecunia sopor ars vero subiungo quis urbanus. Demens minus delinquo."
Faker::Lorem.paragraph(2, false, 4).should eq "Mollitia delectus qui et ut quasi. Eligendi aut facilis praesentium ducimus qui. Itaque molestiae laudantium qui omnis veritatis soluta. Quia reiciendis dignissimos saepe architecto. Eum excepturi dolores iusto quisquam."
Faker::Lorem.paragraph(2, true, 4).should eq "Depraedor vitae spectaculum cupio acervus conatus adipisci. Pecus vulgivagus terra aliqua arbitro. Suscipio socius cupiditas arguo cetera colloco trans solitudo. Adimpleo stillicidium eaque ocer placeat adstringo ustulo balbus. Versus viduo videlicet tenus absconditus."
Faker::Lorem.paragraphs.should eq ["Rerum odit ducimus ipsum at sint. Consequatur sed non dolorem. Incidunt quae libero. Enim quam molestiae necessitatibus.",
"Inventore eos dolores asperiores corrupti cupiditate. Illum at molestiae cumque eaque aut. Blanditiis et laudantium neque. Consequatur labore officiis pariatur possimus facilis.",
"Esse fuga cum quisquam tenetur impedit rem repellat. Quia deleniti nulla. Excepturi perferendis dolor accusamus."]
Faker::Lorem.paragraphs(1).should eq ["Rerum unde voluptas sint autem. Fugit tenetur sequi totam esse. Explicabo omnis consequatur inventore autem. Et et praesentium neque quo natus."]
Faker::Lorem.paragraphs(1, true).should eq ["Conitor reiciendis minima viridis temporibus spiritus. Tabula crustulum error titulus et comptus. Coruscus turpis amplitudo combibo alias deludo triginta."]
end
end

13
spec/name_spec.cr Normal file
View File

@ -0,0 +1,13 @@
require "./spec_helper"
describe Faker::Name do
it "should return deterministic results when seeded" do
Faker.seed 123456
Faker::Name.name.should eq "Bernie Altenwerth"
Faker::Name.first_name.should eq "Ron"
Faker::Name.last_name.should eq "Block"
Faker::Name.prefix.should eq "Mrs."
Faker::Name.suffix.should eq "Sr."
Faker::Name.title.should eq "Product Markets Specialist"
end
end

View File

@ -64,4 +64,16 @@ describe Faker::Number do
Faker::Number.hexadecimal(4).match(/[0-9a-f]{4}/).should_not eq nil
Faker::Number.hexadecimal(7).match(/[0-9a-f]{7}/).should_not eq nil
end
it "should return deterministic results when seeded" do
Faker.seed 123456
Faker::Number.number(10).should eq "6961710422"
Faker::Number.decimal(2).should eq "82.34"
Faker::Number.decimal(2, 3).should eq "21.217"
Faker::Number.hexadecimal(3).should eq "046"
Faker::Number.between(1, 10).should eq 2
Faker::Number.positive.should eq 3995.8054520295627
Faker::Number.negative.should eq -748.5527873256278
Faker::Number.digit.should eq "2"
end
end

View File

@ -0,0 +1,8 @@
require "./spec_helper"
describe Faker::PhoneNumber do
it "should return deterministic results when seeded" do
Faker.seed 123456
Faker::PhoneNumber.phone_number.should eq "361-710-4228 x23421"
end
end

View File

@ -16,4 +16,11 @@ describe Faker::Team do
it "sport" do
# Faker::Team.sport.match(/(\w+){1}/).should_not eq nil
end
it "should return deterministic results when seeded" do
Faker.seed 123456
Faker::Team.creature.should eq "buffalo"
Faker::Team.name.should eq "Washington sorcerors"
Faker::Team.state.should eq "Delaware"
end
end