forgery 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.gitignore +3 -0
  2. data/LICENSE +20 -0
  3. data/README.markdown +13 -13
  4. data/Rakefile +50 -0
  5. data/VERSION.yml +3 -2
  6. data/forgery.gemspec +120 -0
  7. data/init.rb +1 -0
  8. data/lib/forgery.rb +14 -28
  9. data/lib/forgery/dictionaries.rb +24 -0
  10. data/lib/{dictionaries → forgery/dictionaries}/cities +0 -0
  11. data/lib/{dictionaries → forgery/dictionaries}/colors +0 -0
  12. data/lib/{dictionaries → forgery/dictionaries}/company_names +0 -0
  13. data/lib/{dictionaries → forgery/dictionaries}/countries +0 -0
  14. data/lib/{dictionaries → forgery/dictionaries}/female_first_names +0 -0
  15. data/lib/{dictionaries → forgery/dictionaries}/frequencies +0 -0
  16. data/lib/{dictionaries → forgery/dictionaries}/genders +0 -0
  17. data/lib/{dictionaries → forgery/dictionaries}/languages +0 -0
  18. data/lib/{dictionaries → forgery/dictionaries}/last_names +0 -0
  19. data/lib/{dictionaries → forgery/dictionaries}/lorem_ipsum +0 -0
  20. data/lib/{dictionaries → forgery/dictionaries}/male_first_names +0 -0
  21. data/lib/{dictionaries → forgery/dictionaries}/name_suffixes +0 -0
  22. data/lib/{dictionaries → forgery/dictionaries}/name_titles +0 -0
  23. data/lib/{dictionaries → forgery/dictionaries}/province_abbrevs +0 -0
  24. data/lib/{dictionaries → forgery/dictionaries}/provinces +0 -0
  25. data/lib/{dictionaries → forgery/dictionaries}/races +0 -0
  26. data/lib/{dictionaries → forgery/dictionaries}/shirt_sizes +0 -0
  27. data/lib/{dictionaries → forgery/dictionaries}/state_abbrevs +0 -0
  28. data/lib/{dictionaries → forgery/dictionaries}/states +0 -0
  29. data/lib/{dictionaries → forgery/dictionaries}/street_suffixes +0 -0
  30. data/lib/{dictionaries → forgery/dictionaries}/streets +0 -0
  31. data/lib/{dictionaries → forgery/dictionaries}/top_level_domains +0 -0
  32. data/lib/{extensions → forgery/extensions}/array.rb +0 -0
  33. data/lib/{extensions → forgery/extensions}/hash.rb +0 -0
  34. data/lib/{extensions → forgery/extensions}/range.rb +0 -0
  35. data/lib/{extensions → forgery/extensions}/string.rb +1 -0
  36. data/lib/forgery/file_reader.rb +69 -0
  37. data/lib/forgery/forgery.rb +23 -0
  38. data/lib/{forgeries/address_forgery.rb → forgery/forgery/address.rb} +27 -25
  39. data/lib/{forgeries/basic_forgery.rb → forgery/forgery/basic.rb} +41 -1
  40. data/lib/{forgeries/internet_forgery.rb → forgery/forgery/internet.rb} +4 -2
  41. data/lib/{forgeries/lorem_ipsum_forgery.rb → forgery/forgery/lorem_ipsum.rb} +1 -2
  42. data/lib/{forgeries/monetary_forgery.rb → forgery/forgery/monetary.rb} +3 -1
  43. data/lib/{forgeries/name_forgery.rb → forgery/forgery/name.rb} +2 -1
  44. data/lib/{forgeries/personal_forgery.rb → forgery/forgery/personal.rb} +2 -1
  45. data/lib/forgery/forgery_api.rb +9 -0
  46. data/lib/forgery/formats.rb +24 -0
  47. data/lib/{formats → forgery/formats}/phone +0 -0
  48. data/lib/{formats → forgery/formats}/street_number +0 -0
  49. data/lib/{formats → forgery/formats}/zip +0 -0
  50. data/spec/dictionaries_spec.rb +4 -4
  51. data/spec/file_reader_spec.rb +3 -3
  52. data/spec/{forgeries/address_forgery_spec.rb → forgery/address_spec.rb} +13 -13
  53. data/spec/{forgeries/basic_forgery_spec.rb → forgery/basic_spec.rb} +51 -51
  54. data/spec/{forgeries/internet_forgery_spec.rb → forgery/internet_spec.rb} +6 -6
  55. data/spec/{forgeries/lorem_ipsum_forgery_spec.rb → forgery/lorem_ipsum_spec.rb} +26 -26
  56. data/spec/{forgeries/monetary_forgery_spec.rb → forgery/monetary_spec.rb} +1 -1
  57. data/spec/{forgeries/name_forgery_spec.rb → forgery/name_spec.rb} +1 -1
  58. data/spec/{forgeries/personal_forgery_spec.rb → forgery/personal_spec.rb} +3 -3
  59. data/spec/forgery_spec.rb +33 -6
  60. data/spec/formats_spec.rb +4 -4
  61. metadata +78 -57
  62. data/lib/dictionaries.rb +0 -24
  63. data/lib/file_reader.rb +0 -53
  64. data/lib/formats.rb +0 -24
