ffaker 1.7.0 → 1.8.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/README.rdoc +24 -29
- data/ffaker.gemspec +4 -2
- data/lib/ffaker.rb +2 -1
- data/lib/ffaker/html_ipsum.rb +160 -0
- data/scripts/benchmark.rb +12 -19
- data/test/test_html_ipsum.rb +83 -0
- metadata +11 -5
data/README.rdoc
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
= ffaker
|
2
2
|
|
3
|
-
Fast Faker == Faker refactored
|
3
|
+
Fast Faker == Faker refactored. http://rubygems.org/gems/ffaker
|
4
4
|
|
5
5
|
= Faker
|
6
6
|
|
7
|
-
A port of Perl's Data::Faker library that generates fake data.
|
7
|
+
A port of Perl's Data::Faker library that generates fake data. http://rubygems.org/gems/faker
|
8
8
|
|
9
9
|
== Usage
|
10
10
|
|
11
11
|
require 'ffaker'
|
12
|
-
|
13
12
|
Faker::Name.name => "Christophe Bartell"
|
14
|
-
|
15
13
|
Faker::Internet.email => "kirsten.greenholt@corkeryfisher.info"
|
16
14
|
|
17
15
|
== Ffaker / Faker
|
18
16
|
|
19
|
-
|
17
|
+
Faker and Ffaker APIs are mostly the same, although the API on ffaker keeps
|
18
|
+
growing with its users additions. In general, the only difference is that you
|
19
|
+
need to:
|
20
20
|
|
21
21
|
gem install ffaker
|
22
22
|
|
@@ -26,19 +26,15 @@ and then
|
|
26
26
|
|
27
27
|
instead of "faker" with only one f.
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
The second difference is that Faker::VERSION is no longer a module, so instead of accessing the version like this:
|
32
|
-
|
33
|
-
Faker::VERSION::STRING # faker
|
34
|
-
|
35
|
-
you'll need to access it like this:
|
36
|
-
|
37
|
-
Faker::VERSION # ffaker
|
29
|
+
== Faster? does it really matter ?
|
38
30
|
|
39
|
-
|
31
|
+
Ffaker was initially written in an effort to speed up a slow spec suite. Bear
|
32
|
+
in mind, if your spec suite is slow, chances are the generation of random data
|
33
|
+
will not account for much of the run time.
|
40
34
|
|
41
|
-
|
35
|
+
Since then, the original faker gem has become faster (at the moment it did not
|
36
|
+
seem it was mantained). Nevertheless, ffaker is still about 20x faster than
|
37
|
+
faker.
|
42
38
|
|
43
39
|
$ cat scripts/benchmark.rb
|
44
40
|
|
@@ -53,21 +49,15 @@ $ cat scripts/benchmark.rb
|
|
53
49
|
end
|
54
50
|
end
|
55
51
|
|
56
|
-
* ruby 1.8.7 (
|
57
|
-
|
58
|
-
user system total real
|
59
|
-
Faker 9.240000 0.020000 9.260000 ( 9.297381)
|
60
|
-
Fast Faker 0.060000 0.000000 0.060000 ( 0.109047)
|
52
|
+
* ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03
|
61
53
|
|
62
|
-
|
54
|
+
generating 10000 names (faker 0.9.5) 1.500000 0.000000 1.500000 ( 1.506865)
|
55
|
+
generating 10000 names (ffaker 1.5.0) 0.070000 0.000000 0.070000 ( 0.067526)
|
63
56
|
|
64
|
-
|
65
|
-
Faker 74.980000 0.110000 75.090000 ( 75.881142)
|
66
|
-
Fast Faker 0.050000 0.000000 0.050000 ( 0.052292)
|
57
|
+
* ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
|
67
58
|
|
68
|
-
|
69
|
-
|
70
|
-
Try it in your own machine, your mileage may vary!
|
59
|
+
generating 10000 names (faker 0.9.5) 1.030000 0.020000 1.050000 ( 1.046116)
|
60
|
+
generating 10000 names (ffaker 1.7.0) 0.040000 0.000000 0.040000 ( 0.045917)
|
71
61
|
|
72
62
|
== Contributors
|
73
63
|
|
@@ -81,12 +71,17 @@ Try it in your own machine, your mileage may vary!
|
|
81
71
|
* David Noelte (https://github.com/marvin)
|
82
72
|
* Port 80 Labs (https://github.com/port80labs)
|
83
73
|
* Shane Weng (https://github.com/swcool)
|
74
|
+
* Chris Bloom (https://github.com/chrisbloom7)
|
84
75
|
|
85
76
|
== Changelog
|
86
77
|
|
78
|
+
* 1.8.0
|
79
|
+
|
80
|
+
Added Faker::HTMLIpsum module inspired in http://html-ipsum.com/ (Thanks Chris Bloom, https://github.com/EmmanuelOga/ffaker/pull/18)
|
81
|
+
|
87
82
|
* 1.7.0
|
88
83
|
|
89
|
-
Added Faker::LoremCN (Thanks Shane Weng, Shane Weng
|
84
|
+
Added Faker::LoremCN (Thanks Shane Weng, Shane Weng, https://github.com/swcool, https://github.com/EmmanuelOga/ffaker/pull/16/files)
|
90
85
|
|
91
86
|
* 1.6.0
|
92
87
|
|
data/ffaker.gemspec
CHANGED
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.rubygems_version = '1.3.5'
|
6
6
|
|
7
7
|
s.name = 'ffaker'
|
8
|
-
s.version = '1.
|
9
|
-
s.date = '2011-05-
|
8
|
+
s.version = '1.8.0'
|
9
|
+
s.date = '2011-05-30'
|
10
10
|
s.rubyforge_project = 'ffaker'
|
11
11
|
|
12
12
|
s.summary = "Faster Faker, generates dummy data."
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
lib/ffaker/company.rb
|
35
35
|
lib/ffaker/education.rb
|
36
36
|
lib/ffaker/geolocation.rb
|
37
|
+
lib/ffaker/html_ipsum.rb
|
37
38
|
lib/ffaker/internet.rb
|
38
39
|
lib/ffaker/lorem.rb
|
39
40
|
lib/ffaker/lorem_cn.rb
|
@@ -60,6 +61,7 @@ Gem::Specification.new do |s|
|
|
60
61
|
test/test_faker_name_de.rb
|
61
62
|
test/test_faker_name_ru.rb
|
62
63
|
test/test_geolocation.rb
|
64
|
+
test/test_html_ipsum.rb
|
63
65
|
test/test_lorem.rb
|
64
66
|
test/test_lorem_cn.rb
|
65
67
|
test/test_module_utils.rb
|
data/lib/ffaker.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Faker
|
2
|
-
VERSION = "1.
|
2
|
+
VERSION = "1.8.0"
|
3
3
|
|
4
4
|
require 'ffaker/utils/module_utils'
|
5
5
|
|
@@ -25,6 +25,7 @@ module Faker
|
|
25
25
|
autoload :AddressDE, 'ffaker/address_de'
|
26
26
|
autoload :Company, 'ffaker/company'
|
27
27
|
autoload :Education, 'ffaker/education'
|
28
|
+
autoload :HTMLIpsum, 'ffaker/html_ipsum'
|
28
29
|
autoload :Internet, 'ffaker/internet'
|
29
30
|
autoload :Lorem, 'ffaker/lorem'
|
30
31
|
autoload :LoremCN, 'ffaker/lorem_cn'
|
@@ -0,0 +1,160 @@
|
|
1
|
+
module Faker
|
2
|
+
# Loosely based on http://html-ipsum.com/
|
3
|
+
# Requires Faker::Lorem module
|
4
|
+
module HTMLIpsum
|
5
|
+
extend ModuleUtils
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def a(word_count = 2)
|
9
|
+
"<a href=\"##{word}\" title=\"#{words(word_count).capitalize!}\">#{words(word_count).capitalize!}</a>"
|
10
|
+
end
|
11
|
+
|
12
|
+
def p(count = 3, options = {})
|
13
|
+
options = {:fancy => false, :include_breaks => false}.merge(options)
|
14
|
+
if options[:fancy]
|
15
|
+
s = fancy_string(count, options[:include_breaks])
|
16
|
+
else
|
17
|
+
mode = options[:include_breaks] ? "paragraphs" : "paragraph"
|
18
|
+
s = send(mode.to_sym, count)
|
19
|
+
end
|
20
|
+
"<p>#{s}</p>"
|
21
|
+
end
|
22
|
+
|
23
|
+
def dl(definitions = 2)
|
24
|
+
s = "<dl>"
|
25
|
+
definitions.times do
|
26
|
+
s << "<dt>#{words(1).capitalize!}</dt><dd>#{paragraph 2}</dd>"
|
27
|
+
end
|
28
|
+
s << "</dl>"
|
29
|
+
end
|
30
|
+
|
31
|
+
def ul_short(items = 3)
|
32
|
+
s = "<ul>"
|
33
|
+
items.times do
|
34
|
+
s << "<li>#{sentence 2}</li>"
|
35
|
+
end
|
36
|
+
s << "</ul>"
|
37
|
+
end
|
38
|
+
|
39
|
+
def ul_long(items = 3)
|
40
|
+
s = "<ul>"
|
41
|
+
items.times do
|
42
|
+
s << "<li>#{paragraph 2}</li>"
|
43
|
+
end
|
44
|
+
s << "</ul>"
|
45
|
+
end
|
46
|
+
|
47
|
+
def ol_short(items = 3)
|
48
|
+
s = "<ol>"
|
49
|
+
items.times do
|
50
|
+
s << "<li>#{sentence 2}</li>"
|
51
|
+
end
|
52
|
+
s << "</ol>"
|
53
|
+
end
|
54
|
+
|
55
|
+
def ol_long(items = 3)
|
56
|
+
s = "<ol>"
|
57
|
+
items.times do
|
58
|
+
s << "<li>#{paragraph 2}</li>"
|
59
|
+
end
|
60
|
+
s << "</ol>"
|
61
|
+
end
|
62
|
+
|
63
|
+
def ul_links(items = 3)
|
64
|
+
s = "<ul>"
|
65
|
+
items.times do
|
66
|
+
s << "<li>#{a 1}</li>"
|
67
|
+
end
|
68
|
+
s << "</ul>"
|
69
|
+
end
|
70
|
+
|
71
|
+
def table(rows = 3)
|
72
|
+
s = "<table>
|
73
|
+
<thead>
|
74
|
+
<tr>
|
75
|
+
<th>#{word.capitalize!}</th>
|
76
|
+
<th>#{word.capitalize!}</th>
|
77
|
+
<th>#{word.capitalize!}</th>
|
78
|
+
<th>#{word.capitalize!}</th>
|
79
|
+
</tr>
|
80
|
+
</thead>
|
81
|
+
<tbody>"
|
82
|
+
rows.times do
|
83
|
+
s << "<tr>
|
84
|
+
<td>#{words(1).capitalize!}</td>
|
85
|
+
<td>#{words(1).capitalize!}</td>
|
86
|
+
<td>#{words(1).capitalize!}</td>
|
87
|
+
<td>#{a}</td>
|
88
|
+
</tr>"
|
89
|
+
end
|
90
|
+
s << "</tbody>
|
91
|
+
</table>"
|
92
|
+
end
|
93
|
+
|
94
|
+
def body
|
95
|
+
s = "<h1>#{words(2).capitalize!}</h1>"
|
96
|
+
rand(4).times do
|
97
|
+
s << "<p>#{fancy_string}</p>"
|
98
|
+
end
|
99
|
+
s << table(rand(4))
|
100
|
+
s << "<h2>#{words(2).capitalize!}</h2>
|
101
|
+
<ol>"
|
102
|
+
rand(4).times do
|
103
|
+
s << "<li>#{paragraph 1}</li>"
|
104
|
+
end
|
105
|
+
s << "</ol>
|
106
|
+
<blockquote><p>#{paragraphs 3}</p></blockquote>
|
107
|
+
<h3>#{words(2).capitalize!}</h3>
|
108
|
+
<ul>"
|
109
|
+
rand(4).times do
|
110
|
+
s << "<li>#{paragraph 1}</li>"
|
111
|
+
end
|
112
|
+
s << "</ul>
|
113
|
+
<pre><code>
|
114
|
+
##{word} h1 a {
|
115
|
+
display: block;
|
116
|
+
width: 300px;
|
117
|
+
height: 80px;
|
118
|
+
}
|
119
|
+
</code></pre>"
|
120
|
+
end
|
121
|
+
|
122
|
+
def fancy_string(count = 3, include_breaks = false)
|
123
|
+
sep = include_breaks ? "<br>" : " "
|
124
|
+
a = k([
|
125
|
+
"<strong>#{words(2).capitalize!}</strong>.",
|
126
|
+
"<em>#{paragraph}</em>",
|
127
|
+
"<code>#{words 2}</code>",
|
128
|
+
"#{a 2}"
|
129
|
+
] + Faker::Lorem::paragraphs(count))
|
130
|
+
a.random_pick(count).join(sep)
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
def word
|
136
|
+
Faker::Lorem::word
|
137
|
+
end
|
138
|
+
|
139
|
+
def words(word_count = 3)
|
140
|
+
Faker::Lorem::words(word_count).join(' ')
|
141
|
+
end
|
142
|
+
|
143
|
+
def sentence(word_count = 3)
|
144
|
+
Faker::Lorem::sentence(word_count)
|
145
|
+
end
|
146
|
+
|
147
|
+
def sentences(sentence_count = 3)
|
148
|
+
Faker::Lorem::sentences(sentence_count).join(' ')
|
149
|
+
end
|
150
|
+
|
151
|
+
def paragraph(sentence_count = 3)
|
152
|
+
Faker::Lorem::paragraph(sentence_count)
|
153
|
+
end
|
154
|
+
|
155
|
+
def paragraphs(paragraph_count = 3)
|
156
|
+
Faker::Lorem::paragraphs(paragraph_count).join('<br>')
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
end
|
data/scripts/benchmark.rb
CHANGED
@@ -1,27 +1,20 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'ffaker'
|
5
|
-
rescue LoadError
|
6
|
-
begin
|
7
|
-
require 'faker'
|
8
|
-
rescue LoadError
|
9
|
-
puts "You need to install either faker or ffaker to run this."
|
10
|
-
else
|
11
|
-
puts "Using Faker"
|
12
|
-
end
|
13
|
-
else
|
14
|
-
puts "Using Fast Faker"
|
15
|
-
end
|
16
|
-
|
17
2
|
require 'benchmark'
|
18
3
|
|
19
4
|
N = 10_000
|
20
5
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
6
|
+
def run(name)
|
7
|
+
require name
|
8
|
+
Benchmark.bm do |rep|
|
9
|
+
rep.report("generating #{ N } names (#{name} #{Faker::VERSION})") do
|
10
|
+
N.times do
|
11
|
+
Faker::Name.name
|
12
|
+
end
|
25
13
|
end
|
26
14
|
end
|
15
|
+
$stdout.flush
|
16
|
+
exit(0)
|
27
17
|
end
|
18
|
+
|
19
|
+
fork { run("faker") }; Process.wait
|
20
|
+
fork { run("ffaker") }; Process.wait
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestHTMLIpsum < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@tester = Faker::HTMLIpsum
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_a
|
9
|
+
assert_match /^<a href="#\w+" title="[ \w]+">[ \w]+<\/a>$/i, Faker::HTMLIpsum.a
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_p
|
13
|
+
# We can't predict the number of times the sentence pattern will repeat
|
14
|
+
# because the Faker::Lorem methods that we are using adds a random
|
15
|
+
# number on top of what we specify for the count argument.
|
16
|
+
assert_match /^<p>([ \w]+\.)+<\/p>$/i, Faker::HTMLIpsum.p
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_p_breaks
|
20
|
+
# Here we can at least test how many <br> tags there are.
|
21
|
+
assert_match /^<p>(?:[ \w\.]+<br>){2}[ \w\.]+<\/p>$/i, Faker::HTMLIpsum.p(3, {:include_breaks => true})
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_p_fancy
|
25
|
+
# We can't predict the number of times the sentence pattern will repeat
|
26
|
+
# because the Faker::Lorem methods that we are using adds a random
|
27
|
+
# number on top of what we specify for the count argument. We also have to
|
28
|
+
# account for the other HTML that is being returned.
|
29
|
+
assert_match /^<p>[[:alnum:][:punct:] <>\/]+<\/p>$/i, Faker::HTMLIpsum.p(5, {:fancy => true})
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_p_fancy_breaks
|
33
|
+
# Here we can at least test how many <br> tags there are. We also have to
|
34
|
+
# account for the other HTML that is being returned.
|
35
|
+
assert_match /^<p>(?:[[:alnum:][:punct:] <>\/]+?<br>){9}[[:alnum:][:punct:] <>\/]+?<\/p>/i, Faker::HTMLIpsum.p(10, {:fancy => true, :include_breaks => true})
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_dl
|
39
|
+
assert_match /^<dl>(<dt>[ \w]+<\/dt><dd>[ \w.]+<\/dd>){3}<\/dl>$/i, Faker::HTMLIpsum.dl(3)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_ul_short
|
43
|
+
assert_match /^<ul>(<li>[ \w.]+<\/li>){3}<\/ul>$/i, Faker::HTMLIpsum.ul_short(3)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_ul_long
|
47
|
+
assert_match /^<ul>(<li>[ \w.]+<\/li>){3}<\/ul>$/i, Faker::HTMLIpsum.ul_long(3)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_ol_short
|
51
|
+
assert_match /^<ol>(<li>[ \w.]+<\/li>){3}<\/ol>$/i, Faker::HTMLIpsum.ol_short(3)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_ol_long
|
55
|
+
assert_match /^<ol>(<li>[ \w.]+<\/li>){3}<\/ol>$/i, Faker::HTMLIpsum.ol_long(3)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_ul_links
|
59
|
+
assert_match /^<ul>(<li><a href="#\w+" title="\w+">[ \w]+<\/a><\/li>){3}<\/ul>$/i, Faker::HTMLIpsum.ul_links(3)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_table
|
63
|
+
assert_match /(<td>[ \w]+<\/td>\s*){3}/i, Faker::HTMLIpsum.table(3)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_body
|
67
|
+
# We can't reliably predict what's going to end up inside, so just ensure
|
68
|
+
# that we have a complete string.
|
69
|
+
assert_match /^<h1>.+<\/pre>$/im, Faker::HTMLIpsum.body
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_fancy_string
|
73
|
+
# We can't reliably predict what's going to end up inside, so just ensure
|
74
|
+
# that we have a complete string.
|
75
|
+
assert_match /^[[:alnum:][:punct:] <>\/]+$/im, Faker::HTMLIpsum.fancy_string
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_fancy_string_breaks
|
79
|
+
# We can't reliably predict what's going to end up inside, so just ensure
|
80
|
+
# that we have a complete string.
|
81
|
+
assert_match /^(?:[[:alnum:][:punct:] <>\/]+?<br>){2}[[:alnum:][:punct:] <>\/]+?$/im, Faker::HTMLIpsum.fancy_string(3, true)
|
82
|
+
end
|
83
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffaker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 55
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 1
|
7
|
-
-
|
8
|
+
- 8
|
8
9
|
- 0
|
9
|
-
version: 1.
|
10
|
+
version: 1.8.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Emmanuel Oga
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-30 00:00:00 -03:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -39,6 +40,7 @@ files:
|
|
39
40
|
- lib/ffaker/company.rb
|
40
41
|
- lib/ffaker/education.rb
|
41
42
|
- lib/ffaker/geolocation.rb
|
43
|
+
- lib/ffaker/html_ipsum.rb
|
42
44
|
- lib/ffaker/internet.rb
|
43
45
|
- lib/ffaker/lorem.rb
|
44
46
|
- lib/ffaker/lorem_cn.rb
|
@@ -65,6 +67,7 @@ files:
|
|
65
67
|
- test/test_faker_name_de.rb
|
66
68
|
- test/test_faker_name_ru.rb
|
67
69
|
- test/test_geolocation.rb
|
70
|
+
- test/test_html_ipsum.rb
|
68
71
|
- test/test_lorem.rb
|
69
72
|
- test/test_lorem_cn.rb
|
70
73
|
- test/test_module_utils.rb
|
@@ -83,6 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
86
|
requirements:
|
84
87
|
- - ">="
|
85
88
|
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
86
90
|
segments:
|
87
91
|
- 0
|
88
92
|
version: "0"
|
@@ -91,13 +95,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
95
|
requirements:
|
92
96
|
- - ">="
|
93
97
|
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
94
99
|
segments:
|
95
100
|
- 0
|
96
101
|
version: "0"
|
97
102
|
requirements: []
|
98
103
|
|
99
104
|
rubyforge_project: ffaker
|
100
|
-
rubygems_version: 1.
|
105
|
+
rubygems_version: 1.6.0
|
101
106
|
signing_key:
|
102
107
|
specification_version: 2
|
103
108
|
summary: Faster Faker, generates dummy data.
|
@@ -113,6 +118,7 @@ test_files:
|
|
113
118
|
- test/test_faker_name_de.rb
|
114
119
|
- test/test_faker_name_ru.rb
|
115
120
|
- test/test_geolocation.rb
|
121
|
+
- test/test_html_ipsum.rb
|
116
122
|
- test/test_lorem.rb
|
117
123
|
- test/test_lorem_cn.rb
|
118
124
|
- test/test_module_utils.rb
|