cobble 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cobble.rb +2 -0
- data/lib/cobble/errors.rb +1 -0
- data/lib/cobble/fakes.rb +21 -5
- metadata +2 -2
data/lib/cobble.rb
CHANGED
@@ -5,10 +5,12 @@ Dir.glob(File.join(File.dirname(__FILE__), 'cobble', '**/*.rb')).each do |f|
|
|
5
5
|
require File.expand_path(f)
|
6
6
|
end
|
7
7
|
|
8
|
+
# Shortcut for Cobble.create(name, *args, &block)
|
8
9
|
def Cobble(name, *args, &block)
|
9
10
|
Cobble.create(name, *args, &block)
|
10
11
|
end
|
11
12
|
|
13
|
+
# Shortcut for Cobble, really only used to ease transition from FactoryGirl
|
12
14
|
def Factory(name, *args, &block)
|
13
15
|
puts "*** WARNING *** You should migrate over to using the proper Cobble methods as this won't be here forever!"
|
14
16
|
Cobble.create(name, *args, &block)
|
data/lib/cobble/errors.rb
CHANGED
data/lib/cobble/fakes.rb
CHANGED
@@ -1,25 +1,41 @@
|
|
1
1
|
class Cobble
|
2
|
+
# A registry for procs that can be called to generate random, or fake, data.
|
2
3
|
class Fakes
|
3
4
|
include Singleton
|
4
5
|
|
6
|
+
# List of all the fake procs in the system.
|
5
7
|
attr_accessor :list
|
6
8
|
|
7
|
-
def initialize
|
9
|
+
def initialize # :nodoc:
|
8
10
|
self.reset!
|
9
11
|
end
|
10
12
|
|
11
|
-
def reset!
|
13
|
+
def reset! # :nodoc:
|
12
14
|
self.list = {}
|
13
15
|
end
|
14
16
|
|
17
|
+
# Add a new proc to the system.
|
18
|
+
#
|
19
|
+
# Example:
|
20
|
+
# Cobble::Fakes.add(:birth_date) {(rand(80) + 13).years.ago}
|
15
21
|
def add(name, &block)
|
16
22
|
self.list[name.to_sym] = block
|
17
23
|
end
|
18
|
-
|
24
|
+
|
25
|
+
# Create an alias from one fake proc to another.
|
26
|
+
#
|
27
|
+
# Example:
|
28
|
+
# Cobble::Fakes.add(:birth_date) {(rand(80) + 13).years.ago}
|
29
|
+
# Cobble::Fakes.alias(:birthday, :birth_date)
|
19
30
|
def alias(from, to)
|
20
31
|
self.list[from.to_sym] = Cobble::Fakes::Alias.new(to)
|
21
32
|
end
|
22
33
|
|
34
|
+
# Executes the specified fake proc. Raise Cobble::Errors::NoFakeRegistered
|
35
|
+
# if the fake proc is not registered with the system.
|
36
|
+
#
|
37
|
+
# Example:
|
38
|
+
# Cobble::Fakes.execute(:email) # => 'bob@example.com'
|
23
39
|
def execute(name, *args)
|
24
40
|
block = self.list[name.to_sym]
|
25
41
|
if block.is_a?(Cobble::Fakes::Alias)
|
@@ -32,13 +48,13 @@ class Cobble
|
|
32
48
|
end
|
33
49
|
|
34
50
|
class << self
|
35
|
-
def method_missing(sym, *args, &block)
|
51
|
+
def method_missing(sym, *args, &block) # :nodoc:
|
36
52
|
Cobble::Fakes.instance.send(sym, *args, &block)
|
37
53
|
end
|
38
54
|
end # class << self
|
39
55
|
|
40
56
|
private
|
41
|
-
class Alias
|
57
|
+
class Alias # :nodoc:
|
42
58
|
attr_accessor :to
|
43
59
|
def initialize(to)
|
44
60
|
self.to = to
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cobble
|
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
|
- markbates
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-16 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|