forgery 0.5.0 → 0.6.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.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.travis.yml +13 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +27 -0
- data/LICENSE +1 -1
- data/README.markdown +9 -5
- data/Rakefile +9 -1
- data/forgery.gemspec +23 -0
- data/lib/forgery/dictionaries/company_names +0 -1
- data/lib/forgery/dictionaries/currency_descriptions +2 -2
- data/lib/forgery/file_reader.rb +1 -0
- data/lib/forgery/forgery/geo.rb +54 -0
- data/lib/forgery/forgery/internet.rb +7 -0
- data/lib/forgery/forgery/russian_tax.rb +57 -0
- data/lib/forgery/version.rb +1 -1
- data/spec/data/dictionaries/code_names +6 -0
- data/spec/data/dictionaries/female_first_names +1 -0
- data/spec/data/documents/mock_web_page.html +17 -0
- data/spec/data/documents/mock_xml_doc.xml +5 -0
- data/spec/dictionaries_spec.rb +35 -0
- data/spec/extensions/array_spec.rb +25 -0
- data/spec/extensions/range_spec.rb +31 -0
- data/spec/extensions/string_spec.rb +29 -0
- data/spec/file_reader_spec.rb +32 -0
- data/spec/forgery/address_spec.rb +84 -0
- data/spec/forgery/basic_spec.rb +179 -0
- data/spec/forgery/credit_card_spec.rb +68 -0
- data/spec/forgery/currency_spec.rb +15 -0
- data/spec/forgery/date_spec.rb +134 -0
- data/spec/forgery/internet_spec.rb +62 -0
- data/spec/forgery/lorem_ipsum_spec.rb +132 -0
- data/spec/forgery/monetary_spec.rb +14 -0
- data/spec/forgery/name_spec.rb +11 -0
- data/spec/forgery/personal_spec.rb +15 -0
- data/spec/forgery/russian_tax_spec.rb +81 -0
- data/spec/forgery/time_spec.rb +7 -0
- data/spec/forgery_spec.rb +63 -0
- data/spec/formats_spec.rb +35 -0
- data/spec/spec_helper.rb +39 -0
- metadata +101 -64
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9756be4e19ec2f587a22381db7f90398dc1d203a
|
4
|
+
data.tar.gz: 024a6316301e71afafd6eb948aac37992ba168f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a0114bc3393c3a8790ce074e65c4afb66a60406f4fd60df64c55d0151c3fbbf452e52db20d27263e2386b7d9410c67f29c8977b53ee76154b28343681c26185
|
7
|
+
data.tar.gz: 7c882a4f0d9f699ddf7d23244fecaef25860379a605bc8d0be30ad70eb4d1e1fe84b9d0f0ddeea55c6dec7be0c6e31272abbe131ec47163c0ee8b9410126a8de
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
forgery (0.6.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
rake (10.1.0)
|
11
|
+
rspec (2.6.0)
|
12
|
+
rspec-core (~> 2.6.0)
|
13
|
+
rspec-expectations (~> 2.6.0)
|
14
|
+
rspec-mocks (~> 2.6.0)
|
15
|
+
rspec-core (2.6.4)
|
16
|
+
rspec-expectations (2.6.0)
|
17
|
+
diff-lcs (~> 1.1.2)
|
18
|
+
rspec-mocks (2.6.0)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
bundler (~> 1.3)
|
25
|
+
forgery!
|
26
|
+
rake
|
27
|
+
rspec
|
data/LICENSE
CHANGED
data/README.markdown
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
Forgery
|
2
2
|
=======
|
3
3
|
|
4
|
+
[](https://travis-ci.org/sevenwire/forgery)
|
5
|
+
[](https://codeclimate.com/github/sevenwire/forgery)
|
6
|
+
|
7
|
+
|
4
8
|
**A Problem**:
|
5
9
|
It's harder than *absolutely easy* to make meaningful, simple, data for testing and development.
|
6
10
|
|
@@ -32,7 +36,7 @@ Forgery(:monetary).formatted_money :min => 100, :max => 1000
|
|
32
36
|
#=> "$923.36"
|
33
37
|
```
|
34
38
|
|
35
|
-
And many many
|
39
|
+
And many many more!
|
36
40
|
|
37
41
|
Alternatively you can write it like this:
|
38
42
|
|
@@ -43,7 +47,7 @@ Forgery::Personal.shirt_size
|
|
43
47
|
```
|
44
48
|
|
45
49
|
In addition, you can always write your own dictionaries and formats, overriding the ones in the gem.
|
46
|
-
Fully explained
|
50
|
+
Fully explained here.
|
47
51
|
|
48
52
|
|
49
53
|
Installing
|
@@ -59,7 +63,7 @@ $ gem install forgery
|
|
59
63
|
|
60
64
|
This will add it to your gem library, just like any normal gem.
|
61
65
|
You can then use it like any normal gem library.
|
62
|
-
See
|
66
|
+
See examples for more.
|
63
67
|
|
64
68
|
|
65
69
|
**Rails 3.x**
|
@@ -68,7 +72,7 @@ If you're using Rails 3.x you need to do a few extra things (that are probably r
|
|
68
72
|
First step is to add it to your `Rails.root/Gemfile`, we also suggest specifying the latest version (found on rubygems):
|
69
73
|
|
70
74
|
```ruby
|
71
|
-
gem 'forgery', '0.
|
75
|
+
gem 'forgery', '0.6.0'
|
72
76
|
```
|
73
77
|
|
74
78
|
Then you'll need to run `bundle install` to install and lock in your new gem.
|
@@ -159,4 +163,4 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
159
163
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
160
164
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
161
165
|
|
162
|
-
On that note, have fun!
|
166
|
+
On that note, have fun!
|
data/Rakefile
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
require 'rspec/core/rake_task'
|
3
3
|
|
4
|
+
task :default => :spec
|
5
|
+
|
4
6
|
Bundler::GemHelper.install_tasks
|
5
7
|
RSpec::Core::RakeTask.new
|
6
8
|
|
7
|
-
task :
|
9
|
+
task :console do
|
10
|
+
require 'irb'
|
11
|
+
require 'irb/completion'
|
12
|
+
require 'forgery'
|
13
|
+
ARGV.clear
|
14
|
+
IRB.start
|
15
|
+
end
|
data/forgery.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "forgery/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "forgery"
|
7
|
+
spec.version = Forgery::VERSION
|
8
|
+
spec.authors = ["Nathan Sutton", "Brandon Arbini", "Kamil Kieliszczyk"]
|
9
|
+
spec.email = ["nate@zencoder.com", "brandon@zencoder.com", "kamil@kieliszczyk.net"]
|
10
|
+
spec.homepage = "http://github.com/sevenwire/forgery"
|
11
|
+
spec.summary = "Easy and customizable generation of forged data."
|
12
|
+
spec.description = "Easy and customizable generation of forged data. Can be used as a gem or a rails plugin. Includes rails generators for creating your own forgeries."
|
13
|
+
|
14
|
+
spec.platform = Gem::Platform::RUBY
|
15
|
+
spec.required_rubygems_version = ">= 1.3.6"
|
16
|
+
spec.rubyforge_project = "forgery"
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.test_files = `git ls-files spec`.split($/)
|
20
|
+
spec.require_paths = %w(lib)
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
end
|
@@ -73,7 +73,7 @@ Palladium Ounces
|
|
73
73
|
Peru Nuevos Soles
|
74
74
|
Philippines Pesos
|
75
75
|
Platinum Ounces
|
76
|
-
|
76
|
+
Polish Zloty
|
77
77
|
Portugal Escudos
|
78
78
|
Qatar Riyals
|
79
79
|
Romania New Lei
|
@@ -103,4 +103,4 @@ United States Dollars
|
|
103
103
|
Venezuela Bolivares
|
104
104
|
Venezuela Bolivares Fuertes
|
105
105
|
Vietnam Dong
|
106
|
-
Zambia Kwacha
|
106
|
+
Zambia Kwacha
|
data/lib/forgery/file_reader.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Generates random geographic information.
|
2
|
+
class Forgery::Geo < Forgery
|
3
|
+
|
4
|
+
# Return a latitude in the range -90.0 to +90.0 as a float.
|
5
|
+
def self.latitude
|
6
|
+
rand * 180.0 - 90.0
|
7
|
+
end
|
8
|
+
|
9
|
+
# Return a latitude's degrees component in the range -180 to +180 as an integer.
|
10
|
+
def self.latitude_degrees
|
11
|
+
rand(360)-180
|
12
|
+
end
|
13
|
+
|
14
|
+
# Return a latitude's minutes component in the range 0 to 60 as an integer.
|
15
|
+
def self.latitude_minutes
|
16
|
+
rand(60)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Return a latitude's seconds component in the range 0 to 60 as an integer.
|
20
|
+
def self.latitude_seconds
|
21
|
+
rand(60)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Return a latitude's direction component, either "N" (north) or "S" (south)
|
25
|
+
def self.latitude_direction
|
26
|
+
['N','S'].sample
|
27
|
+
end
|
28
|
+
|
29
|
+
# Return a longitude in the range -180.0 to +180.0 as a float.
|
30
|
+
def self.longitude
|
31
|
+
rand * 360.0 - 180.0
|
32
|
+
end
|
33
|
+
|
34
|
+
# Return a longitude's degrees component in the range -180 to +180 as an integer.
|
35
|
+
def self.longitude_degrees
|
36
|
+
rand(360)-180
|
37
|
+
end
|
38
|
+
|
39
|
+
# Return a longitude's minutes component in the range 0 to 60 as an integer.
|
40
|
+
def self.longitude_minutes
|
41
|
+
rand(60)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Return a longitude's seconds component in the range 0 to 60 as an integer.
|
45
|
+
def self.longitude_seconds
|
46
|
+
rand(60)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Return a longitude's direction component, either "E" (east) or "W" (west)
|
50
|
+
def self.longitude_direction
|
51
|
+
["E","W"].sample
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'ipaddr'
|
2
|
+
|
1
3
|
class Forgery::Internet < Forgery
|
2
4
|
|
3
5
|
def self.user_name
|
@@ -28,4 +30,9 @@ class Forgery::Internet < Forgery
|
|
28
30
|
(1..4).map{rand(256)}.join('.')
|
29
31
|
end
|
30
32
|
|
33
|
+
# credit for this method from http://stackoverflow.com/a/2811349/793330
|
34
|
+
def self.ip_v6
|
35
|
+
IPAddr.new(rand(2**128),Socket::AF_INET6).to_s
|
36
|
+
end
|
37
|
+
|
31
38
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Generates various special numbers for Russian taxation system
|
2
|
+
# They have numbers for identification, for banks, for companies and entrepreneurs
|
3
|
+
class Forgery::RussianTax < Forgery
|
4
|
+
|
5
|
+
TYPES = Forgery::Extend([:person, :legal])
|
6
|
+
|
7
|
+
#bank identification
|
8
|
+
def self.bik
|
9
|
+
"04#{5.times.map { rand(9) + 1 }.join}#{rand(50) + 50}"
|
10
|
+
end
|
11
|
+
|
12
|
+
#bank account format pretty simple
|
13
|
+
def self.account_number
|
14
|
+
20.times.map { rand(9) + 1 }.join
|
15
|
+
end
|
16
|
+
|
17
|
+
#taxation id
|
18
|
+
def self.inn(options = {})
|
19
|
+
type = TYPES.include?(options[:type]) ? options[:type] : TYPES.random
|
20
|
+
send [type, :inn].join('_')
|
21
|
+
end
|
22
|
+
|
23
|
+
#government registration id
|
24
|
+
def self.ogrn(options = {})
|
25
|
+
type = TYPES.include?(options[:type]) ? options[:type] : TYPES.random
|
26
|
+
send [type, :ogrn].join('_')
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def self.person_inn
|
31
|
+
mask = [[7, 2, 4, 10, 3, 5, 9, 4, 6, 8], [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8]]
|
32
|
+
inn = 12.times.map { rand(9) + 1 }.join
|
33
|
+
inn[10] = ((0..(inn.length-3)).inject(0) {|crc, i| crc + inn[i].to_i*mask[0][i].to_i} % 11 % 10).to_s
|
34
|
+
inn[11] = ((0..(inn.length-2)).inject(0) {|crc, i| crc + inn[i].to_i*mask[1][i].to_i} % 11 % 10).to_s
|
35
|
+
inn
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.legal_inn
|
39
|
+
mask = [2, 4, 10, 3, 5, 9, 4, 6, 8]
|
40
|
+
inn = 10.times.map { rand(9) + 1 }.join
|
41
|
+
inn[9] = ((0..(inn.length-2)).inject(0) {|crc, i| crc + inn[i].to_i*mask[i].to_i} % 11 % 10).to_s
|
42
|
+
inn
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.person_ogrn
|
46
|
+
ogrn = 14.times.map { rand(9) + 1 }.join
|
47
|
+
ogrn += (ogrn.to_i%13%10).to_s
|
48
|
+
ogrn
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.legal_ogrn
|
52
|
+
ogrn = 12.times.map { rand(9) + 1 }.join
|
53
|
+
ogrn += (ogrn.to_i%11%10).to_s
|
54
|
+
ogrn
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/lib/forgery/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
Amber
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/html4/loose.dtd">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<title>Mock Web Page</title>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<h1>Title</h1>
|
9
|
+
<h2>Subtitle</h2>
|
10
|
+
<p>Paragraph.</p>
|
11
|
+
<ul id="list">
|
12
|
+
<li>uno</li>
|
13
|
+
<li>dos</li>
|
14
|
+
<li>tres</li>
|
15
|
+
</ul>
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Forgery::Dictionaries do
|
4
|
+
it "should check if the dictionary is loaded" do
|
5
|
+
dictionaries = Forgery::Dictionaries.new
|
6
|
+
|
7
|
+
dictionaries[:colors]
|
8
|
+
|
9
|
+
dictionaries.should be_loaded(:colors)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should load a dictionary when called by the key" do
|
13
|
+
dictionaries = Forgery::Dictionaries.new
|
14
|
+
|
15
|
+
dictionaries.reset!
|
16
|
+
|
17
|
+
dictionaries.should_not be_loaded(:colors)
|
18
|
+
|
19
|
+
dictionaries[:colors]
|
20
|
+
|
21
|
+
dictionaries.should be_loaded(:colors)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should clear the loaded dictionaries when calling reset!" do
|
25
|
+
dictionaries = Forgery::Dictionaries.new
|
26
|
+
|
27
|
+
dictionaries[:colors]
|
28
|
+
|
29
|
+
dictionaries.should be_loaded(:colors)
|
30
|
+
|
31
|
+
dictionaries.reset!
|
32
|
+
|
33
|
+
dictionaries.should_not be_loaded(:colors)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Array do
|
4
|
+
before do
|
5
|
+
@array = Forgery::Extend([0,1,2,3,4,5,6,7,8,9])
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should get a random item out of the array" do
|
9
|
+
10.times { @array.should include(@array.random) }
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return nil if the array is empty" do
|
13
|
+
Forgery::Extend([]).random.should be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return a random subset of the array" do
|
17
|
+
@array.random_subset(5).each do |i|
|
18
|
+
@array.should include(i)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return a random subset of the array that is 3 long" do
|
23
|
+
@array.random_subset(3).size.should == 3
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'timeout'
|
3
|
+
|
4
|
+
describe Range do
|
5
|
+
it "should get a random number out of the range" do
|
6
|
+
range = Forgery::Extend(0..9)
|
7
|
+
10.times { range.should include(range.random) }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should not take a long time when the range is huge" do
|
11
|
+
Timeout.timeout(1){Forgery::Extend(1234567890..12345678901234567890).random}.should_not raise_error(Timeout::Error)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return nil for a random number from a reverse range" do
|
15
|
+
10.times { Forgery::Extend(9..0).random.should be_nil }
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should get a random string our of the range" do
|
19
|
+
range = Forgery::Extend("a".."z")
|
20
|
+
10.times { range.should include(range.random) }
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return nil if the maximum is less than the minimum" do
|
24
|
+
Forgery::Extend("z".."a").random.should be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not return the maximum at excluded range" do
|
28
|
+
Kernel.should_receive(:rand).with(9).and_return(8)
|
29
|
+
Forgery::Extend(0...9).random.should_not be_equal 9
|
30
|
+
end
|
31
|
+
end
|