@@ -1,4 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'pathname'
2
3
 
3
4
  describe Forgery do
4
5
  it "should load a dictionary when it is requested" do
@@ -22,21 +23,47 @@ describe Forgery do
22
23
  end
23
24
 
24
25
  it "should accept a symbol and return the appropriate forgery class" do
25
- Forgery(:address).should == AddressForgery
26
- Forgery(:basic).should == BasicForgery
27
- Forgery(:internet).should == InternetForgery
26
+ Forgery(:address).should == Forgery::Address
27
+ Forgery(:basic).should == Forgery::Basic
28
+ Forgery(:internet).should == Forgery::Internet
28
29
  end
29
30
 
30
31
  it "should accept two symbols, finding the right class and calling the appropriate method" do
31
- AddressForgery.should_receive(:street_name)
32
+ Forgery::Address.should_receive(:street_name)
32
33
  Forgery(:address, :street_name)
33
34
 
34
- NameForgery.should_receive(:full_name)
35
+ Forgery::Name.should_receive(:full_name)
35
36
  Forgery(:name, :full_name)
36
37
  end
37
38
 
38
39
  it "should accept two symbols and arguments, passing them along to the appropriate method" do
39
- LoremIpsumForgery.should_receive(:text).with(:sentences, 2)
40
+ Forgery::LoremIpsum.should_receive(:text).with(:sentences, 2)
40
41
  Forgery(:lorem_ipsum, :text, :sentences, 2)
41
42
  end
43
+
44
+ it "should return the rails root path if RAILS_ROOT is defined" do
45
+ RAILS_ROOT = '/path/from/rails/root/const'
46
+ Forgery.rails_root.should == '/path/from/rails/root/const'
47
+ Object.instance_eval { remove_const(:RAILS_ROOT) }
48
+ end
49
+
50
+ it "should return the rails root path as a string if Rails.root is defined" do
51
+ Rails = Object.new
52
+ Rails.stub!(:root).and_return(Pathname.new('/path/from/rails/dot/root'))
53
+ Forgery.rails_root.should == '/path/from/rails/dot/root'
54
+ Object.instance_eval { remove_const(:Rails) }
55
+ end
56
+
57
+ it "should return nil when RAILS_ROOT and Rails.root are not defined" do
58
+ Forgery.rails_root.should be_nil
59
+ end
60
+
61
+ it "should not be a rails environment when there is not a rails_root" do
62
+ Forgery.rails?.should be_false
63
+ end
64
+
65
+ it "should be a rails environment when there is a rails_root" do
66
+ Forgery.stub!(:rails?).and_return(true)
67
+ Forgery.rails?.should be_true
68
+ end
42
69
  end
@@ -1,8 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- describe Formats do
3
+ describe Forgery::Formats do
4
4
  it "should check if the dictionary is loaded" do
5
- formats = Formats.new
5
+ formats = Forgery::Formats.new
6
6
 
7
7
  formats[:phone]
8
8
 
@@ -10,7 +10,7 @@ describe Formats do
10
10
  end
11
11
 
12
12
  it "should load a dictionary when called by the key" do
13
- formats = Formats.new
13
+ formats = Forgery::Formats.new
14
14
 
15
15
  formats.reset!
16
16
 
@@ -22,7 +22,7 @@ describe Formats do
22
22
  end
23
23
 
24
24
  it "should clear the loaded formats when calling reset!" do
25
- formats = Formats.new
25
+ formats = Forgery::Formats.new
26
26
 
27
27
  formats[:phone]
28
28
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forgery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Sutton
@@ -9,75 +9,83 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-07 00:00:00 +03:00
12
+ date: 2009-11-13 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: Forgery generates fake data from dictionaries, formats, and recipes. The plugin includes a generator providing directories to make your own forgeries.
16
+ 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.
17
17
  email: nate@sevenwire.com
