sevenwire-forgery 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/README.markdown +81 -0
  2. data/VERSION.yml +4 -0
  3. data/generators/forgery/USAGE +6 -0
  4. data/generators/forgery/forgery_generator.rb +12 -0
  5. data/lib/dictionaries/cities +478 -0
  6. data/lib/dictionaries/colors +19 -0
  7. data/lib/dictionaries/company_names +400 -0
  8. data/lib/dictionaries/countries +249 -0
  9. data/lib/dictionaries/female_first_names +100 -0
  10. data/lib/dictionaries/frequencies +8 -0
  11. data/lib/dictionaries/genders +2 -0
  12. data/lib/dictionaries/languages +97 -0
  13. data/lib/dictionaries/last_names +250 -0
  14. data/lib/dictionaries/lorem_ipsum +151 -0
  15. data/lib/dictionaries/male_first_names +100 -0
  16. data/lib/dictionaries/name_suffixes +5 -0
  17. data/lib/dictionaries/name_titles +6 -0
  18. data/lib/dictionaries/races +93 -0
  19. data/lib/dictionaries/shirt_sizes +7 -0
  20. data/lib/dictionaries/state_abbrevs +50 -0
  21. data/lib/dictionaries/states +50 -0
  22. data/lib/dictionaries/street_suffixes +21 -0
  23. data/lib/dictionaries/streets +500 -0
  24. data/lib/dictionaries/top_level_domains +9 -0
  25. data/lib/extensions/array.rb +11 -0
  26. data/lib/extensions/hash.rb +12 -0
  27. data/lib/extensions/range.rb +9 -0
  28. data/lib/extensions/string.rb +48 -0
  29. data/lib/forgeries/address_forgery.rb +117 -0
  30. data/lib/forgeries/basic_forgery.rb +73 -0
  31. data/lib/forgeries/internet_forgery.rb +19 -0
  32. data/lib/forgeries/lorem_ipsum_forgery.rb +107 -0
  33. data/lib/forgeries/monetary_forgery.rb +13 -0
  34. data/lib/forgeries/name_forgery.rb +36 -0
  35. data/lib/forgeries/personal_forgery.rb +23 -0
  36. data/lib/forgery.rb +82 -0
  37. data/lib/formats/phone +1 -0
  38. data/lib/formats/street_number +5 -0
  39. data/lib/formats/zip +2 -0
  40. data/spec/extensions/array_spec.rb +25 -0
  41. data/spec/extensions/range_spec.rb +17 -0
  42. data/spec/extensions/string_spec.rb +29 -0
  43. data/spec/forgeries/address_forgery_spec.rb +69 -0
  44. data/spec/forgeries/basic_forgery_spec.rb +175 -0
  45. data/spec/forgeries/internet_forgery_spec.rb +30 -0
  46. data/spec/forgeries/lorem_ipsum_forgery_spec.rb +128 -0
  47. data/spec/forgeries/monetary_forgery_spec.rb +4 -0
  48. data/spec/forgeries/name_forgery_spec.rb +4 -0
  49. data/spec/forgeries/personal_forgery_spec.rb +15 -0
  50. data/spec/forgery_spec.rb +36 -0
  51. data/spec/spec_helper.rb +31 -0
  52. metadata +110 -0
