forgery 0.2.2 → 0.3.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/.gitignore +3 -0
- data/LICENSE +20 -0
- data/README.markdown +13 -13
- data/Rakefile +50 -0
- data/VERSION.yml +3 -2
- data/forgery.gemspec +120 -0
- data/init.rb +1 -0
- data/lib/forgery.rb +14 -28
- data/lib/forgery/dictionaries.rb +24 -0
- data/lib/{dictionaries → forgery/dictionaries}/cities +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/colors +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/company_names +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/countries +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/female_first_names +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/frequencies +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/genders +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/languages +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/last_names +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/lorem_ipsum +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/male_first_names +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/name_suffixes +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/name_titles +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/province_abbrevs +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/provinces +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/races +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/shirt_sizes +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/state_abbrevs +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/states +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/street_suffixes +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/streets +0 -0
- data/lib/{dictionaries → forgery/dictionaries}/top_level_domains +0 -0
- data/lib/{extensions → forgery/extensions}/array.rb +0 -0
- data/lib/{extensions → forgery/extensions}/hash.rb +0 -0
- data/lib/{extensions → forgery/extensions}/range.rb +0 -0
- data/lib/{extensions → forgery/extensions}/string.rb +1 -0
- data/lib/forgery/file_reader.rb +69 -0
- data/lib/forgery/forgery.rb +23 -0
- data/lib/{forgeries/address_forgery.rb → forgery/forgery/address.rb} +27 -25
- data/lib/{forgeries/basic_forgery.rb → forgery/forgery/basic.rb} +41 -1
- data/lib/{forgeries/internet_forgery.rb → forgery/forgery/internet.rb} +4 -2
- data/lib/{forgeries/lorem_ipsum_forgery.rb → forgery/forgery/lorem_ipsum.rb} +1 -2
- data/lib/{forgeries/monetary_forgery.rb → forgery/forgery/monetary.rb} +3 -1
- data/lib/{forgeries/name_forgery.rb → forgery/forgery/name.rb} +2 -1
- data/lib/{forgeries/personal_forgery.rb → forgery/forgery/personal.rb} +2 -1
- data/lib/forgery/forgery_api.rb +9 -0
- data/lib/forgery/formats.rb +24 -0
- data/lib/{formats → forgery/formats}/phone +0 -0
- data/lib/{formats → forgery/formats}/street_number +0 -0
- data/lib/{formats → forgery/formats}/zip +0 -0
- data/spec/dictionaries_spec.rb +4 -4
- data/spec/file_reader_spec.rb +3 -3
- data/spec/{forgeries/address_forgery_spec.rb → forgery/address_spec.rb} +13 -13
- data/spec/{forgeries/basic_forgery_spec.rb → forgery/basic_spec.rb} +51 -51
- data/spec/{forgeries/internet_forgery_spec.rb → forgery/internet_spec.rb} +6 -6
- data/spec/{forgeries/lorem_ipsum_forgery_spec.rb → forgery/lorem_ipsum_spec.rb} +26 -26
- data/spec/{forgeries/monetary_forgery_spec.rb → forgery/monetary_spec.rb} +1 -1
- data/spec/{forgeries/name_forgery_spec.rb → forgery/name_spec.rb} +1 -1
- data/spec/{forgeries/personal_forgery_spec.rb → forgery/personal_spec.rb} +3 -3
- data/spec/forgery_spec.rb +33 -6
- data/spec/formats_spec.rb +4 -4
- metadata +78 -57
- data/lib/dictionaries.rb +0 -24
- data/lib/file_reader.rb +0 -53
- data/lib/formats.rb +0 -24
@@ -1,175 +1,175 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Forgery::Basic do
|
4
4
|
describe ".password" do
|
5
5
|
it "should only uppercase characters" do
|
6
|
-
|
6
|
+
Forgery::Basic.password(:allow_lower => false,
|
7
7
|
:allow_upper => true,
|
8
8
|
:allow_numeric => false,
|
9
|
-
:allow_special => false).should only_contain(
|
9
|
+
:allow_special => false).should only_contain(Forgery::Basic::UPPER_ALPHA)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should only contain lowercase characters" do
|
13
|
-
|
13
|
+
Forgery::Basic.password(:allow_lower => true,
|
14
14
|
:allow_upper => false,
|
15
15
|
:allow_numeric => false,
|
16
|
-
:allow_special => false).should only_contain(
|
16
|
+
:allow_special => false).should only_contain(Forgery::Basic::LOWER_ALPHA)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should only contain numeric characters" do
|
20
|
-
|
20
|
+
Forgery::Basic.password(:allow_lower => false,
|
21
21
|
:allow_upper => false,
|
22
22
|
:allow_numeric => true,
|
23
|
-
:allow_special => false).should only_contain(
|
23
|
+
:allow_special => false).should only_contain(Forgery::Basic::NUMERIC)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should only contain special characters" do
|
27
|
-
|
27
|
+
Forgery::Basic.password(:allow_lower => false,
|
28
28
|
:allow_upper => false,
|
29
29
|
:allow_numeric => false,
|
30
|
-
:allow_special => true).should only_contain(
|
30
|
+
:allow_special => true).should only_contain(Forgery::Basic::SPECIAL_CHARACTERS)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should only contain lower and uppercase characters" do
|
34
|
-
|
34
|
+
Forgery::Basic.password(:allow_lower => true,
|
35
35
|
:allow_upper => true,
|
36
36
|
:allow_numeric => false,
|
37
|
-
:allow_special => false).should only_contain(
|
38
|
-
|
37
|
+
:allow_special => false).should only_contain(Forgery::Basic::LOWER_ALPHA,
|
38
|
+
Forgery::Basic::UPPER_ALPHA)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should only contain numeric and special characters" do
|
42
|
-
|
42
|
+
Forgery::Basic.password(:allow_lower => false,
|
43
43
|
:allow_upper => false,
|
44
44
|
:allow_numeric => true,
|
45
|
-
:allow_special => true).should only_contain(
|
46
|
-
|
45
|
+
:allow_special => true).should only_contain(Forgery::Basic::NUMERIC,
|
46
|
+
Forgery::Basic::SPECIAL_CHARACTERS)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should contain any of the defined characters" do
|
50
|
-
|
50
|
+
Forgery::Basic.password(:allow_lower => true,
|
51
51
|
:allow_upper => true,
|
52
52
|
:allow_numeric => true,
|
53
|
-
:allow_special => true).should only_contain(
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
:allow_special => true).should only_contain(Forgery::Basic::NUMERIC,
|
54
|
+
Forgery::Basic::SPECIAL_CHARACTERS,
|
55
|
+
Forgery::Basic::LOWER_ALPHA,
|
56
|
+
Forgery::Basic::UPPER_ALPHA)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
describe ".encrypt" do
|
61
61
|
it "should encrypt to hex digits" do
|
62
|
-
|
62
|
+
Forgery::Basic.encrypt("something").should only_contain(Forgery::Basic::HEX_DIGITS)
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should encrypt different words to different output" do
|
66
|
-
|
66
|
+
Forgery::Basic.encrypt("foo").should_not == Forgery::Basic.encrypt("bar")
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should allow a salt that changes the output" do
|
70
|
-
|
70
|
+
Forgery::Basic.encrypt("foo", "baz").should_not == Forgery::Basic.encrypt("foo", "bar")
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should have the same output when encrypting twice" do
|
74
|
-
|
74
|
+
Forgery::Basic.encrypt("foo", "bar").should == Forgery::Basic.encrypt("foo", "bar")
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
describe ".boolean" do
|
79
79
|
it "should return true or false" do
|
80
|
-
[true, false].should include(
|
80
|
+
[true, false].should include(Forgery::Basic.boolean)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
describe ".color" do
|
85
85
|
it "should return a random color" do
|
86
|
-
Forgery.dictionaries[:colors].should include(
|
86
|
+
Forgery.dictionaries[:colors].should include(Forgery::Basic.color)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
describe ".hex_color" do
|
91
91
|
it "should return a 6-character hex color" do
|
92
|
-
|
92
|
+
Forgery::Basic.hex_color.should match(/#(#{Forgery::Basic::HEX_DIGITS.join('|')}){6}/)
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
96
|
describe ".short_hex_color" do
|
97
97
|
it "should return a 3-character hex color" do
|
98
|
-
|
98
|
+
Forgery::Basic.short_hex_color.should match(/#(#{Forgery::Basic::HEX_DIGITS.join('|')}){3}/)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
102
|
describe ".number" do
|
103
103
|
it "should return a number >= the at_least option" do
|
104
|
-
|
104
|
+
Forgery::Basic.number(:at_least => 2).should >= 2
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should return a number <= the at_most option" do
|
108
|
-
|
108
|
+
Forgery::Basic.number(:at_most => 12).should <= 12
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
112
|
describe ".text" do
|
113
113
|
it "should return text whose length is >= the at_least option" do
|
114
|
-
|
114
|
+
Forgery::Basic.text(:at_least => 5).size.should >= 5
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should return text whose length is <= the at_most option" do
|
118
|
-
|
118
|
+
Forgery::Basic.text(:at_least => 15).size.should <= 15
|
119
119
|
end
|
120
120
|
|
121
121
|
it "should only uppercase characters" do
|
122
|
-
|
122
|
+
Forgery::Basic.text(:allow_lower => false,
|
123
123
|
:allow_upper => true,
|
124
124
|
:allow_numeric => false,
|
125
|
-
:allow_special => false).should only_contain(
|
125
|
+
:allow_special => false).should only_contain(Forgery::Basic::UPPER_ALPHA)
|
126
126
|
end
|
127
127
|
|
128
128
|
it "should only contain lowercase characters" do
|
129
|
-
|
129
|
+
Forgery::Basic.text(:allow_lower => true,
|
130
130
|
:allow_upper => false,
|
131
131
|
:allow_numeric => false,
|
132
|
-
:allow_special => false).should only_contain(
|
132
|
+
:allow_special => false).should only_contain(Forgery::Basic::LOWER_ALPHA)
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should only contain numeric characters" do
|
136
|
-
|
136
|
+
Forgery::Basic.text(:allow_lower => false,
|
137
137
|
:allow_upper => false,
|
138
138
|
:allow_numeric => true,
|
139
|
-
:allow_special => false).should only_contain(
|
139
|
+
:allow_special => false).should only_contain(Forgery::Basic::NUMERIC)
|
140
140
|
end
|
141
141
|
|
142
142
|
it "should only contain special characters" do
|
143
|
-
|
143
|
+
Forgery::Basic.text(:allow_lower => false,
|
144
144
|
:allow_upper => false,
|
145
145
|
:allow_numeric => false,
|
146
|
-
:allow_special => true).should only_contain(
|
146
|
+
:allow_special => true).should only_contain(Forgery::Basic::SPECIAL_CHARACTERS)
|
147
147
|
end
|
148
148
|
|
149
149
|
it "should only contain lower and uppercase characters" do
|
150
|
-
|
150
|
+
Forgery::Basic.text(:allow_lower => true,
|
151
151
|
:allow_upper => true,
|
152
152
|
:allow_numeric => false,
|
153
|
-
:allow_special => false).should only_contain(
|
154
|
-
|
153
|
+
:allow_special => false).should only_contain(Forgery::Basic::LOWER_ALPHA,
|
154
|
+
Forgery::Basic::UPPER_ALPHA)
|
155
155
|
end
|
156
156
|
|
157
157
|
it "should only contain numeric and special characters" do
|
158
|
-
|
158
|
+
Forgery::Basic.text(:allow_lower => false,
|
159
159
|
:allow_upper => false,
|
160
160
|
:allow_numeric => true,
|
161
|
-
:allow_special => true).should only_contain(
|
162
|
-
|
161
|
+
:allow_special => true).should only_contain(Forgery::Basic::NUMERIC,
|
162
|
+
Forgery::Basic::SPECIAL_CHARACTERS)
|
163
163
|
end
|
164
164
|
|
165
165
|
it "should contain any of the defined characters" do
|
166
|
-
|
166
|
+
Forgery::Basic.text(:allow_lower => true,
|
167
167
|
:allow_upper => true,
|
168
168
|
:allow_numeric => true,
|
169
|
-
:allow_special => true).should only_contain(
|
170
|
-
|
171
|
-
|
172
|
-
|
169
|
+
:allow_special => true).should only_contain(Forgery::Basic::NUMERIC,
|
170
|
+
Forgery::Basic::SPECIAL_CHARACTERS,
|
171
|
+
Forgery::Basic::LOWER_ALPHA,
|
172
|
+
Forgery::Basic::UPPER_ALPHA)
|
173
173
|
end
|
174
174
|
end
|
175
175
|
end
|
@@ -1,30 +1,30 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Forgery::Internet do
|
4
4
|
describe ".user_name" do
|
5
5
|
it "should return a username that is lowercase" do
|
6
|
-
|
6
|
+
Forgery::Internet.user_name.should only_contain(Forgery::Basic::LOWER_ALPHA)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should return a top level domain" do
|
11
|
-
Forgery.dictionaries[:top_level_domains].should include(
|
11
|
+
Forgery.dictionaries[:top_level_domains].should include(Forgery::Internet.top_level_domain)
|
12
12
|
end
|
13
13
|
|
14
14
|
describe ".domain_name" do
|
15
15
|
it "should return a domain name that contains a lowercase company name" do
|
16
|
-
downcase_company_name =
|
16
|
+
downcase_company_name = Forgery::Internet.domain_name.split('.').first
|
17
17
|
Forgery.dictionaries[:company_names].any?{ |cn| cn =~ /#{downcase_company_name}/i }
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should return a domain name that contains a top level domain" do
|
21
|
-
Forgery.dictionaries[:top_level_domains].should include(
|
21
|
+
Forgery.dictionaries[:top_level_domains].should include(Forgery::Internet.domain_name.split('.').last)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
describe ".email_address" do
|
26
26
|
it "should match the email format" do
|
27
|
-
|
27
|
+
Forgery::Internet.email_address.should match(/.+@.+\.(#{Forgery.dictionaries[:top_level_domains].join("|")})/)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -1,128 +1,128 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Forgery::LoremIpsum do
|
4
4
|
describe ".paragraphs" do
|
5
5
|
it "should return text" do
|
6
|
-
|
6
|
+
Forgery::LoremIpsum.paragraphs.should be_a_kind_of(String)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should return text with 1 or more character" do
|
10
|
-
|
10
|
+
Forgery::LoremIpsum.paragraphs.size.should >= 1
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should default to returning 2 paragraphs separated by \\n\\n" do
|
14
|
-
|
14
|
+
Forgery::LoremIpsum.paragraphs.split("\n\n").size.should == 2
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should default to returning 3 sentences per paragraph" do
|
18
|
-
paragraphs =
|
18
|
+
paragraphs = Forgery::LoremIpsum.paragraphs.split("\n\n")
|
19
19
|
paragraphs.each do |paragraph|
|
20
20
|
paragraph.scan(".").size.should == 3
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should wrap paragraphs in html paragraph tags when the :html option is true" do
|
25
|
-
paragraphs =
|
25
|
+
paragraphs = Forgery::LoremIpsum.paragraphs(2, :html => true).split("\n\n")
|
26
26
|
paragraphs.each do |paragraph|
|
27
27
|
paragraph.should match(/<p>.+?<\/p>/)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should wrap paragraphs in specified wrapping text" do
|
32
|
-
paragraphs =
|
32
|
+
paragraphs = Forgery::LoremIpsum.paragraphs(2, :wrap => {:start => "foo", :end => "bar"}).split("\n\n")
|
33
33
|
paragraphs.each do |paragraph|
|
34
34
|
paragraph.should match(/foo.+bar/)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should separate paragraphs with the specified string" do
|
39
|
-
|
39
|
+
Forgery::LoremIpsum.paragraphs(2, :separator => "foo").split("foo").size.should == 2
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
describe ".paragraph" do
|
44
44
|
it "should return text" do
|
45
|
-
|
45
|
+
Forgery::LoremIpsum.paragraph.should be_a_kind_of(String)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should return text with 1 or more character" do
|
49
|
-
|
49
|
+
Forgery::LoremIpsum.paragraph.size.should >= 1
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should return a single paragraph" do
|
53
|
-
|
53
|
+
Forgery::LoremIpsum.paragraph.scan("\n\n").size.should == 0
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
describe ".sentences" do
|
58
58
|
it "should return text" do
|
59
|
-
|
59
|
+
Forgery::LoremIpsum.sentences.should be_a_kind_of(String)
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should return text with 1 or more character" do
|
63
|
-
|
63
|
+
Forgery::LoremIpsum.sentences.size.should >= 1
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should return two sentences by default" do
|
67
|
-
|
67
|
+
Forgery::LoremIpsum.sentences.scan(".").size.should == 2
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should return as many sentences as you specify" do
|
71
|
-
|
71
|
+
Forgery::LoremIpsum.sentences(4).scan(".").size.should == 4
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
describe ".sentence" do
|
76
76
|
it "should return text" do
|
77
|
-
|
77
|
+
Forgery::LoremIpsum.sentence.should be_a_kind_of(String)
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should return text with 1 or more character" do
|
81
|
-
|
81
|
+
Forgery::LoremIpsum.sentence.size.should >= 1
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should return a single sentence" do
|
85
|
-
|
85
|
+
Forgery::LoremIpsum.sentence.scan(".").size.should == 1
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
describe ".words" do
|
90
90
|
it "should return text" do
|
91
|
-
|
91
|
+
Forgery::LoremIpsum.words.should be_a_kind_of(String)
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should return text with 1 or more character" do
|
95
|
-
|
95
|
+
Forgery::LoremIpsum.words.size.should >= 1
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
99
|
describe ".word" do
|
100
100
|
it "should return text" do
|
101
|
-
|
101
|
+
Forgery::LoremIpsum.word.should be_a_kind_of(String)
|
102
102
|
end
|
103
103
|
|
104
104
|
it "should return text with 1 or more character" do
|
105
|
-
|
105
|
+
Forgery::LoremIpsum.word.size.should >= 1
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
109
|
describe ".characters" do
|
110
110
|
it "should return text" do
|
111
|
-
|
111
|
+
Forgery::LoremIpsum.characters.should be_a_kind_of(String)
|
112
112
|
end
|
113
113
|
|
114
114
|
it "should return text with 1 or more character" do
|
115
|
-
|
115
|
+
Forgery::LoremIpsum.characters.size.should >= 1
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
119
|
describe ".character" do
|
120
120
|
it "should return text" do
|
121
|
-
|
121
|
+
Forgery::LoremIpsum.character.should be_a_kind_of(String)
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should return text with 1 or more character" do
|
125
|
-
|
125
|
+
Forgery::LoremIpsum.character.size.should >= 1
|
126
126
|
end
|
127
127
|
end
|
128
128
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Forgery::Personal do
|
4
4
|
describe '.gender' do
|
5
5
|
it 'should return male or female' do
|
6
|
-
Forgery.dictionaries[:genders].should include(
|
6
|
+
Forgery.dictionaries[:genders].should include(Forgery::Personal.gender)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '.shirt_size' do
|
11
11
|
it 'should return a sane size' do
|
12
|
-
Forgery.dictionaries[:shirt_sizes].should include(
|
12
|
+
Forgery.dictionaries[:shirt_sizes].should include(Forgery::Personal.shirt_size)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|