rahoulb-object-factory 0.1.2 → 0.1.3
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/CHANGELOG +12 -2
- data/Rakefile +1 -1
- data/lib/object_factory.rb +13 -1
- data/object-factory.gemspec +3 -3
- data/spec/object_spec.rb +21 -0
- metadata +3 -4
data/CHANGELOG
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
-
= 0.1.
|
1
|
+
= Version 0.1.3 (2008-12-08)
|
2
|
+
|
3
|
+
Added generate_ip_address
|
4
|
+
|
5
|
+
= Version 0.1.2 (2008-12-08)
|
6
|
+
|
7
|
+
...
|
8
|
+
|
9
|
+
= Version 0.1.1 2008-11-24
|
2
10
|
|
3
11
|
Added when_creating_a and when_creating_an as short-cut methods
|
4
12
|
|
5
|
-
= 0.1.0
|
13
|
+
= Version 0.1.0 (2008-11-24)
|
14
|
+
|
15
|
+
Initial Release
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('object-factory', '0.1.
|
5
|
+
Echoe.new('object-factory', '0.1.3') do | config |
|
6
6
|
config.description = 'A simple object factory to help you build valid objects in your tests'
|
7
7
|
config.url = 'http://github.com/rahoub/object-factory'
|
8
8
|
config.author = 'Brightbox Systems Ltd'
|
data/lib/object_factory.rb
CHANGED
@@ -55,7 +55,8 @@ class Object
|
|
55
55
|
def when_creating_a klass, options = {}
|
56
56
|
need_to_generate_values_for klass, options[:auto_generate] unless options[:auto_generate].nil?
|
57
57
|
need_to_confirm_values_for klass, options[:auto_confirm] unless options[:auto_confirm].nil?
|
58
|
-
need_to_generate_email_addresses_for klass, options[:generate_email_address] unless options[:generate_email_address].nil?
|
58
|
+
need_to_generate_email_addresses_for klass, options[:generate_email_address] unless options[:generate_email_address].nil?
|
59
|
+
need_to_generate_ip_addresses_for klass, options[:generate_ip_address] unless options[:generate_ip_address].nil?
|
59
60
|
need_to_set_values_for klass, options[:set] unless options[:set].nil?
|
60
61
|
need_to_set_generators_for klass, options[:generate] unless options[:generate].nil?
|
61
62
|
end
|
@@ -122,6 +123,17 @@ class Object
|
|
122
123
|
end
|
123
124
|
end
|
124
125
|
|
126
|
+
def need_to_generate_ip_addresses_for klass, fields
|
127
|
+
fields = [fields] unless fields.respond_to?(:each)
|
128
|
+
fields.each do | field |
|
129
|
+
add_generator_for klass, field, lambda {
|
130
|
+
octs = []
|
131
|
+
4.times { octs << 1.random_numbers(:to => 255) }
|
132
|
+
octs.join(".")
|
133
|
+
}
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
125
137
|
def need_to_set_values_for klass, fields_and_values
|
126
138
|
fields_and_values.each do | field, value |
|
127
139
|
add_generator_for klass, field, lambda { value }
|
data/object-factory.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{object-factory}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Brightbox Systems Ltd"]
|
9
|
-
s.date = %q{2008-
|
9
|
+
s.date = %q{2008-12-08}
|
10
10
|
s.description = %q{A simple object factory to help you build valid objects in your tests}
|
11
11
|
s.email = %q{hello@brightbox.co.uk}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "lib/object_factory.rb", "README.rdoc", "tasks/rspec.rake"]
|
13
|
-
s.files = ["CHANGELOG", "init.rb", "lib/object_factory.rb", "Manifest", "
|
13
|
+
s.files = ["CHANGELOG", "init.rb", "lib/object_factory.rb", "Manifest", "object-factory.gemspec", "Rakefile", "README.rdoc", "spec/object_spec.rb", "spec/spec.opts", "tasks/rspec.rake"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://github.com/rahoub/object-factory}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Object-factory", "--main", "README.rdoc"]
|
data/spec/object_spec.rb
CHANGED
@@ -266,6 +266,27 @@ describe Object::Factory, "generating email addresses" do
|
|
266
266
|
end
|
267
267
|
end
|
268
268
|
|
269
|
+
describe Object::Factory, "generating ip addresses" do
|
270
|
+
before :each do
|
271
|
+
Object.factory.reset
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should generate a random ip address for a configured field" do
|
275
|
+
Object.factory.when_creating_a TestClass, :generate_ip_address => :field
|
276
|
+
|
277
|
+
@instance = Object.factory.create_a TestClass
|
278
|
+
@instance.field.should match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should generate a random ip address for multiple configured fields" do
|
282
|
+
Object.factory.when_creating_a TestClass, :generate_ip_address => [:field, :another_field]
|
283
|
+
|
284
|
+
@instance = Object.factory.create_a TestClass
|
285
|
+
@instance.field.should match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)
|
286
|
+
@instance.another_field.should match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
269
290
|
describe Object::Factory, "using lambdas to generate values" do
|
270
291
|
before :each do
|
271
292
|
Object.factory.reset
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rahoulb-object-factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brightbox Systems Ltd
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-08 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -37,13 +37,12 @@ files:
|
|
37
37
|
- init.rb
|
38
38
|
- lib/object_factory.rb
|
39
39
|
- Manifest
|
40
|
-
-
|
40
|
+
- object-factory.gemspec
|
41
41
|
- Rakefile
|
42
42
|
- README.rdoc
|
43
43
|
- spec/object_spec.rb
|
44
44
|
- spec/spec.opts
|
45
45
|
- tasks/rspec.rake
|
46
|
-
- object-factory.gemspec
|
47
46
|
has_rdoc: true
|
48
47
|
homepage: http://github.com/rahoub/object-factory
|
49
48
|
post_install_message:
|