@@ -0,0 +1,175 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe BasicForgery do
4
+ describe ".password" do
5
+ it "should only uppercase characters" do
6
+ BasicForgery.password(:allow_lower => false,
7
+ :allow_upper => true,
8
+ :allow_numeric => false,
9
+ :allow_special => false).should only_contain(BasicForgery::UPPER_ALPHA)
10
+ end
11
+
12
+ it "should only contain lowercase characters" do
13
+ BasicForgery.password(:allow_lower => true,
14
+ :allow_upper => false,
15
+ :allow_numeric => false,
16
+ :allow_special => false).should only_contain(BasicForgery::LOWER_ALPHA)
17
+ end
18
+
19
+ it "should only contain numeric characters" do
20
+ BasicForgery.password(:allow_lower => false,
21
+ :allow_upper => false,
22
+ :allow_numeric => true,
23
+ :allow_special => false).should only_contain(BasicForgery::NUMERIC)
24
+ end
25
+
26
+ it "should only contain special characters" do
27
+ BasicForgery.password(:allow_lower => false,
28
+ :allow_upper => false,
29
+ :allow_numeric => false,
30
+ :allow_special => true).should only_contain(BasicForgery::SPECIAL_CHARACTERS)
31
+ end
32
+
33
+ it "should only contain lower and uppercase characters" do
34
+ BasicForgery.password(:allow_lower => true,
35
+ :allow_upper => true,
36
+ :allow_numeric => false,
37
+ :allow_special => false).should only_contain(BasicForgery::LOWER_ALPHA,
38
+ BasicForgery::UPPER_ALPHA)
39
+ end
40
+
41
+ it "should only contain numeric and special characters" do
42
+ BasicForgery.password(:allow_lower => false,
43
+ :allow_upper => false,
44
+ :allow_numeric => true,
45
+ :allow_special => true).should only_contain(BasicForgery::NUMERIC,
46
+ BasicForgery::SPECIAL_CHARACTERS)
47
+ end
48
+
49
+ it "should contain any of the defined characters" do
50
+ BasicForgery.password(:allow_lower => true,
51
+ :allow_upper => true,
52
+ :allow_numeric => true,
53
+ :allow_special => true).should only_contain(BasicForgery::NUMERIC,
54
+ BasicForgery::SPECIAL_CHARACTERS,
55
+ BasicForgery::LOWER_ALPHA,
56
+ BasicForgery::UPPER_ALPHA)
57
+ end
58
+ end
59
+
60
+ describe ".encrypt" do
61
+ it "should encrypt to hex digits" do
62
+ BasicForgery.encrypt("something").should only_contain(BasicForgery::HEX_DIGITS)
63
+ end
64
+
65
+ it "should encrypt different words to different output" do
66
+ BasicForgery.encrypt("foo").should_not == BasicForgery.encrypt("bar")
67
+ end
68
+
69
+ it "should allow a salt that changes the output" do
70
+ BasicForgery.encrypt("foo", "baz").should_not == BasicForgery.encrypt("foo", "bar")
71
+ end
72
+
73
+ it "should have the same output when encrypting twice" do
74
+ BasicForgery.encrypt("foo", "bar").should == BasicForgery.encrypt("foo", "bar")
75
+ end
76
+ end
77
+
78
+ describe ".boolean" do
79
+ it "should return true or false" do
80
+ [true, false].should include(BasicForgery.boolean)
81
+ end
82
+ end
83
+
84
+ describe ".color" do
85
+ it "should return a random color" do
86
+ BasicForgery::COLORS.should include(BasicForgery.color)
87
+ end
88
+ end
89
+
90
+ describe ".hex_color" do
91
+ it "should return a 6-character hex color" do
92
+ BasicForgery.hex_color.should match(/#(#{BasicForgery::HEX_DIGITS.join('|')}){6}/)
93
+ end
94
+ end
95
+
96
+ describe ".short_hex_color" do
97
+ it "should return a 3-character hex color" do
98
+ BasicForgery.short_hex_color.should match(/#(#{BasicForgery::HEX_DIGITS.join('|')}){3}/)
99
+ end
100
+ end
101
+
102
+ describe ".number" do
103
+ it "should return a number >= the at_least option" do
104
+ BasicForgery.number(:at_least => 2).should >= 2
105
+ end
106
+
107
+ it "should return a number <= the at_most option" do
108
+ BasicForgery.number(:at_most => 12).should <= 12
109
+ end
110
+ end
111
+
112
+ describe ".text" do
113
+ it "should return text whose length is >= the at_least option" do
114
+ BasicForgery.text(:at_least => 5).size.should >= 5
115
+ end
116
+
117
+ it "should return text whose length is <= the at_most option" do
118
+ BasicForgery.text(:at_least => 15).size.should <= 15
119
+ end
120
+
121
+ it "should only uppercase characters" do
122
+ BasicForgery.text(:allow_lower => false,
123
+ :allow_upper => true,
124
+ :allow_numeric => false,
125
+ :allow_special => false).should only_contain(BasicForgery::UPPER_ALPHA)
126
+ end
127
+
128
+ it "should only contain lowercase characters" do
129
+ BasicForgery.text(:allow_lower => true,
130
+ :allow_upper => false,
131
+ :allow_numeric => false,
132
+ :allow_special => false).should only_contain(BasicForgery::LOWER_ALPHA)
133
+ end
134
+
135
+ it "should only contain numeric characters" do
136
+ BasicForgery.text(:allow_lower => false,
137
+ :allow_upper => false,
138
+ :allow_numeric => true,
139
+ :allow_special => false).should only_contain(BasicForgery::NUMERIC)
140
+ end
141
+
142
+ it "should only contain special characters" do
143
+ BasicForgery.text(:allow_lower => false,
144
+ :allow_upper => false,
145
+ :allow_numeric => false,
146
+ :allow_special => true).should only_contain(BasicForgery::SPECIAL_CHARACTERS)
147
+ end
148
+
149
+ it "should only contain lower and uppercase characters" do
150
+ BasicForgery.text(:allow_lower => true,
151
+ :allow_upper => true,
152
+ :allow_numeric => false,
153
+ :allow_special => false).should only_contain(BasicForgery::LOWER_ALPHA,
154
+ BasicForgery::UPPER_ALPHA)
155
+ end
156
+
157
+ it "should only contain numeric and special characters" do
158
+ BasicForgery.text(:allow_lower => false,
159
+ :allow_upper => false,
160
+ :allow_numeric => true,
161
+ :allow_special => true).should only_contain(BasicForgery::NUMERIC,
162
+ BasicForgery::SPECIAL_CHARACTERS)
163
+ end
164
+
165
+ it "should contain any of the defined characters" do
166
+ BasicForgery.text(:allow_lower => true,
167
+ :allow_upper => true,
168
+ :allow_numeric => true,
169
+ :allow_special => true).should only_contain(BasicForgery::NUMERIC,
170
+ BasicForgery::SPECIAL_CHARACTERS,
171
+ BasicForgery::LOWER_ALPHA,
172
+ BasicForgery::UPPER_ALPHA)
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe InternetForgery do
4
+ describe ".user_name" do
5
+ it "should return a username that is lowercase" do
6
+ InternetForgery.user_name.should only_contain(BasicForgery::LOWER_ALPHA)
7
+ end
8
+ end
9
+
10
+ it "should return a top level domain" do
11
+ InternetForgery::TOP_LEVEL_DOMAINS.should include(InternetForgery.top_level_domain)
12
+ end
13
+
14
+ describe ".domain_name" do
15
+ it "should return a domain name that contains a lowercase company name" do
16
+ downcase_company_name = InternetForgery.domain_name.split('.').first
17
+ InternetForgery::COMPANY_NAMES.any?{ |cn| cn =~ /#{downcase_company_name}/i }
18
+ end
19
+
20
+ it "should return a domain name that contains a top level domain" do
21
+ InternetForgery::TOP_LEVEL_DOMAINS.should include(InternetForgery.domain_name.split('.').last)
22
+ end
23
+ end
24
+
25
+ describe ".email_address" do
26
+ it "should match the email format" do
27
+ InternetForgery.email_address.should match(/.+@.+\.(#{InternetForgery::TOP_LEVEL_DOMAINS.join("|")})/)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,128 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe LoremIpsumForgery do
4
+ describe ".paragraphs" do
5
+ it "should return text" do
6
+ LoremIpsumForgery.paragraphs.should be_a_kind_of(String)
7
+ end
8
+
9
+ it "should return text with 1 or more character" do
10
+ LoremIpsumForgery.paragraphs.size.should >= 1
11
+ end
12
+
13
+ it "should default to returning 2 paragraphs separated by \\n\\n" do
14
+ LoremIpsumForgery.paragraphs.split("\n\n").size.should == 2
15
+ end
16
+
17
+ it "should default to returning 3 sentences per paragraph" do
18
+ paragraphs = LoremIpsumForgery.paragraphs.split("\n\n")
19
+ paragraphs.each do |paragraph|
20
+ paragraph.scan(".").size.should == 3
21
+ end
22
+ end
23
+
24
+ it "should wrap paragraphs in html paragraph tags when the :html option is true" do
25
+ paragraphs = LoremIpsumForgery.paragraphs(2, :html => true).split("\n\n")
26
+ paragraphs.each do |paragraph|
27
+ paragraph.should match(/<p>.+?<\/p>/)
28
+ end
29
+ end
30
+
31
+ it "should wrap paragraphs in specified wrapping text" do
32
+ paragraphs = LoremIpsumForgery.paragraphs(2, :wrap => {:start => "foo", :end => "bar"}).split("\n\n")
33
+ paragraphs.each do |paragraph|
34
+ paragraph.should match(/foo.+bar/)
35
+ end
36
+ end
37
+
38
+ it "should separate paragraphs with the specified string" do
39
+ LoremIpsumForgery.paragraphs(2, :separator => "foo").split("foo").size.should == 2
40
+ end
41
+ end
42
+
43
+ describe ".paragraph" do
44
+ it "should return text" do
45
+ LoremIpsumForgery.paragraph.should be_a_kind_of(String)
46
+ end
47
+
48
+ it "should return text with 1 or more character" do
49
+ LoremIpsumForgery.paragraph.size.should >= 1
50
+ end
51
+
52
+ it "should return a single paragraph" do
53
+ LoremIpsumForgery.paragraph.scan("\n\n").size.should == 0
54
+ end
55
+ end
56
+
57
+ describe ".sentences" do
58
+ it "should return text" do
59
+ LoremIpsumForgery.sentences.should be_a_kind_of(String)
60
+ end
61
+
62
+ it "should return text with 1 or more character" do
63
+ LoremIpsumForgery.sentences.size.should >= 1
64
+ end
65
+
66
+ it "should return two sentences by default" do
67
+ LoremIpsumForgery.sentences.scan(".").size.should == 2
68
+ end
69
+
70
+ it "should return as many sentences as you specify" do
71
+ LoremIpsumForgery.sentences(4).scan(".").size.should == 4
72
+ end
73
+ end
74
+
75
+ describe ".sentence" do
76
+ it "should return text" do
77
+ LoremIpsumForgery.sentence.should be_a_kind_of(String)
78
+ end
79
+
80
+ it "should return text with 1 or more character" do
81
+ LoremIpsumForgery.sentence.size.should >= 1
82
+ end
83
+
84
+ it "should return a single sentence" do
85
+ LoremIpsumForgery.sentence.scan(".").size.should == 1
86
+ end
87
+ end
88
+
89
+ describe ".words" do
90
+ it "should return text" do
91
+ LoremIpsumForgery.words.should be_a_kind_of(String)
92
+ end
93
+
94
+ it "should return text with 1 or more character" do
95
+ LoremIpsumForgery.words.size.should >= 1
96
+ end
97
+ end
98
+
99
+ describe ".word" do
100
+ it "should return text" do
101
+ LoremIpsumForgery.word.should be_a_kind_of(String)
102
+ end
103
+
104
+ it "should return text with 1 or more character" do
105
+ LoremIpsumForgery.word.size.should >= 1
106
+ end
107
+ end
108
+
109
+ describe ".characters" do
110
+ it "should return text" do
111
+ LoremIpsumForgery.characters.should be_a_kind_of(String)
112
+ end
113
+
114
+ it "should return text with 1 or more character" do
115
+ LoremIpsumForgery.characters.size.should >= 1
116
+ end
117
+ end
118
+
119
+ describe ".character" do
120
+ it "should return text" do
121
+ LoremIpsumForgery.character.should be_a_kind_of(String)
122
+ end
123
+
124
+ it "should return text with 1 or more character" do
125
+ LoremIpsumForgery.character.size.should >= 1
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe MonetaryForgery do
4
+ end
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe NameForgery do
4
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe PersonalForgery do
4
+ describe '.gender' do
5
+ it 'should return male or female' do
6
+ PersonalForgery::GENDERS.should include(PersonalForgery.gender)
7
+ end
8
+ end
9
+
10
+ describe '.shirt_size' do
11
+ it 'should return a sane size' do
12
+ PersonalForgery::SHIRT_SIZES.should include(PersonalForgery.shirt_size)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Forgery do
4
+ it "should define constants for defined dictionaries" do
5
+ Forgery.dictionaries :cities, :colors, :countries
6
+ Forgery::CITIES.should be_is_a(Array)
7
+ Forgery::COLORS.should be_is_a(Array)
8
+ Forgery::COUNTRIES.should be_is_a(Array)
9
+ end
10
+
11
+ it "should define constants for defined formats" do
12
+ Forgery.formats :phone, :street_number, :zip
13
+ Forgery::PHONE_FORMATS.should be_is_a(Array)
14
+ Forgery::STREET_NUMBER_FORMATS.should be_is_a(Array)
15
+ Forgery::ZIP_FORMATS.should be_is_a(Array)
16
+ end
17
+
18
+ it "should accept a symbol and return the appropriate forgery class" do
19
+ Forgery(:address).should == AddressForgery
20
+ Forgery(:basic).should == BasicForgery
21
+ Forgery(:internet).should == InternetForgery
22
+ end
23
+
24
+ it "should accept two symbols, finding the right class and calling the appropriate method" do
25
+ AddressForgery.should_receive(:street_name)
26
+ Forgery(:address, :street_name)
27
+
28
+ NameForgery.should_receive(:full_name)
29
+ Forgery(:name, :full_name)
30
+ end
31
+
32
+ it "should accept two symbols and arguments, passing them along to the appropriate method" do
33
+ LoremIpsumForgery.should_receive(:text).with(:sentences, 2)
34
+ Forgery(:lorem_ipsum, :text, :sentences, 2)
35
+ end
36
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec'
2
+ require File.dirname(__FILE__) + '/../init'
3
+ Spec::Runner.configure do |config|
4
+
5
+ end
6
+
7
+ class OnlyContain
8
+ def initialize(*expected)
9
+ @expected = [expected].flatten
10
+ end
11
+
12
+ def matches?(target)
13
+ @target = target.dup
14
+ @expected.each do |e|
15
+ target.gsub!(e, '')
16
+ end
17
+ target.size == 0
18
+ end
19
+
20
+ def failure_message
21
+ "expected #{@target} to only contain #{@expected.join(', ')}"
22
+ end
23
+
24
+ def failure_message
25
+ "expected #{@target} to not only contain #{@expected.join(', ')}"
26
+ end
27
+ end
28
+
29
+ def only_contain(*expected)
30
+ OnlyContain.new(expected)
31
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sevenwire-forgery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Sutton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-15 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: TODO
17
+ email: nate@sevenwire.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README.markdown
26
+ - VERSION.yml
27
+ - generators/forgery
28
+ - generators/forgery/forgery_generator.rb
29
+ - generators/forgery/USAGE
30
+ - lib/dictionaries
31
+ - lib/dictionaries/cities
32
+ - lib/dictionaries/colors
33
+ - lib/dictionaries/company_names
34
+ - lib/dictionaries/countries
35
+ - lib/dictionaries/female_first_names
36
+ - lib/dictionaries/frequencies
37
+ - lib/dictionaries/genders
38
+ - lib/dictionaries/languages
39
+ - lib/dictionaries/last_names
40
+ - lib/dictionaries/lorem_ipsum
41
+ - lib/dictionaries/male_first_names
42
+ - lib/dictionaries/name_suffixes
43
+ - lib/dictionaries/name_titles
44
+ - lib/dictionaries/races
45
+ - lib/dictionaries/shirt_sizes
46
+ - lib/dictionaries/state_abbrevs
47
+ - lib/dictionaries/states
48
+ - lib/dictionaries/street_suffixes
49
+ - lib/dictionaries/streets
50
+ - lib/dictionaries/top_level_domains
51
+ - lib/extensions
52
+ - lib/extensions/array.rb
53
+ - lib/extensions/hash.rb
54
+ - lib/extensions/range.rb
55
+ - lib/extensions/string.rb
56
+ - lib/forgeries
57
+ - lib/forgeries/address_forgery.rb
58
+ - lib/forgeries/basic_forgery.rb
59
+ - lib/forgeries/internet_forgery.rb
60
+ - lib/forgeries/lorem_ipsum_forgery.rb
61
+ - lib/forgeries/monetary_forgery.rb
62
+ - lib/forgeries/name_forgery.rb
63
+ - lib/forgeries/personal_forgery.rb
64
+ - lib/forgery.rb
65
+ - lib/formats
66
+ - lib/formats/phone
67
+ - lib/formats/street_number
68
+ - lib/formats/zip
69
+ - spec/extensions
70
+ - spec/extensions/array_spec.rb
71
+ - spec/extensions/range_spec.rb
72
+ - spec/extensions/string_spec.rb
73
+ - spec/forgeries
74
+ - spec/forgeries/address_forgery_spec.rb
75
+ - spec/forgeries/basic_forgery_spec.rb
76
+ - spec/forgeries/internet_forgery_spec.rb
77
+ - spec/forgeries/lorem_ipsum_forgery_spec.rb
78
+ - spec/forgeries/monetary_forgery_spec.rb
79
+ - spec/forgeries/name_forgery_spec.rb
80
+ - spec/forgeries/personal_forgery_spec.rb
81
+ - spec/forgery_spec.rb
82
+ - spec/spec_helper.rb
83
+ has_rdoc: false
84
+ homepage: http://github.com/sevenwire/forgery
85
+ post_install_message:
86
+ rdoc_options: []
87
+
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ version:
102
+ requirements: []
103
+
104
+ rubyforge_project:
105
+ rubygems_version: 1.2.0
106
+ signing_key:
107
+ specification_version: 2
108
+ summary: TODO
109
+ test_files: []
110
+