rspec_for_generators 0.2.0 → 0.2.1
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/README.markdown
CHANGED
@@ -19,35 +19,37 @@ To install using edge
|
|
19
19
|
|
20
20
|
The following demonstrates an example usage. There are many more options and cool DSL convenience methods. Check out the code!
|
21
21
|
|
22
|
-
|
23
|
-
# spec/spec_helper.rb
|
24
|
-
require 'rspec'
|
22
|
+
### spec/spec_helper.rb
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
#
|
29
|
-
#
|
24
|
+
<pre>require 'rspec'
|
25
|
+
|
26
|
+
# The following somewhat ugly 'hack' is currently required for rails_spec_helper.rb to work.
|
27
|
+
# It's the relative root for which the Rails mock app is created.
|
28
|
+
# So if it's set to point to the spec folder, then the temporary rails application
|
29
|
+
# will be generated in ../tmp, relative to the folder of this file : File.dirname(__FILE__)
|
30
|
+
# Thus in this example the /tmp folder will be in the current project root.
|
31
|
+
|
32
|
+
# Note: In the near future I will provide a better way to achieve this, by hooking into the Rails 3 loading
|
33
|
+
# behavior as described in a *Rails Dispatch* article by *wycatz*
|
30
34
|
|
31
35
|
module Rails
|
32
36
|
def config_root_dir
|
33
|
-
File.dirname(
|
37
|
+
File.dirname(__FILE__)
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
37
41
|
# load this rspec toolbox to help spec generators
|
38
|
-
require 'rspec_for_generators'
|
42
|
+
require 'rspec_for_generators'</pre>
|
43
|
+
|
44
|
+
### spec/generators/canable.rb
|
39
45
|
|
40
|
-
|
46
|
+
Convenience way to define which generators to require
|
41
47
|
|
42
|
-
<pre>
|
43
|
-
# spec/generators/canable.rb
|
44
|
-
require_generators :canable => ['model', 'user']
|
45
|
-
</pre>
|
48
|
+
<pre>require_generators :canable => ['model', 'user']</pre>
|
46
49
|
|
47
|
-
|
48
|
-
# spec/generators/model_generator_spec.rb
|
50
|
+
### spec/generators/model_generator_spec.rb
|
49
51
|
|
50
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
52
|
+
<pre>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
51
53
|
|
52
54
|
# list of generators to spec are loaded
|
53
55
|
require 'generators/canable'
|
@@ -93,8 +95,7 @@ describe 'model_generator' do
|
|
93
95
|
end
|
94
96
|
end
|
95
97
|
end
|
96
|
-
end
|
97
|
-
</pre>
|
98
|
+
end</pre>
|
98
99
|
|
99
100
|
## Note on Patches/Pull Requests
|
100
101
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
@@ -11,11 +11,15 @@ require 'rspec_for_generators/rails_spec_helper'
|
|
11
11
|
Rails::Generators.configure!
|
12
12
|
|
13
13
|
# require the generators
|
14
|
-
def require_generators generator_list
|
15
|
-
generator_list.each do |name, generators|
|
16
|
-
generators
|
17
|
-
require File.join('generators', name.to_s,
|
18
|
-
|
14
|
+
def require_generators *generator_list
|
15
|
+
generator_list.each do |name, generators|
|
16
|
+
if !generators || generators.empty
|
17
|
+
require File.join('generators', name.to_s, "#{name.to_s}_generator")
|
18
|
+
else
|
19
|
+
generators.each do |generator_name|
|
20
|
+
require File.join('generators', name.to_s, generator_name.to_s, "#{generator_name}_generator")
|
21
|
+
end
|
22
|
+
end
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|