jelly_bird 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *~
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jelly_bird.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 0.9.2"
7
+ gem "rspec", "~> 2.3.0"
8
+ gem "randexp"
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ # If you want to make this the default task
7
+ task :default => :spec
data/Readme.md ADDED
@@ -0,0 +1,31 @@
1
+ # Jelly Bird gem
2
+
3
+ # instalation
4
+
5
+ add to bundler ( test group )
6
+
7
+ "jelly_bird", :git => "git@github.com:JakubOboza/jellybird.git"
8
+
9
+ # usage
10
+
11
+ assuming you have class called `Dummy` with two properties name and number you can create test factory this say:
12
+
13
+ Dummy.define {{
14
+ :name => /\w{3,8}/.gen,
15
+ :number => /\d\d\d\d\d\d/.gen
16
+ }}
17
+
18
+ to generate object in test just use `.gen` like this `Dummy.gen` to get generated object
19
+
20
+ # example
21
+
22
+ class Dummy < Hash; end
23
+
24
+ Dummy.define {{
25
+ :name => /\w{3,10}/.gen
26
+ }}
27
+
28
+ 10.times { puts Dummy.gen[:name] }
29
+
30
+ dummy = Dummy.gen
31
+ puts dummy[:name]
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "jelly_bird/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jelly_bird"
7
+ s.version = JellyBird::VERSION
8
+ s.authors = ["JO"]
9
+ s.email = ["jakub.oboza@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Ultra small gem for generating objects}
12
+ s.description = %q{JellyBird is a ultra small factory to help generating objects for purpose of tests.}
13
+
14
+ s.rubyforge_project = "jelly_bird"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,17 @@
1
+ module JellyBird
2
+
3
+ module Define
4
+
5
+ @@generators = nil
6
+
7
+ def define(&default_lambda)
8
+ @@generator = default_lambda
9
+ end
10
+
11
+ def generator
12
+ @@generator
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,14 @@
1
+ module JellyBird
2
+
3
+ module Generate
4
+
5
+ def gen(opts = {})
6
+ options = self::generator.call if self::generator
7
+ options.merge!(opts)
8
+ obj = self.new(options)
9
+ options.each_pair { |key, value| obj[key] = value } if obj.kind_of?(Hash)
10
+ obj
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module JellyBird
2
+ VERSION = "0.0.1"
3
+ end
data/lib/jelly_bird.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "randexp"
2
+ require "jelly_bird/version"
3
+ require "jelly_bird/gen"
4
+ require "jelly_bird/define"
5
+
6
+ module JellyBird
7
+
8
+ def self.included(base)
9
+ base.extend( JellyBird::Generate )
10
+ base.extend( JellyBird::Define )
11
+ end
12
+
13
+ end
14
+
15
+ # add it to each Object
16
+ class Object
17
+ include JellyBird
18
+ end
@@ -0,0 +1,76 @@
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 JellyBird do
17
+
18
+ describe "#define_scheme" do
19
+
20
+ it "should be able to define scheme for activerecord like objects" do
21
+
22
+ Mummy.define {{
23
+ :name => /\w{3,8}/.gen,
24
+ :number => /\d\d\d\d\d\d/.gen
25
+ }}
26
+ mummy = Mummy.gen
27
+ mummy.should be_kind_of(Mummy)
28
+ mummy.attributes[:name].should =~ /\w{3,8}/
29
+ mummy.attributes[:number].should =~ /\d\d\d\d\d\d/
30
+
31
+ end
32
+
33
+ it "should be able to define scheme for hashlike objects" do
34
+
35
+ Dummy.define {{
36
+ :name => /\w{3,8}/.gen,
37
+ :number => /\d\d\d\d\d\d/.gen
38
+ }}
39
+
40
+ Rummy.define {{
41
+ :name => /\w{3,8}/.gen,
42
+ :number => /\d\d\d\d\d\d/.gen
43
+ }}
44
+
45
+ dummy = Dummy.gen
46
+ dummy.should be_kind_of(Dummy)
47
+ dummy[:name].should =~ /\w{3,8}/
48
+ dummy[:number].should =~ /\d\d\d\d\d\d/
49
+
50
+ rummy = Rummy.gen
51
+ rummy.should be_kind_of(Rummy)
52
+ rummy[:name].should =~ /\w{3,8}/
53
+ rummy[:number].should =~ /\d\d\d\d\d\d/
54
+
55
+ end
56
+
57
+ end
58
+
59
+
60
+ describe "#gen" do
61
+
62
+ it "should be able to generate object" do
63
+ dummy = Dummy.gen( :name => "test" )
64
+ dummy.should be_kind_of(Dummy)
65
+ dummy[:name].should eql("test")
66
+ end
67
+
68
+ it "should not generate same name" do
69
+ 500.times do
70
+ Dummy.gen[:name].should_not eql(Dummy.gen[:name])
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'jelly_bird'
5
+
6
+ RSpec.configure do |config|
7
+ # some (optional) config here
8
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jelly_bird
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - JO
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-30 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: JellyBird is a ultra small factory to help generating objects for purpose of tests.
22
+ email:
23
+ - jakub.oboza@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - .rspec
33
+ - Gemfile
34
+ - Rakefile
35
+ - Readme.md
36
+ - jelly_bird.gemspec
37
+ - lib/jelly_bird.rb
38
+ - lib/jelly_bird/define.rb
39
+ - lib/jelly_bird/gen.rb
40
+ - lib/jelly_bird/version.rb
41
+ - spec/jelly_bird/jelly_bird_spec.rb
42
+ - spec/spec_helper.rb
43
+ homepage: ""
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ requirements: []
70
+
71
+ rubyforge_project: jelly_bird
72
+ rubygems_version: 1.8.5
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Ultra small gem for generating objects
76
+ test_files:
77
+ - spec/jelly_bird/jelly_bird_spec.rb
78
+ - spec/spec_helper.rb