18
18
  executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.markdown
24
25
  files:
26
+ - .gitignore
27
+ - LICENSE
25
28
  - README.markdown
29
+ - Rakefile
26
30
  - VERSION.yml
27
- - generators/forgery/forgery_generator.rb
31
+ - forgery.gemspec
28
32
  - generators/forgery/USAGE
29
- - lib/dictionaries/cities
30
- - lib/dictionaries/colors
31
- - lib/dictionaries/company_names
32
- - lib/dictionaries/countries
33
- - lib/dictionaries/female_first_names
34
- - lib/dictionaries/frequencies
35
- - lib/dictionaries/genders
36
- - lib/dictionaries/languages
37
- - lib/dictionaries/last_names
38
- - lib/dictionaries/lorem_ipsum
39
- - lib/dictionaries/male_first_names
40
- - lib/dictionaries/name_suffixes
41
- - lib/dictionaries/name_titles
42
- - lib/dictionaries/province_abbrevs
43
- - lib/dictionaries/provinces
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/dictionaries.rb
52
- - lib/extensions/array.rb
53
- - lib/extensions/hash.rb
54
- - lib/extensions/range.rb
55
- - lib/extensions/string.rb
56
- - lib/file_reader.rb
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
33
+ - generators/forgery/forgery_generator.rb
34
+ - init.rb
64
35
  - lib/forgery.rb
65
- - lib/formats/phone
66
- - lib/formats/street_number
67
- - lib/formats/zip
68
- - lib/formats.rb
36
+ - lib/forgery/dictionaries.rb
37
+ - lib/forgery/dictionaries/cities
38
+ - lib/forgery/dictionaries/colors
39
+ - lib/forgery/dictionaries/company_names
40
+ - lib/forgery/dictionaries/countries
41
+ - lib/forgery/dictionaries/female_first_names
42
+ - lib/forgery/dictionaries/frequencies
43
+ - lib/forgery/dictionaries/genders
44
+ - lib/forgery/dictionaries/languages
45
+ - lib/forgery/dictionaries/last_names
46
+ - lib/forgery/dictionaries/lorem_ipsum
47
+ - lib/forgery/dictionaries/male_first_names
48
+ - lib/forgery/dictionaries/name_suffixes
49
+ - lib/forgery/dictionaries/name_titles
50
+ - lib/forgery/dictionaries/province_abbrevs
51
+ - lib/forgery/dictionaries/provinces
52
+ - lib/forgery/dictionaries/races
53
+ - lib/forgery/dictionaries/shirt_sizes
54
+ - lib/forgery/dictionaries/state_abbrevs
55
+ - lib/forgery/dictionaries/states
56
+ - lib/forgery/dictionaries/street_suffixes
57
+ - lib/forgery/dictionaries/streets
58
+ - lib/forgery/dictionaries/top_level_domains
59
+ - lib/forgery/extensions/array.rb
60
+ - lib/forgery/extensions/hash.rb
61
+ - lib/forgery/extensions/range.rb
62
+ - lib/forgery/extensions/string.rb
63
+ - lib/forgery/file_reader.rb
64
+ - lib/forgery/forgery.rb
65
+ - lib/forgery/forgery/address.rb
66
+ - lib/forgery/forgery/basic.rb
67
+ - lib/forgery/forgery/internet.rb
68
+ - lib/forgery/forgery/lorem_ipsum.rb
69
+ - lib/forgery/forgery/monetary.rb
70
+ - lib/forgery/forgery/name.rb
71
+ - lib/forgery/forgery/personal.rb
72
+ - lib/forgery/forgery_api.rb
73
+ - lib/forgery/formats.rb
74
+ - lib/forgery/formats/phone
75
+ - lib/forgery/formats/street_number
76
+ - lib/forgery/formats/zip
69
77
  - spec/dictionaries_spec.rb
70
78
  - spec/extensions/array_spec.rb
71
79
  - spec/extensions/range_spec.rb
72
80
  - spec/extensions/string_spec.rb
73
81
  - spec/file_reader_spec.rb
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
82
+ - spec/forgery/address_spec.rb
83
+ - spec/forgery/basic_spec.rb
84
+ - spec/forgery/internet_spec.rb
85
+ - spec/forgery/lorem_ipsum_spec.rb
86
+ - spec/forgery/monetary_spec.rb
87
+ - spec/forgery/name_spec.rb
88
+ - spec/forgery/personal_spec.rb
81
89
  - spec/forgery_spec.rb
82
90
  - spec/formats_spec.rb
83
91
  - spec/spec_helper.rb
