Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions faker.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = "faker"
s.version = "0.3.2"
s.platform = Gem::Platform::RUBY
s.authors = []
s.email = []
s.homepage = "http://rubygems.org/gems/faker"
s.summary = "TODO: Write a gem summary"
s.description = "TODO: Write a gem description"

s.required_rubygems_version = ">= 1.3.6"
s.rubyforge_project = "faker"

s.add_development_dependency "bundler", ">= 1.0.0"

s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
s.require_path = 'lib'
end
3 changes: 2 additions & 1 deletion lib/faker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'faker/name'
require 'faker/phone_number'
require 'faker/version'
require 'faker/money'

require 'extensions/array'
require 'extensions/object'
Expand All @@ -23,4 +24,4 @@ def self.letterify(letter_string)
def self.bothify(string)
self.letterify(self.numerify(string))
end
end
end
15 changes: 14 additions & 1 deletion lib/faker/internet.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
require 'ipaddr'

module Faker
class Internet
class << self

def ipv4
IPAddr.new(rand(2**32),Socket::AF_INET)
end
alias :ip :ipv4

def password(size = 10)
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
(1..size.to_i).to_a.inject("") { |pass,i| pass << chars[rand(chars.size-1)] }
end

def email(name = nil)
[ user_name(name), domain_name ].join('@')
end
Expand Down Expand Up @@ -34,4 +47,4 @@ def domain_suffix
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/faker/lorem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.sentence(word_count = 4)
end

def self.sentences(sentence_count = 3)
returning([]) do |sentences|
[].tap do |sentences|
1.upto(sentence_count) do
sentences << sentence
end
Expand All @@ -24,7 +24,7 @@ def self.paragraph(sentence_count = 3)
end

def self.paragraphs(paragraph_count = 3)
returning([]) do |paragraphs|
[].tap do |paragraphs|
1.upto(paragraph_count) do
paragraphs << paragraph
end
Expand Down
54 changes: 54 additions & 0 deletions lib/faker/money.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module Faker
class Money
TestCards = {
:american_express => %w(
378282246310005
371449635398431
378734493671000
),
:discover => %w(
6011111111111117
6011000990139424
),
:mastercard => %w(
5555555555554444
5105105105105100
),
:visa => %w(
4111111111111111
4012888888881881
4222222222222
)
}

class << self

def number(n)
n.is_a?(Range) ? n.to_a.rand : rand(n)
end

def currency_string(lim = (50..100))
sprintf("%.2f", "#{number(lim) - 1}.#{number(0..100)}".to_f)
end

def test_number(issuer = :all)
return all_cards.sample if issuer && issuer.to_sym == :all
cards_for(issuer).sample
end

def cards_for(issuer)
issuer = issuer.to_s.downcase.to_sym
TestCards[issuer] rescue []
end

def issuers
[:visa, :mastercard, :american_express, :discover]
end

def all_cards
issuers.collect { |t| cards_for(t) }.flatten.uniq.compact
end

end
end
end
10 changes: 10 additions & 0 deletions test/test_faker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ def setup
def test_numerify
assert Faker.numerify('###').match(/\d{3}/)
end


def test_cc
assert Faker::Money::TestCards.values.flatten.include?(Faker::Money.test_number)
end

def test_money
assert Faker::Money.currency_string(12..25).to_f < 25
assert Faker::Money.currency_string(12..25).to_f > 12
end
end