cranky 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +14 -0
- data/README.rdoc +19 -0
- data/lib/cranky.rb +17 -2
- data/spec/cranky_spec.rb +38 -9
- metadata +12 -6
data/Gemfile.lock
ADDED
data/README.rdoc
CHANGED
@@ -36,6 +36,15 @@ Cranky steals its core syntax from Factory Girl...
|
|
36
36
|
Factory.build(:user, :name => "Ian") # Override a default attribute value
|
37
37
|
Factory.attributes_for(:user) # Return a set of valid attributes rather than the object
|
38
38
|
|
39
|
+
And has a nice debug option (rails only) to warn you when your factory is broken, recommend you do this for your first spec...
|
40
|
+
|
41
|
+
describe User do
|
42
|
+
it "should have a working factory" do
|
43
|
+
# This will raise an error and report the validation errors should they occur
|
44
|
+
Factory.debug(:user).should be_valid
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
39
48
|
Cranky allows you to build factories via std Ruby methods, like this...
|
40
49
|
|
41
50
|
# factories/my_factories.rb
|
@@ -226,6 +235,16 @@ Sometimes it is useful to be warned that your factory is generating invalid inst
|
|
226
235
|
|
227
236
|
Factory.debug = true
|
228
237
|
|
238
|
+
Or run within a block...
|
239
|
+
|
240
|
+
Factory.debug do
|
241
|
+
Factory.build(:user)
|
242
|
+
end
|
243
|
+
|
244
|
+
Or inline (runs the build method with debug enabled)...
|
245
|
+
|
246
|
+
Factory.debug(:user)
|
247
|
+
|
229
248
|
Note that this relies on the instance having a valid? method, so in practice this may only work with Rails.
|
230
249
|
|
231
250
|
=== Attributes For
|
data/lib/cranky.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Cranky
|
2
2
|
|
3
|
-
VERSION = "0.1.
|
3
|
+
VERSION = "0.1.1"
|
4
4
|
|
5
5
|
# Dir.glob("#{File.expand_path(File.dirname(__FILE__))}/*.rb").each do |file|
|
6
6
|
# require file
|
@@ -12,7 +12,7 @@ class Cranky
|
|
12
12
|
# end
|
13
13
|
# end
|
14
14
|
|
15
|
-
|
15
|
+
attr_writer :debug
|
16
16
|
|
17
17
|
def initialize
|
18
18
|
@what = []
|
@@ -39,6 +39,21 @@ class Cranky
|
|
39
39
|
build(what, attrs).attributes
|
40
40
|
end
|
41
41
|
|
42
|
+
def debug(what=nil)
|
43
|
+
if block_given?
|
44
|
+
@debug = true
|
45
|
+
yield
|
46
|
+
@debug = false
|
47
|
+
elsif what
|
48
|
+
@debug = true
|
49
|
+
item = build(what)
|
50
|
+
@debug = false
|
51
|
+
item
|
52
|
+
else
|
53
|
+
@debug
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
42
57
|
private
|
43
58
|
|
44
59
|
def n
|
data/spec/cranky_spec.rb
CHANGED
@@ -63,16 +63,45 @@ describe Cranky do
|
|
63
63
|
b.unique.should_not == c.unique
|
64
64
|
end
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
error
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
66
|
+
describe "debugger" do
|
67
|
+
|
68
|
+
it "should raise an error if the factory produces an invalid object when enabled (rails only)" do
|
69
|
+
Factory.debug = true
|
70
|
+
error = false
|
71
|
+
begin
|
72
|
+
Factory.build(:user)
|
73
|
+
rescue
|
74
|
+
error = true
|
75
|
+
end
|
76
|
+
error.should == true
|
77
|
+
Factory.debug = false
|
78
|
+
end
|
79
|
+
|
80
|
+
it "can be run as a block" do
|
81
|
+
Factory.debug.should == false
|
82
|
+
error = false
|
83
|
+
Factory.debug do
|
84
|
+
begin
|
85
|
+
Factory.build(:user)
|
86
|
+
rescue
|
87
|
+
error = true
|
88
|
+
end
|
89
|
+
end
|
90
|
+
error.should == true
|
91
|
+
Factory.debug.should == false
|
73
92
|
end
|
74
|
-
|
75
|
-
|
93
|
+
|
94
|
+
it "can be run inline" do
|
95
|
+
Factory.debug.should == false
|
96
|
+
error = false
|
97
|
+
begin
|
98
|
+
Factory.debug(:user)
|
99
|
+
rescue
|
100
|
+
error = true
|
101
|
+
end
|
102
|
+
error.should == true
|
103
|
+
end
|
104
|
+
|
76
105
|
end
|
77
106
|
|
78
107
|
it "should allow arguments to be passed in the overrides hash" do
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cranky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Stephen McGinty
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-08-14 00:00:00 -05:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -28,11 +29,12 @@ extra_rdoc_files: []
|
|
28
29
|
|
29
30
|
files:
|
30
31
|
- lib/cranky.rb
|
31
|
-
- spec/cranky_spec.rb
|
32
32
|
- spec/spec_helper.rb
|
33
|
+
- spec/cranky_spec.rb
|
33
34
|
- README.rdoc
|
34
|
-
- Gemfile
|
35
35
|
- LICENSE
|
36
|
+
- Gemfile.lock
|
37
|
+
- Gemfile
|
36
38
|
- init.rb
|
37
39
|
has_rdoc: true
|
38
40
|
homepage: http://github.com/ginty/cranky
|
@@ -44,16 +46,20 @@ rdoc_options: []
|
|
44
46
|
require_paths:
|
45
47
|
- lib
|
46
48
|
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
47
50
|
requirements:
|
48
51
|
- - ">="
|
49
52
|
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
50
54
|
segments:
|
51
55
|
- 0
|
52
56
|
version: "0"
|
53
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
54
59
|
requirements:
|
55
60
|
- - ">="
|
56
61
|
- !ruby/object:Gem::Version
|
62
|
+
hash: 19
|
57
63
|
segments:
|
58
64
|
- 1
|
59
65
|
- 3
|
@@ -62,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
68
|
requirements: []
|
63
69
|
|
64
70
|
rubyforge_project:
|
65
|
-
rubygems_version: 1.3.
|
71
|
+
rubygems_version: 1.3.7
|
66
72
|
signing_key:
|
67
73
|
specification_version: 3
|
68
74
|
summary: A very light yet powerful test factory framework.
|