generator-spec 0.4.8 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +6 -0
- data/VERSION +1 -1
- data/generator-spec.gemspec +4 -2
- data/lib/generator_spec/extensions/core_ext.rb +30 -0
- data/lib/generator_spec/helpers/migration_helper.rb +15 -10
- data/lib/generator_spec/main.rb +5 -3
- data/lib/generator_spec/matchers/content/content_matcher.rb +8 -4
- data/lib/generator_spec/matchers/content/have_call.rb +4 -4
- data/lib/generator_spec/matchers/content/have_comment.rb +42 -0
- data/lib/generator_spec/matchers/file/generate_file.rb +2 -4
- data/lib/generator_spec/matchers/file/have_file.rb +2 -2
- data/lib/generator_spec/matchers/migration/have_up_down.rb +2 -0
- data/lib/generator_spec/rails_helpers/base_helper.rb +171 -0
- data/lib/generator_spec/rails_helpers/rails_app.rb +9 -2
- data/lib/generator_spec/rails_helpers/rails_controller.rb +33 -25
- data/lib/generator_spec/rails_helpers/rails_helper.rb +27 -25
- data/lib/generator_spec/rails_helpers/rails_mailer.rb +29 -21
- data/lib/generator_spec/rails_helpers/rails_migration.rb +41 -26
- data/lib/generator_spec/rails_helpers/rails_model.rb +29 -19
- data/lib/generator_spec/rails_helpers/rails_observer.rb +27 -23
- data/lib/generator_spec/rails_helpers/rails_orm.rb +33 -18
- data/lib/generator_spec/rails_helpers/rails_view.rb +42 -28
- data/spec/generator_spec/matchers/content/have_call_spec.rb +16 -0
- data/spec/generator_spec/matchers/rails/controller_matcher_spec.rb +3 -2
- data/spec/generator_spec/matchers/rails/helper_matcher_spec.rb +1 -1
- data/spec/generator_spec/matchers/rails/mailer_matcher_spec.rb +1 -1
- data/spec/generator_spec/matchers/rails/model_matcher_spec.rb +4 -4
- data/spec/generator_spec/matchers/rails/observer_matcher_spec.rb +1 -1
- data/spec/generator_spec/matchers/rails/view_matcher_spec.rb +1 -1
- data/spec/generator_spec/rails_helpers/rails_controller_spec.rb +33 -0
- data/spec/generator_spec/rails_helpers/rails_helper_spec.rb +33 -0
- data/spec/generator_spec/rails_helpers/rails_mailer_spec.rb +33 -0
- data/spec/generator_spec/rails_helpers/rails_model_spec.rb +31 -0
- data/spec/generator_spec/rails_helpers/rails_observer_spec.rb +33 -0
- data/spec/generator_spec/rails_helpers/rails_view_spec.rb +31 -0
- data/spec/spec_helper.rb +1 -1
- metadata +6 -4
@@ -1,5 +1,12 @@
|
|
1
1
|
module RSpec::Rails
|
2
|
-
module App
|
2
|
+
module App
|
3
|
+
def create_empty_tmp *args
|
4
|
+
args.flatten.each do |arg|
|
5
|
+
dir = send :"#{arg}_dir"
|
6
|
+
FileUtils.mkdir_p dir
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
3
10
|
def root_dir
|
4
11
|
::Rails.root
|
5
12
|
end
|
@@ -85,7 +92,7 @@ module RSpec::Rails
|
|
85
92
|
end
|
86
93
|
|
87
94
|
def mailer_files
|
88
|
-
rails_app_files :mailers
|
95
|
+
rails_app_files :mailers, '**/*_mailer.rb'
|
89
96
|
end
|
90
97
|
|
91
98
|
def helper_files
|
@@ -1,36 +1,44 @@
|
|
1
1
|
module RSpec::Rails
|
2
|
-
module Controller
|
3
|
-
include RSpec::Rails::
|
4
|
-
|
5
|
-
def create_controller name, content=nil
|
6
|
-
file = controller_file_name(name)
|
7
|
-
unless File.exist?(file)
|
8
|
-
FileUtils.mkdir_p File.dirname(file)
|
9
|
-
content ||= yield if block_given?
|
10
|
-
File.open(file, 'w') do |f|
|
11
|
-
f.puts controller_content(name, content)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
2
|
+
module Controller
|
3
|
+
include RSpec::Rails::BaseHelper
|
15
4
|
|
16
|
-
def
|
17
|
-
|
18
|
-
#{content}
|
19
|
-
end}
|
5
|
+
def controller_file_name name, options=nil
|
6
|
+
artifact_path name, :controller
|
20
7
|
end
|
21
8
|
|
9
|
+
# CREATE
|
10
|
+
def create_controller name, options={}, &block
|
11
|
+
create_artifact(name, set(options, :controller), &block)
|
12
|
+
end
|
13
|
+
|
14
|
+
# UPDATE
|
15
|
+
def insert_into_controller(name, options={}, &block)
|
16
|
+
insert_content(name, set(options, :controller), &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
# READ
|
20
|
+
def read_controller(name, options={}, &block)
|
21
|
+
read_artifact(name, set(options, :controller), &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
# DELETE
|
22
25
|
def remove_controller name
|
23
|
-
|
24
|
-
FileUtils.rm_f(file) if File.exist?(file)
|
26
|
+
remove_artifact name, :controller
|
25
27
|
end
|
26
28
|
|
27
29
|
def remove_controllers *names
|
28
|
-
|
30
|
+
remove_artifacts :controller, *names
|
29
31
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
|
33
|
+
|
34
|
+
def controller_marker name, options=nil
|
35
|
+
"#{name.to_s.camelize}Controller < ActionController::Base"
|
36
|
+
end
|
37
|
+
|
38
|
+
def new_controller_content name, content=nil, &block
|
39
|
+
new_artifact_content name, :controller, content, &block
|
40
|
+
end
|
41
|
+
|
42
|
+
aliases_for :controller
|
35
43
|
end
|
36
44
|
end
|
@@ -1,38 +1,40 @@
|
|
1
1
|
module RSpec::Rails
|
2
|
-
module Helper
|
3
|
-
include RSpec::Rails::
|
2
|
+
module Helper
|
3
|
+
include RSpec::Rails::BaseHelper
|
4
|
+
|
5
|
+
def helper_file_name name, options=nil
|
6
|
+
artifact_path name, :helper
|
7
|
+
end
|
4
8
|
|
5
|
-
def create_helper name,
|
6
|
-
|
7
|
-
unless File.exist?(file)
|
8
|
-
FileUtils.mkdir_p File.dirname(file)
|
9
|
-
content ||= yield if block_given?
|
10
|
-
File.open(file, 'w') do |f|
|
11
|
-
f.puts helper_content(name, content)
|
12
|
-
end
|
13
|
-
end
|
9
|
+
def create_helper name, options={}, &block
|
10
|
+
create_artifact(name, set(options, :helper), &block)
|
14
11
|
end
|
15
12
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
def insert_into_helper(name, options={}, &block)
|
14
|
+
insert_content(name, set(options, :helper), &block)
|
15
|
+
end
|
16
|
+
alias_method :update_helper, :insert_into_helper
|
17
|
+
|
18
|
+
def read_helper(name, options={}, &block)
|
19
|
+
read_artifact(name, set(options, :helper), &block)
|
20
|
+
end
|
21
21
|
|
22
22
|
def remove_helper name
|
23
|
-
|
24
|
-
FileUtils.rm_f(file) if File.exist?(file)
|
23
|
+
remove_artifact name, :helper
|
25
24
|
end
|
26
25
|
|
27
26
|
def remove_helpers *names
|
28
|
-
|
27
|
+
remove_artifacts :helper, *names
|
28
|
+
end
|
29
|
+
|
30
|
+
def helper_marker name, options=nil
|
31
|
+
"#{name.to_s.camelize}Helper"
|
32
|
+
end
|
33
|
+
|
34
|
+
def new_helper_content name, content=nil, &block
|
35
|
+
new_artifact_content name, :helper, content, &block
|
29
36
|
end
|
30
37
|
|
31
|
-
|
32
|
-
|
33
|
-
def helper_file_name name
|
34
|
-
File.join(helper_dir, "#{name}_helper.rb")
|
35
|
-
end
|
36
|
-
|
38
|
+
aliases_for :helper
|
37
39
|
end
|
38
40
|
end
|
@@ -1,31 +1,39 @@
|
|
1
1
|
module RSpec::Rails
|
2
|
-
module Mailer
|
3
|
-
include RSpec::Rails::
|
4
|
-
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
File.open(file, 'w') do |f|
|
12
|
-
f.puts content
|
13
|
-
end
|
14
|
-
end
|
2
|
+
module Mailer
|
3
|
+
include RSpec::Rails::BaseHelper
|
4
|
+
|
5
|
+
def mailer_file_name name, options=nil
|
6
|
+
artifact_path name, :mailer
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_mailer name, options={}, &block
|
10
|
+
create_artifact(name, set(options, :mailer), &block)
|
15
11
|
end
|
16
12
|
|
13
|
+
def insert_into_mailer(name, options={}, &block)
|
14
|
+
insert_content(name, set(options, :mailer), &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def read_mailer(name, options={}, &block)
|
18
|
+
read_artifact(name, set(options, :mailer), &block)
|
19
|
+
end
|
20
|
+
|
17
21
|
def remove_mailer name
|
18
|
-
|
19
|
-
FileUtils.rm_f(file) if File.exist?(file)
|
22
|
+
remove_artifact name, :mailer
|
20
23
|
end
|
21
24
|
|
22
25
|
def remove_mailers *names
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
def
|
27
|
-
|
28
|
-
end
|
26
|
+
remove_artifacts :mailer, *names
|
27
|
+
end
|
28
|
+
|
29
|
+
def mailer_marker name, options=nil
|
30
|
+
"#{name.to_s.camelize} < ActionMailer::Base"
|
31
|
+
end
|
32
|
+
|
33
|
+
def new_mailer_content name, content=nil, &block
|
34
|
+
new_artifact_content name, :mailer, content, &block
|
35
|
+
end
|
29
36
|
|
37
|
+
aliases_for :mailer
|
30
38
|
end
|
31
39
|
end
|
@@ -1,36 +1,51 @@
|
|
1
1
|
module RSpec::Rails
|
2
|
-
module Migration
|
3
|
-
include RSpec::Rails::
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
2
|
+
module Migration
|
3
|
+
include RSpec::Rails::BaseHelper
|
4
|
+
|
5
|
+
include Rails::Generators::MigrationHelper::ClassMethods
|
6
|
+
|
7
|
+
def migration_file_name name, options={}
|
8
|
+
number = options[:number]
|
9
|
+
number = next_migration_number(migration_dir) if !number
|
10
|
+
File.join(migration_dir, "#{number}_#{name}.rb")
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_migration name, options={}, &block
|
14
|
+
create_artifact(name, set(options, :migration), &block)
|
14
15
|
end
|
16
|
+
|
17
|
+
def find_migration name, option=nil
|
18
|
+
migrations = Dir.glob("#{migration_dir}/[0-9]*_*.rb")
|
19
|
+
return nil if !migrations.empty?
|
20
|
+
matching_migrations = migrations.grep(/\d+_#{name}\.rb$/)
|
21
|
+
return nil if matching_migrations.empty?
|
22
|
+
migration_file = (option == :last) ? matching_migrations.last : matching_migrations.first
|
23
|
+
end
|
24
|
+
|
25
|
+
def insert_into_migration(name, options={}, &block)
|
26
|
+
insert_content(name, set(options, :migration), &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def read_migration(name, options={}, &block)
|
30
|
+
read_artifact(name, set(options, :migration), &block)
|
31
|
+
end
|
15
32
|
|
16
33
|
def remove_migration name
|
17
|
-
|
18
|
-
migration_file = if !migrations.empty?
|
19
|
-
migrations.grep(/\d+_#{name}\.rb$/).first
|
20
|
-
else
|
21
|
-
false
|
22
|
-
end
|
23
|
-
FileUtils.rm_f(migration_file) if migration_file
|
34
|
+
remove_artifact :migration, name
|
24
35
|
end
|
25
36
|
|
26
37
|
def remove_migrations *names
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
38
|
+
remove_artifacts :migration, *names
|
39
|
+
end
|
40
|
+
|
41
|
+
def migration_marker name, options=nil
|
42
|
+
"#{name.to_s.camelize} < ActiveRecord::Migration"
|
43
|
+
end
|
44
|
+
|
45
|
+
def new_migration_content name, content=nil, &block
|
46
|
+
new_artifact_content name, :migration, content, &block
|
47
|
+
end
|
31
48
|
|
32
|
-
|
33
|
-
File.join(migration_dir, "#{number}_#{name}.rb")
|
34
|
-
end
|
49
|
+
aliases_for :migration
|
35
50
|
end
|
36
51
|
end
|
@@ -1,30 +1,40 @@
|
|
1
1
|
module RSpec::Rails
|
2
|
-
module Model
|
3
|
-
include RSpec::Rails::
|
2
|
+
module Model
|
3
|
+
include RSpec::Rails::BaseHelper
|
4
|
+
|
5
|
+
def model_file_name name, options=nil
|
6
|
+
artifact_path name, :model
|
7
|
+
end
|
4
8
|
|
5
|
-
def create_model name,
|
6
|
-
|
7
|
-
unless File.exist?(file)
|
8
|
-
FileUtils.mkdir_p File.dirname(file)
|
9
|
-
File.open(file, 'w') do |f|
|
10
|
-
raise "You must include an ORM helper in your model spec, fx: include RSpec::Rails::Orm::ActiveRecord" if !respond_to? :file_content
|
11
|
-
f.puts file_content(name, type)
|
12
|
-
yield f if block_given?
|
13
|
-
end
|
14
|
-
end
|
9
|
+
def create_model name, options={}, &block
|
10
|
+
create_artifact(name, set(options, :model), &block)
|
15
11
|
end
|
16
12
|
|
13
|
+
def insert_into_model(name, options={}, &block)
|
14
|
+
insert_content(name, set(options, :model), &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def read_model(name, options={}, &block)
|
18
|
+
read_artifact(name, set(options, :model), &block)
|
19
|
+
end
|
20
|
+
|
17
21
|
def remove_model name
|
18
|
-
|
19
|
-
FileUtils.rm_f(file) if File.exist?(file)
|
22
|
+
remove_artifact name, :model
|
20
23
|
end
|
21
24
|
|
22
25
|
def remove_models *names
|
23
|
-
|
24
|
-
end
|
26
|
+
remove_artifacts :model, *names
|
27
|
+
end
|
28
|
+
|
29
|
+
def model_marker name, options={}
|
30
|
+
return send :orm_marker_name, options[:model_type] if respond_to?(:orm_marker_name)
|
31
|
+
name.camelize
|
32
|
+
end
|
33
|
+
|
34
|
+
aliases_for :model
|
25
35
|
|
26
|
-
def
|
27
|
-
|
28
|
-
end
|
36
|
+
def orm_notify
|
37
|
+
". You must specify an ORM with the macro use_orm, f.ex -- use_orm :active_record"
|
38
|
+
end
|
29
39
|
end
|
30
40
|
end
|
@@ -1,35 +1,39 @@
|
|
1
1
|
module RSpec::Rails
|
2
|
-
module Observer
|
3
|
-
include RSpec::Rails::
|
4
|
-
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
f.puts observer_content(name, content)
|
12
|
-
end
|
13
|
-
end
|
2
|
+
module Observer
|
3
|
+
include RSpec::Rails::BaseHelper
|
4
|
+
|
5
|
+
def observer_file_name name, options=nil
|
6
|
+
artifact_path name, :observer
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_observer name, options={}, &block
|
10
|
+
create_artifact(name, set(options, :observer), &block)
|
14
11
|
end
|
15
12
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
def insert_into_observer(name, options={}, &block)
|
14
|
+
insert_content(name, set(options, :observer), &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def read_observer(name, options={}, &block)
|
18
|
+
read_artifact(name, set(options, :observer), &block)
|
20
19
|
end
|
21
20
|
|
22
21
|
def remove_observer name
|
23
|
-
|
24
|
-
FileUtils.rm_f(file) if File.exist?(file)
|
22
|
+
remove_artifact name, :observer
|
25
23
|
end
|
26
24
|
|
27
|
-
def remove_observers *names
|
28
|
-
|
25
|
+
def remove_observers *names
|
26
|
+
remove_artifacts :observer, *names
|
29
27
|
end
|
28
|
+
|
29
|
+
def observer_marker name, options=nil
|
30
|
+
"#{name.to_s.camelize}Observer < ActiveRecord::Observer"
|
31
|
+
end
|
32
|
+
|
33
|
+
def new_observer_content name, content=nil, &block
|
34
|
+
new_artifact_content name, :observer, content, &block
|
35
|
+
end
|
30
36
|
|
31
|
-
|
32
|
-
File.join(observer_dir, "#{name}_observer.rb")
|
33
|
-
end
|
37
|
+
aliases_for :observer
|
34
38
|
end
|
35
39
|
end
|
@@ -3,10 +3,14 @@ require 'generator_spec/rails_helpers/rails_model'
|
|
3
3
|
module RSpec::Rails
|
4
4
|
module Orm
|
5
5
|
module Base
|
6
|
-
include RSpec::Rails::Model
|
6
|
+
include RSpec::Rails::Model
|
7
7
|
|
8
8
|
protected
|
9
9
|
|
10
|
+
def orm_marker_name type = :document
|
11
|
+
document_name type
|
12
|
+
end
|
13
|
+
|
10
14
|
def document_name type
|
11
15
|
type_content = type == :document ? "#{orm_name}::Document" : "#{orm_name}::EmbeddedDocument"
|
12
16
|
end
|
@@ -15,19 +19,21 @@ module RSpec::Rails
|
|
15
19
|
"class #{name.to_s.camelize}"
|
16
20
|
end
|
17
21
|
|
18
|
-
def file name
|
22
|
+
def file name, include_stmt, &block
|
19
23
|
%Q{#{clazz name}
|
20
|
-
|
21
|
-
|
24
|
+
#{include_stmt}
|
25
|
+
#{yield if block}
|
26
|
+
end}
|
22
27
|
end
|
23
28
|
|
24
|
-
def file_w_include name
|
25
|
-
file name
|
29
|
+
def file_w_include name, module_name, &block
|
30
|
+
file name, "include #{module_name}", &block
|
26
31
|
end
|
27
32
|
|
28
|
-
def file_w_inherit name
|
29
|
-
%Q{#{clazz name} < #{
|
30
|
-
|
33
|
+
def file_w_inherit name, module_name, &block
|
34
|
+
%Q{#{clazz name} < #{module_name}
|
35
|
+
#{yield if block}
|
36
|
+
end}
|
31
37
|
end
|
32
38
|
|
33
39
|
def field name, type = nil
|
@@ -39,8 +45,12 @@ module RSpec::Rails
|
|
39
45
|
module ActiveRecord
|
40
46
|
include RSpec::Rails::Orm::Base
|
41
47
|
|
42
|
-
def
|
43
|
-
|
48
|
+
def orm_marker_name type=nil
|
49
|
+
'ActiveRecord::Base'
|
50
|
+
end
|
51
|
+
|
52
|
+
def new_model_content name, type=nil, content
|
53
|
+
file_w_inherit(name, orm_marker_name(type)) { content }
|
44
54
|
end
|
45
55
|
end
|
46
56
|
|
@@ -49,9 +59,10 @@ module RSpec::Rails
|
|
49
59
|
|
50
60
|
def orm_name
|
51
61
|
'MongoMapper'
|
52
|
-
end
|
53
|
-
|
54
|
-
|
62
|
+
end
|
63
|
+
|
64
|
+
def new_model_content name, type = :document
|
65
|
+
file_w_include(name, orm_marker_name(type)) { content }
|
55
66
|
end
|
56
67
|
|
57
68
|
def field_name
|
@@ -70,8 +81,8 @@ module RSpec::Rails
|
|
70
81
|
'field'
|
71
82
|
end
|
72
83
|
|
73
|
-
def
|
74
|
-
file_w_include(name) {
|
84
|
+
def new_model_content name, type = :document
|
85
|
+
file_w_include(name, orm_marker_name(type)) { content }
|
75
86
|
end
|
76
87
|
|
77
88
|
def field name, type = nil
|
@@ -87,8 +98,12 @@ module RSpec::Rails
|
|
87
98
|
'DataMapper'
|
88
99
|
end
|
89
100
|
|
90
|
-
def
|
91
|
-
|
101
|
+
def orm_marker_name type=nil
|
102
|
+
"#{orm_name}::Resource"
|
103
|
+
end
|
104
|
+
|
105
|
+
def new_model_content name
|
106
|
+
file_w_include(name, orm_marker_name(type)) { content }
|
92
107
|
end
|
93
108
|
|
94
109
|
def field_name
|