rspec_rails3_gen 0.2.0 → 0.2.2

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.
@@ -16,4 +16,4 @@ Signal.trap("INT") { puts; exit }
16
16
  require 'rails/generators'
17
17
  require 'generators/rspec/controller/controller_generator'
18
18
 
19
- RSpec::Generators::ControllerGenerator.start
19
+ Rspec::Generators::ControllerGenerator.start
@@ -18,4 +18,4 @@ require 'rails/version'
18
18
  require 'rails/generators'
19
19
  require 'generators/rspec/integration_spec/integration_spec_generator'
20
20
 
21
- RSpec::Generators::IntegrationSpecGenerator.start
21
+ Rspec::Generators::IntegrationSpecGenerator.start
@@ -16,4 +16,4 @@ Signal.trap("INT") { puts; exit }
16
16
  require 'rails/generators'
17
17
  require 'generators/rspec/model/model_generator'
18
18
 
19
- RSpec::Generators::ModelGenerator.start
19
+ Rspec::Generators::ModelGenerator.start
@@ -18,4 +18,4 @@ require 'rails/version'
18
18
  require 'rails/generators'
19
19
  require 'generators/rspec/scaffold/scaffold_generator'
20
20
 
21
- RSpec::Generators::ScaffoldGenerator.start
21
+ Rspec::Generators::ScaffoldGenerator.start
@@ -16,4 +16,4 @@ Signal.trap("INT") { puts; exit }
16
16
  require 'rails/generators'
17
17
  require 'generators/rspec/skeleton/skeleton_generator'
18
18
 
19
- RSpec::Generators::SkeletonGenerator.start
19
+ Rspec::Generators::SkeletonGenerator.start
@@ -5,7 +5,7 @@ require 'generators/rspec_rails3_gen_base'
5
5
  # see 'hook_for'
6
6
  # ==================
7
7
 
8
- module RSpec
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.rb.t', File.join('spec/helpers', class_path, "#{file_name}_helper_spec.rb")
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!
@@ -16,6 +16,10 @@ module Rails
16
16
  end
17
17
  end
18
18
 
19
+ def to_s
20
+ "#{name}:#{type}"
21
+ end
22
+
19
23
  def name_or_reference
20
24
  if ::Rails::VERSION::STRING >= '2.2'
21
25
  reference? ? :"#{name}_id" : name
@@ -1,7 +1,7 @@
1
1
  # Author: Kristian Mandrup
2
2
  # email: kmandrup@gmail.com
3
3
  require 'generators/rspec_rails3_gen_base'
4
- module RSpec
4
+ module Rspec
5
5
  module Generators
6
6
  class IntegrationSpecGenerator < NamedBase
7
7
 
@@ -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 RSpec
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, :migration, :fixture
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 RSpec
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, :model, :migration, :scaffold, :layout
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
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'generators/rspec_rails3_gen_base'
5
5
 
6
- module RSpec
6
+ module Rspec
7
7
  module Generators
8
8
  class SkeletonGenerator < Base
9
9
 
@@ -1,7 +1,7 @@
1
1
  require 'rails/generators/base'
2
2
  require 'rails/generators/named_base'
3
3
 
4
- module RSpec
4
+ module Rspec
5
5
  module Generators
6
6
  class Base < Rails::Generators::Base #:nodoc:
7
7
  def self.source_root
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.0
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-05 00:00:00 +01:00
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