@@ -87,7 +95,6 @@ licenses: []
87
95
 
88
96
  post_install_message:
89
97
  rdoc_options:
90
- - --inline-source
91
98
  - --charset=UTF-8
92
99
  require_paths:
93
100
  - lib
@@ -108,7 +115,21 @@ requirements: []
108
115
  rubyforge_project:
109
116
  rubygems_version: 1.3.5
110
117
  signing_key:
111
- specification_version: 2
112
- summary: Forgery generates fake data from dictionaries, formats, and recipes. The plugin includes a generator providing directories to make your own forgeries.
113
- test_files: []
114
-
118
+ specification_version: 3
119
+ summary: Easy and customizable generation of forged data.
120
+ test_files:
121
+ - spec/dictionaries_spec.rb
122
+ - spec/extensions/array_spec.rb
123
+ - spec/extensions/range_spec.rb
124
+ - spec/extensions/string_spec.rb
125
+ - spec/file_reader_spec.rb
126
+ - spec/forgery/address_spec.rb
127
+ - spec/forgery/basic_spec.rb
128
+ - spec/forgery/internet_spec.rb
129
+ - spec/forgery/lorem_ipsum_spec.rb
130
+ - spec/forgery/monetary_spec.rb
131
+ - spec/forgery/name_spec.rb
132
+ - spec/forgery/personal_spec.rb
133
+ - spec/forgery_spec.rb
134
+ - spec/formats_spec.rb
135
+ - spec/spec_helper.rb
@@ -1,24 +0,0 @@
1
- class Dictionaries
2
-
3
- def initialize
4
- @dictionaries = {}
5
- end
6
-
7
- def [](key)
8
- symbolized_key = key.to_sym
9
- if loaded?(symbolized_key)
10
- @dictionaries[symbolized_key]
11
- else
12
- @dictionaries[symbolized_key] = FileReader.read_dictionary(symbolized_key)
13
- end
14
- end
15
-
16
- def loaded?(key)
17
- @dictionaries.has_key?(key.to_sym)
18
- end
19
-
20
- def reset!
21
- @dictionaries = {}
22
- end
23
-
24
- end
@@ -1,53 +0,0 @@
1
- class FileReader
2
-
3
- def self.read_dictionary(dictionary)
4
- read_file(path_to_dictionary(dictionary))
5
- end
6
-
7
- def self.read_format(format)
8
- read_file(path_to_format(format))
9
- end
10
-
11
- protected
12
-
13
- def self.read_file(file)
14
- lines = []
15
- IO.foreach(file) do |line|
16
- lines << line.chomp unless line.chomp == ''
17
- end
18
- lines
19
- end
20
-
21
- def self.path_to_format(format)
22
- if external_path_to_format(format) && File.exists?(external_path_to_format(format))
23
- external_path_to_format(format)
24
- else
25
- internal_path_to_format(format)
26
- end
27
- end
28
-
29
- def self.external_path_to_format(format)
30
- RAILS_ROOT + '/lib/forgery/formats/' + format.to_s if defined?(RAILS_ROOT)
31
- end
32
-
33
- def self.internal_path_to_format(format)
34
- File.dirname(__FILE__) + '/formats/' + format.to_s
35
- end
36
-
37
- def self.path_to_dictionary(dictionary)
38
- if external_path_to_dictionary(dictionary) && File.exists?(external_path_to_dictionary(dictionary))
39
- external_path_to_dictionary(dictionary)
40
- else
41
- internal_path_to_dictionary(dictionary)
42
- end
43
- end
44
-
45
- def self.external_path_to_dictionary(dictionary)
46
- RAILS_ROOT + '/lib/forgery/dictionaries/' + dictionary.to_s if defined?(RAILS_ROOT)
47
- end
48
-
49
- def self.internal_path_to_dictionary(dictionary)
50
- File.dirname(__FILE__) + '/dictionaries/' + dictionary.to_s
51
- end
52
-
53
- end
@@ -1,24 +0,0 @@
1
- class Formats
2
-
3
- def initialize
4
- @formats = {}
5
- end
6
-
7
- def [](key)
8
- symbolized_key = key.to_sym
9
- if @formats.has_key?(symbolized_key)
10
- @formats[symbolized_key]
11
- else
12
- @formats[symbolized_key] = FileReader.read_format(symbolized_key)
13
- end
14
- end
15
-
16
- def loaded?(key)
17
- @formats.has_key?(key.to_sym)
18
- end
19
-
20
- def reset!
21
- @formats = {}
22
- end
23
-
24
- end