jelly_bird 0.0.2 → 0.0.3b
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/LICENCE +19 -0
- data/Readme.md +38 -2
- data/lib/jelly_bird/define.rb +9 -4
- data/lib/jelly_bird/gen.rb +5 -1
- data/lib/jelly_bird/version.rb +1 -1
- data/spec/jelly_bird/custom_builders_spec.rb +35 -0
- data/spec/jelly_bird/jelly_bird_spec.rb +7 -2
- metadata +16 -10
data/LICENCE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2011 by Jakub Oboza
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/Readme.md
CHANGED
@@ -2,7 +2,10 @@
|
|
2
2
|
|
3
3
|
# instalation
|
4
4
|
|
5
|
-
|
5
|
+
type
|
6
|
+
`gem install jelly_bird`
|
7
|
+
|
8
|
+
or add to bundler ( test group )
|
6
9
|
|
7
10
|
"jelly_bird", :git => "git@github.com:JakubOboza/jellybird.git"
|
8
11
|
|
@@ -28,4 +31,37 @@ to generate object in test just use `.gen` like this `Dummy.gen` to get generate
|
|
28
31
|
10.times { puts Dummy.gen[:name] }
|
29
32
|
|
30
33
|
dummy = Dummy.gen
|
31
|
-
|
34
|
+
# dummy[:name] => random generated /\w{3,10}/ compilant word
|
35
|
+
|
36
|
+
other_dummy = Dummy.gen(:name => "dummy name")
|
37
|
+
# other_dummy[:name] => "dummy name"
|
38
|
+
|
39
|
+
# integration with rspec
|
40
|
+
|
41
|
+
touch a file with defines like `factories.rb` in spec folder and then require it inside of your `spec_helper.rb`. Then define all the factories like this.
|
42
|
+
|
43
|
+
|
44
|
+
User.define {{
|
45
|
+
:first_name => /\w{3,9}/.gen,
|
46
|
+
:last_name => /\w{3,8}/.gen,
|
47
|
+
:email => /\w{3,8}@\w{3,8}\.com/.gen
|
48
|
+
}}
|
49
|
+
|
50
|
+
Family.define {{
|
51
|
+
:father => User.gen,
|
52
|
+
:mom => User.gen,
|
53
|
+
:kind => USer.gen,
|
54
|
+
:family_name => /\w{3,8}/.gen
|
55
|
+
}}
|
56
|
+
|
57
|
+
|
58
|
+
remember that if you wanna embbed one into another please don't specify them at random order :).
|
59
|
+
|
60
|
+
Now just use it in tests!
|
61
|
+
|
62
|
+
$ Powered by
|
63
|
+
It is powered by `randexp` gem and initial concept was based on `dm-sweatshop` syntax. Big thanks to this two projects.
|
64
|
+
|
65
|
+
|
66
|
+
# Author
|
67
|
+
Jakub Oboza, https://github.com/JakubOboza
|
data/lib/jelly_bird/define.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
|
+
|
1
2
|
module JellyBird
|
2
3
|
|
3
4
|
module Define
|
4
5
|
|
5
6
|
@@generator = {}
|
6
7
|
|
7
|
-
def define(&default_lambda)
|
8
|
-
@@generator[self.to_s]
|
8
|
+
def define(name = :default, &default_lambda)
|
9
|
+
if @@generator[self.to_s]
|
10
|
+
@@generator[self.to_s][name] = default_lambda
|
11
|
+
else
|
12
|
+
@@generator[self.to_s] = { name => default_lambda }
|
13
|
+
end
|
9
14
|
end
|
10
15
|
|
11
|
-
def generator
|
12
|
-
@@generator[self.to_s]
|
16
|
+
def generator(name = :default)
|
17
|
+
@@generator[self.to_s][name]
|
13
18
|
end
|
14
19
|
|
15
20
|
end
|
data/lib/jelly_bird/gen.rb
CHANGED
@@ -3,7 +3,11 @@ module JellyBird
|
|
3
3
|
module Generate
|
4
4
|
|
5
5
|
def gen(opts = {})
|
6
|
-
|
6
|
+
generate(:default, opts)
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate(name = :default, opts = {})
|
10
|
+
options = self::generator(name).call if self::generator(name)
|
7
11
|
options.merge!(opts)
|
8
12
|
obj = self.new(options)
|
9
13
|
options.each_pair { |key, value| obj[key] = value } if obj.kind_of?(Hash)
|
data/lib/jelly_bird/version.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Mummy
|
4
|
+
attr_accessor :attributes
|
5
|
+
|
6
|
+
def initialize(opts = {})
|
7
|
+
self.attributes = opts
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
class Dummy < Hash; end
|
13
|
+
|
14
|
+
class Rummy < Hash; end
|
15
|
+
|
16
|
+
describe "Custom Builders" do
|
17
|
+
|
18
|
+
it "should be able to define custom builders" do
|
19
|
+
|
20
|
+
Mummy.define {{
|
21
|
+
:left => /\w{3,10}/.gen,
|
22
|
+
:right => /\w{3,10}/.gen
|
23
|
+
}}
|
24
|
+
|
25
|
+
Mummy.define(:custom) {{
|
26
|
+
:center => /\w{3,10}/.gen
|
27
|
+
}}
|
28
|
+
|
29
|
+
mummy = Mummy.generate(:custom, :mumble => true)
|
30
|
+
mummy.attributes[:center].should_not be_nil
|
31
|
+
mummy.attributes[:mumble].should eql(true)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -87,8 +87,6 @@ describe JellyBird do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should generate object inside of other object" do
|
90
|
-
|
91
|
-
# bug, currently for hashes you can input a gen inside of a define ;/
|
92
90
|
dummy = Dummy.gen
|
93
91
|
|
94
92
|
Rummy.define {{
|
@@ -98,6 +96,13 @@ describe JellyBird do
|
|
98
96
|
mummy = Rummy.gen
|
99
97
|
mummy[:baby_rummy_is_a][:name].should_not be_nil
|
100
98
|
|
99
|
+
Rummy.define {{
|
100
|
+
:baby => Dummy.gen,
|
101
|
+
:name => /\w{3,6}/.gen
|
102
|
+
}}
|
103
|
+
|
104
|
+
Rummy.gen.should be_a(Rummy)
|
105
|
+
Rummy.gen[:baby].should be_a(Dummy)
|
101
106
|
end
|
102
107
|
|
103
108
|
it "should not override other generators" do
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jelly_bird
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 39
|
5
|
+
prerelease: 5
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
|
9
|
+
- 3
|
10
|
+
- b
|
11
|
+
version: 0.0.3b
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- JO
|
@@ -15,7 +16,7 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2011-07-
|
19
|
+
date: 2011-07-12 00:00:00 Z
|
19
20
|
dependencies: []
|
20
21
|
|
21
22
|
description: JellyBird is a ultra small factory to help generating objects for purpose of tests.
|
@@ -31,6 +32,7 @@ files:
|
|
31
32
|
- .gitignore
|
32
33
|
- .rspec
|
33
34
|
- Gemfile
|
35
|
+
- LICENCE
|
34
36
|
- Rakefile
|
35
37
|
- Readme.md
|
36
38
|
- jelly_bird.gemspec
|
@@ -38,6 +40,7 @@ files:
|
|
38
40
|
- lib/jelly_bird/define.rb
|
39
41
|
- lib/jelly_bird/gen.rb
|
40
42
|
- lib/jelly_bird/version.rb
|
43
|
+
- spec/jelly_bird/custom_builders_spec.rb
|
41
44
|
- spec/jelly_bird/jelly_bird_spec.rb
|
42
45
|
- spec/spec_helper.rb
|
43
46
|
homepage: ""
|
@@ -60,19 +63,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
64
|
none: false
|
62
65
|
requirements:
|
63
|
-
- - "
|
66
|
+
- - ">"
|
64
67
|
- !ruby/object:Gem::Version
|
65
|
-
hash:
|
68
|
+
hash: 25
|
66
69
|
segments:
|
67
|
-
-
|
68
|
-
|
70
|
+
- 1
|
71
|
+
- 3
|
72
|
+
- 1
|
73
|
+
version: 1.3.1
|
69
74
|
requirements: []
|
70
75
|
|
71
76
|
rubyforge_project: jelly_bird
|
72
|
-
rubygems_version: 1.8.
|
77
|
+
rubygems_version: 1.8.5
|
73
78
|
signing_key:
|
74
79
|
specification_version: 3
|
75
80
|
summary: Ultra small gem for generating objects
|
76
81
|
test_files:
|
82
|
+
- spec/jelly_bird/custom_builders_spec.rb
|
77
83
|
- spec/jelly_bird/jelly_bird_spec.rb
|
78
84
|
- spec/spec_helper.rb
|