rspec_rails3_gen 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/rspec_controller +1 -1
- data/bin/rspec_integration_spec +1 -1
- data/bin/rspec_model +1 -1
- data/bin/rspec_scaffold +1 -1
- data/bin/rspec_skeleton +1 -1
- data/lib/generators/rspec/controller/controller_generator.rb +5 -2
- data/lib/generators/rspec/default_values.rb +4 -0
- data/lib/generators/rspec/integration_spec/integration_spec_generator.rb +1 -1
- data/lib/generators/rspec/model/model_generator.rb +12 -3
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +49 -30
- data/lib/generators/rspec/skeleton/skeleton_generator.rb +1 -1
- data/lib/generators/rspec_rails3_gen_base.rb +1 -1
- metadata +2 -2
data/bin/rspec_controller
CHANGED
data/bin/rspec_integration_spec
CHANGED
data/bin/rspec_model
CHANGED
data/bin/rspec_scaffold
CHANGED
data/bin/rspec_skeleton
CHANGED
@@ -5,7 +5,7 @@ require 'generators/rspec_rails3_gen_base'
|
|
5
5
|
# see 'hook_for'
|
6
6
|
# ==================
|
7
7
|
|
8
|
-
module
|
8
|
+
module Rspec
|
9
9
|
module Generators
|
10
10
|
class ControllerGenerator < NamedBase
|
11
11
|
|
@@ -78,7 +78,7 @@ module RSpec
|
|
78
78
|
|
79
79
|
# Controller spec, class, and helper.
|
80
80
|
template 'controller_spec.rb', File.join('spec/controllers', class_path, "#{file_name}_controller_spec.rb")
|
81
|
-
template 'helper_spec.
|
81
|
+
template 'helper_spec.erb', File.join('spec/helpers', class_path, "#{file_name}_helper_spec.rb")
|
82
82
|
|
83
83
|
# Spec and view template for each action.
|
84
84
|
html_actions.each do |action|
|
@@ -87,6 +87,9 @@ module RSpec
|
|
87
87
|
puts target_file
|
88
88
|
template 'view_spec.rb', target_file
|
89
89
|
end
|
90
|
+
|
91
|
+
actions_str = actions.join(' ')
|
92
|
+
generate "controller #{file_name} #{actions_str}"
|
90
93
|
end
|
91
94
|
|
92
95
|
# hook into controller and helper generators to have them execute using same arguments!
|
@@ -2,7 +2,7 @@ require 'rails/version'
|
|
2
2
|
require File.dirname(__FILE__) + '/../default_values'
|
3
3
|
require 'generators/rspec_rails3_gen_base'
|
4
4
|
|
5
|
-
module
|
5
|
+
module Rspec
|
6
6
|
module Generators
|
7
7
|
class ModelGenerator < NamedBase
|
8
8
|
# argument :model_name, :type => :string, :required => true, :banner => 'ModelName'
|
@@ -32,7 +32,14 @@ module RSpec
|
|
32
32
|
# use hook to execute model generator
|
33
33
|
|
34
34
|
# create spec for model
|
35
|
-
template 'model_spec.rb', "spec/models/#{file_name}_spec.rb"
|
35
|
+
template 'model_spec.rb', "spec/models/#{file_name}_spec.rb"
|
36
|
+
attribs = attributes.map{|a| a.to_s}.join(' ')
|
37
|
+
# puts "script/generate model #{file_name} #{attribs}"
|
38
|
+
no_fixture = options[:skip_fixture] ? '--skip-fixture' : ''
|
39
|
+
skip_migration = options[:skip_migration] ? '--skip-migration' : ''
|
40
|
+
flags = [no_fixture, skip_migration].join(' ')
|
41
|
+
|
42
|
+
generate "model #{file_name} #{attribs} #{flags}"
|
36
43
|
|
37
44
|
# unless options[:skip_fixture]
|
38
45
|
# template 'fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml")
|
@@ -46,7 +53,9 @@ module RSpec
|
|
46
53
|
end
|
47
54
|
|
48
55
|
# hook into generators for model, migration and fixture and have them execute with same arguments
|
49
|
-
hook_for :model, :
|
56
|
+
hook_for :model, :in => :rails
|
57
|
+
hook_for :migration, :in => :rails
|
58
|
+
hook_for :fixture, :in => :rails
|
50
59
|
end
|
51
60
|
|
52
61
|
end
|
@@ -8,13 +8,20 @@ require 'generators/rspec_rails3_gen_base'
|
|
8
8
|
# TODO: Make hooks for other generators work!!!
|
9
9
|
# see 'hook_for'
|
10
10
|
# ==================
|
11
|
-
module
|
11
|
+
module Rspec
|
12
12
|
module Generators
|
13
13
|
class ScaffoldGenerator < NamedBase
|
14
14
|
|
15
15
|
class_option :default_file_extension, :type => :string, :aliases => "-fe", :default => 'html.erb',
|
16
16
|
:desc => "Default file extension for views"
|
17
17
|
|
18
|
+
class_option :skip_fixture, :type => :boolean, :aliases => "-F", :default => false,
|
19
|
+
:desc => "Skip Fixture creation"
|
20
|
+
|
21
|
+
class_option :skip_migration, :type => :boolean, :aliases => "-M", :default => false,
|
22
|
+
:desc => "Skip Migration creation"
|
23
|
+
|
24
|
+
|
18
25
|
no_tasks do
|
19
26
|
attr_accessor :model_name
|
20
27
|
attr_accessor :model_attributes
|
@@ -68,44 +75,56 @@ module RSpec
|
|
68
75
|
def create_files
|
69
76
|
# Controller, helper, views, and spec directories.
|
70
77
|
|
71
|
-
empty_directory 'spec/controllers'
|
72
|
-
empty_directory 'spec/routing'
|
73
|
-
empty_directory 'spec/models'
|
74
|
-
empty_directory 'spec/helpers'
|
75
|
-
empty_directory 'spec/fixtures'
|
76
|
-
empty_directory 'spec/views'
|
77
|
-
empty_directory 'spec/integration'
|
78
|
+
# empty_directory 'spec/controllers'
|
79
|
+
# empty_directory 'spec/routing'
|
80
|
+
# empty_directory 'spec/models'
|
81
|
+
# empty_directory 'spec/helpers'
|
82
|
+
# empty_directory 'spec/fixtures'
|
83
|
+
# empty_directory 'spec/views'
|
84
|
+
# empty_directory 'spec/integration'
|
78
85
|
|
79
86
|
# Controller spec, class, and helper.
|
80
|
-
template 'routing_spec.rb',
|
81
|
-
File.join('spec/routing', controller_class_path, "#{controller_file_name}_routing_spec.rb")
|
82
|
-
|
83
|
-
template 'controller_spec.rb',
|
84
|
-
File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb")
|
85
|
-
|
86
|
-
|
87
|
-
template 'helper_spec.rb',
|
88
|
-
File.join('spec/helpers', class_path, "#{controller_file_name}_helper_spec.rb")
|
89
|
-
|
90
|
-
# View specs
|
91
|
-
template "edit_erb_spec.rb",
|
92
|
-
File.join('spec/views', controller_class_path, controller_file_name, "edit.#{default_file_extension}_spec.rb")
|
93
|
-
template "index_erb_spec.rb",
|
94
|
-
File.join('spec/views', controller_class_path, controller_file_name, "index.#{default_file_extension}_spec.rb")
|
95
|
-
template "new_erb_spec.rb",
|
96
|
-
File.join('spec/views', controller_class_path, controller_file_name, "new.#{default_file_extension}_spec.rb")
|
97
|
-
template "show_erb_spec.rb",
|
98
|
-
File.join('spec/views', controller_class_path, controller_file_name, "show.#{default_file_extension}_spec.rb")
|
99
|
-
|
100
|
-
# route_resources controller_file_name
|
101
87
|
|
88
|
+
# template 'controller_spec.rb',
|
89
|
+
# File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb")
|
90
|
+
#
|
91
|
+
#
|
92
|
+
# template 'helper_spec.erb',
|
93
|
+
# File.join('spec/helpers', class_path, "#{controller_file_name}_helper_spec.rb")
|
94
|
+
#
|
95
|
+
# # View specs
|
96
|
+
# template "edit_erb_spec.rb",
|
97
|
+
# File.join('spec/views', controller_class_path, controller_file_name, "edit.#{default_file_extension}_spec.rb")
|
98
|
+
# template "index_erb_spec.rb",
|
99
|
+
# File.join('spec/views', controller_class_path, controller_file_name, "index.#{default_file_extension}_spec.rb")
|
100
|
+
# template "new_erb_spec.rb",
|
101
|
+
# File.join('spec/views', controller_class_path, controller_file_name, "new.#{default_file_extension}_spec.rb")
|
102
|
+
# template "show_erb_spec.rb",
|
103
|
+
# File.join('spec/views', controller_class_path, controller_file_name, "show.#{default_file_extension}_spec.rb")
|
104
|
+
|
105
|
+
no_fixture = options[:skip_fixture] ? '--skip-fixture' : ''
|
106
|
+
skip_migration = options[:skip_migration] ? '--skip-migration' : ''
|
107
|
+
flags = [no_fixture, skip_migration].join(' ')
|
108
|
+
|
109
|
+
actions_str = controller_actions.join(' ')
|
110
|
+
generate "rspec:controller #{controller_file_name} #{actions_str}"
|
111
|
+
|
112
|
+
attribs = model_attributes.map{|a| a.to_s}.join(' ')
|
113
|
+
generate "rspec:model #{controller_file_name} #{attribs} #{flags}"
|
114
|
+
|
115
|
+
empty_directory 'spec/routing'
|
116
|
+
template 'routing_spec.rb', File.join('spec/routing', controller_class_path, "#{controller_file_name}_routing_spec.rb")
|
102
117
|
end
|
103
118
|
|
104
119
|
# tries to find generator within rspec first, then in rails
|
105
120
|
# use :in, fx :in => :rails to be more specific!
|
106
121
|
|
107
122
|
# TODO: Make hooks work!!!
|
108
|
-
# hook_for :integration_spec
|
123
|
+
# hook_for :integration_spec
|
124
|
+
# hook_for :model
|
125
|
+
# hook_for :migration
|
126
|
+
# hook_for :scaffold
|
127
|
+
# hook_for :layout
|
109
128
|
|
110
129
|
no_tasks do
|
111
130
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_rails3_gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristian Mandrup
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-06 00:00:00 +01:00
|
13
13
|
default_executable: rspec_skeleton
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|