generator-spec 0.4.5 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +58 -46
- data/VERSION +1 -1
- data/generator-spec.gemspec +83 -14
- data/lib/generator_spec/helpers/migration_helper.rb +2 -2
- data/lib/generator_spec/main.rb +5 -0
- data/lib/generator_spec/matchers/content/content_matcher.rb +84 -4
- data/lib/generator_spec/matchers/content/have_block.rb +24 -22
- data/lib/generator_spec/matchers/content/have_call.rb +21 -13
- data/lib/generator_spec/matchers/content/have_calls.rb +32 -26
- data/lib/generator_spec/matchers/content/have_class_self.rb +40 -0
- data/lib/generator_spec/matchers/content/have_method.rb +31 -24
- data/lib/generator_spec/matchers/content/have_module.rb +49 -19
- data/lib/generator_spec/matchers/content/have_region.rb +9 -10
- data/lib/generator_spec/matchers/content/have_subclass.rb +9 -15
- data/lib/generator_spec/matchers/content/include_module.rb +9 -10
- data/lib/generator_spec/matchers/content/inherit_from.rb +10 -10
- data/lib/generator_spec/matchers/file/generate_file.rb +4 -11
- data/lib/generator_spec/matchers/file/generate_migration.rb +1 -5
- data/lib/generator_spec/matchers/file/have_file.rb +115 -0
- data/lib/generator_spec/rails_helpers/rails_controller.rb +30 -32
- data/lib/generator_spec/rails_helpers/rails_model.rb +2 -1
- data/lib/generator_spec/rails_helpers/rails_view.rb +19 -3
- data/spec/generator_spec/{controller_generator_spec.rb → generators/controller_generator_spec.rb} +0 -0
- data/spec/generator_spec/{helper_generator_spec.rb → generators/helper_generator_spec.rb} +0 -0
- data/spec/generator_spec/{migration_generator_spec.rb → generators/migration_generator_spec.rb} +0 -0
- data/spec/generator_spec/{model_generator_spec.rb → generators/model_generator_spec.rb} +0 -0
- data/spec/generator_spec/{observer_generator_spec.rb → generators/observer_generator_spec.rb} +0 -0
- data/spec/generator_spec/{view_generator_spec.rb → generators/view_generator_spec.rb} +0 -0
- data/spec/generator_spec/matchers/content/class_self_spec.rb +32 -0
- data/spec/generator_spec/matchers/content/have_block_spec.rb +57 -0
- data/spec/generator_spec/matchers/content/have_call_spec.rb +39 -0
- data/spec/generator_spec/matchers/content/have_calls_spec.rb +50 -0
- data/spec/generator_spec/matchers/content/have_class_spec.rb +34 -0
- data/spec/generator_spec/matchers/content/have_method_spec.rb +52 -0
- data/spec/generator_spec/matchers/content/have_module_spec.rb +34 -0
- data/spec/generator_spec/matchers/content/have_region_spec.rb +56 -0
- data/spec/generator_spec/matchers/content/have_subclass_spec.rb +34 -0
- data/spec/generator_spec/matchers/content/include_module_spec.rb +36 -0
- data/spec/generator_spec/matchers/content/inherit_from_spec.rb +34 -0
- data/spec/generator_spec/matchers/file/directory_spec.rb +0 -0
- data/spec/generator_spec/matchers/file/file_spec.rb +0 -0
- data/spec/generator_spec/matchers/file/migration_spec.rb +0 -0
- data/spec/generator_spec/matchers/migration/have_column_spec.rb +0 -0
- data/spec/generator_spec/matchers/migration/have_index_spec.rb +0 -0
- data/spec/generator_spec/matchers/migration/have_table_spec.rb +0 -0
- data/spec/generator_spec/matchers/migration/have_tbl_column_spec.rb +0 -0
- data/spec/generator_spec/matchers/migration/have_up_down_spec.rb +0 -0
- data/spec/generator_spec/matchers/rails/controller_matcher_spec.rb +26 -0
- data/spec/generator_spec/matchers/rails/helper_matcher_spec.rb +26 -0
- data/spec/generator_spec/matchers/rails/mailer_matcher_spec.rb +24 -0
- data/spec/generator_spec/matchers/rails/model_matcher_spec.rb +31 -0
- data/spec/generator_spec/matchers/rails/observer_matcher_spec.rb +19 -0
- data/spec/generator_spec/matchers/rails/view_matcher_spec.rb +23 -0
- data/spec/generator_spec/rails_helpers/rails_app_spec.rb +0 -0
- data/spec/generator_spec/rails_helpers/rails_controller_spec.rb +0 -0
- data/spec/generator_spec/rails_helpers/rails_helper_spec.rb +0 -0
- data/spec/generator_spec/rails_helpers/rails_mailer_spec.rb +0 -0
- data/spec/generator_spec/rails_helpers/rails_migration_spec.rb +0 -0
- data/spec/generator_spec/rails_helpers/rails_model_spec.rb +0 -0
- data/spec/generator_spec/rails_helpers/rails_observer_spec.rb +0 -0
- data/spec/generator_spec/rails_helpers/rails_orm_spec.rb +0 -0
- data/spec/generator_spec/rails_helpers/rails_view_spec.rb +0 -0
- metadata +84 -15
- data/lib/generator_spec/matchers/content/have_class.rb +0 -53
@@ -7,53 +7,60 @@
|
|
7
7
|
#
|
8
8
|
module RSpec::RubyContentMatchers
|
9
9
|
class HaveMethod < RSpec::RubyContentMatcher
|
10
|
-
attr_reader :method, :type
|
10
|
+
attr_reader :method, :type, :args
|
11
11
|
|
12
|
-
def initialize(method, type=nil)
|
12
|
+
def initialize(method, type=nil, options = {})
|
13
13
|
@method = method.to_s
|
14
|
+
super method
|
14
15
|
@type = type
|
16
|
+
@args = options[:args]
|
15
17
|
end
|
16
18
|
|
17
|
-
def
|
18
|
-
|
19
|
-
match_res = case type
|
20
|
-
when :class
|
21
|
-
content =~ /def\s+self.#{method}#{args_expr}(.*?)#{end_expr}/m
|
22
|
-
else
|
23
|
-
content =~ /def\s+#{method}#{args_expr}(.*?)#{end_expr}/m
|
24
|
-
end
|
25
|
-
if block_given? && $2
|
26
|
-
ruby_content = $2.strip.extend(RSpec::RubyContent::Helpers)
|
27
|
-
ruby_content << "\nend" if !(ruby_content =~ /\nend$/)
|
28
|
-
yield ruby_content
|
29
|
-
end
|
30
|
-
match_res
|
19
|
+
def index
|
20
|
+
1
|
31
21
|
end
|
32
22
|
|
33
23
|
def failure_message
|
34
24
|
super
|
35
|
-
|
36
|
-
"Expected there to be the method #{method}, but there wasn't"
|
25
|
+
"Expected there to be the #{class_msg} method #{method}, but there wasn't"
|
37
26
|
end
|
38
27
|
|
39
28
|
def negative_failure_message
|
40
29
|
super
|
41
|
-
|
42
|
-
"Did not expect there to be the method #{method}, but there was"
|
30
|
+
"Did not expect there to be the #{class_msg} method #{method}, but there was"
|
43
31
|
end
|
44
32
|
|
45
33
|
protected
|
46
34
|
|
35
|
+
def class_msg
|
36
|
+
(type == :class) ? 'class' : ''
|
37
|
+
end
|
38
|
+
|
39
|
+
def main_expr
|
40
|
+
'def' + SPACES + "#{self_expr}#{method}#{args_expr}" + ANY_GROUP
|
41
|
+
end
|
42
|
+
|
47
43
|
def args_expr
|
48
|
-
|
44
|
+
return super if args
|
45
|
+
any_args_expr
|
49
46
|
end
|
50
|
-
|
51
|
-
def
|
52
|
-
|
47
|
+
|
48
|
+
def self_expr
|
49
|
+
type == :class ? 'self.' : ''
|
53
50
|
end
|
51
|
+
|
52
|
+
def alt_end
|
53
|
+
'def'
|
54
|
+
end
|
55
|
+
|
54
56
|
end
|
55
57
|
|
56
58
|
def have_method(method, type = nil)
|
57
59
|
HaveMethod.new(method, type)
|
58
60
|
end
|
61
|
+
|
62
|
+
def have_args_method(method, options = {})
|
63
|
+
HaveMethod.new(method, options[:type], options)
|
64
|
+
end
|
65
|
+
|
59
66
|
end
|
@@ -1,36 +1,66 @@
|
|
1
1
|
module RSpec::RubyContentMatchers
|
2
2
|
class HaveModule < RSpec::RubyContentMatcher
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :name, :type, :postfix
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(name, postfix=nil)
|
6
|
+
@name = name.to_s.camelize
|
7
|
+
super @name
|
8
|
+
@postfix = postfix.to_s.camelize if postfix
|
9
|
+
@type = :module
|
7
10
|
end
|
8
|
-
|
9
|
-
def matches?(content)
|
10
|
-
super
|
11
|
-
match_res =~ /module\s+#{module_name}\s+(.*)end/m
|
12
|
-
if block_given? && match_res
|
13
|
-
ruby_content = $2.strip.extend(RSpec::RubyContent::Helpers)
|
14
|
-
yield ruby_content
|
15
|
-
else
|
16
|
-
match_res
|
17
|
-
end
|
18
|
-
end
|
19
11
|
|
20
12
|
def failure_message
|
21
13
|
super
|
22
|
-
"Expected there to be the
|
14
|
+
"Expected there to be the #{type} #{name}"
|
23
15
|
end
|
24
16
|
|
25
17
|
def negative_failure_message
|
26
18
|
super
|
27
|
-
"Did
|
19
|
+
"Did not expected there to be the #{type} #{name}"
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def main_expr
|
25
|
+
"#{type}" + SPACES + "#{name}#{postfix}" + SPACES + ANY_GROUP
|
28
26
|
end
|
29
|
-
|
27
|
+
|
28
|
+
def alt_end
|
29
|
+
type
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class HaveClass < HaveModule
|
34
|
+
|
35
|
+
def initialize(name, postfix)
|
36
|
+
super name, postfix
|
37
|
+
@type = :class
|
38
|
+
end
|
30
39
|
end
|
31
40
|
|
32
|
-
def have_module(module_name)
|
33
|
-
HaveModule.new(module_name)
|
41
|
+
def have_module(module_name, postfix=nil)
|
42
|
+
HaveModule.new(module_name, postfix)
|
34
43
|
end
|
35
44
|
alias_method :be_module, :have_module
|
45
|
+
|
46
|
+
def have_class(module_name)
|
47
|
+
HaveModule.new(module_name, :class)
|
48
|
+
end
|
49
|
+
|
50
|
+
def have_class(klass, postfix = nil)
|
51
|
+
HaveClass.new(klass, postfix)
|
52
|
+
end
|
53
|
+
alias_method :be_class, :have_class
|
54
|
+
|
55
|
+
def have_helper_class(klass)
|
56
|
+
HaveClass.new(klass, :helper)
|
57
|
+
end
|
58
|
+
alias_method :be_helper_class, :have_helper_class
|
59
|
+
|
60
|
+
|
61
|
+
def have_controller_class(klass)
|
62
|
+
HaveClass.new(klass, :controller)
|
63
|
+
end
|
64
|
+
alias_method :be_controller_class, :have_controller_class
|
65
|
+
|
36
66
|
end
|
@@ -4,17 +4,8 @@ module RSpec::RubyContentMatchers
|
|
4
4
|
|
5
5
|
def initialize(region)
|
6
6
|
@region = region.to_s
|
7
|
+
super @region
|
7
8
|
end
|
8
|
-
|
9
|
-
def matches?(content)
|
10
|
-
super
|
11
|
-
match_res = (content =~ /#{region}(.*)#{end_epxr}/m)
|
12
|
-
if block_given? && $1
|
13
|
-
ruby_content = $1.strip.extend(RSpec::RubyContent::Helpers)
|
14
|
-
yield ruby_content
|
15
|
-
end
|
16
|
-
match_res
|
17
|
-
end
|
18
9
|
|
19
10
|
def failure_message
|
20
11
|
super
|
@@ -27,11 +18,19 @@ module RSpec::RubyContentMatchers
|
|
27
18
|
end
|
28
19
|
|
29
20
|
protected
|
21
|
+
|
22
|
+
def main_expr
|
23
|
+
"#{region}" + ANY_GROUP
|
24
|
+
end
|
30
25
|
|
31
26
|
def end_expr
|
32
27
|
'(private|protected|public|$)'
|
33
28
|
end
|
34
29
|
end
|
30
|
+
|
31
|
+
def have_region name
|
32
|
+
HaveRegion.new name
|
33
|
+
end
|
35
34
|
|
36
35
|
def have_public
|
37
36
|
HaveRegion.new :public
|
@@ -3,22 +3,12 @@ module RSpec::RubyContentMatchers
|
|
3
3
|
attr_reader :klass, :superclass, :type
|
4
4
|
|
5
5
|
def initialize(klass, superclass, type=nil)
|
6
|
-
@klass = klass.to_s.camelize
|
6
|
+
@klass = klass.to_s.camelize
|
7
|
+
super @klass
|
7
8
|
@superclass = superclass.to_s.camelize
|
8
9
|
@type = type.to_s.camelize if type
|
9
10
|
end
|
10
11
|
|
11
|
-
def matches?(content)
|
12
|
-
super
|
13
|
-
match_res = (content =~ /class\s+#{klass}#{type}\s+<\s+#{superclass}(.*)#{end_expr}/m)
|
14
|
-
if block_given? && $1
|
15
|
-
ruby_content = $1.strip.extend(RSpec::RubyContent::Helpers)
|
16
|
-
yield ruby_content
|
17
|
-
else
|
18
|
-
match_res
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
12
|
def failure_message
|
23
13
|
super
|
24
14
|
"Expected there to be the subclass #{klass} of #{superclass}"
|
@@ -29,10 +19,14 @@ module RSpec::RubyContentMatchers
|
|
29
19
|
"Did no expected there to be the subclass #{klass} of #{superclass}"
|
30
20
|
end
|
31
21
|
|
32
|
-
protected
|
22
|
+
protected
|
23
|
+
|
24
|
+
def main_expr
|
25
|
+
'class' + SPACES + "#{klass}#{type}" + OPT_SPACES + '<' + OPT_SPACES + "#{superclass}" + ANY_GROUP
|
26
|
+
end
|
33
27
|
|
34
|
-
def
|
35
|
-
|
28
|
+
def alt_end
|
29
|
+
'class'
|
36
30
|
end
|
37
31
|
|
38
32
|
end
|
@@ -1,20 +1,15 @@
|
|
1
1
|
module RSpec::RubyContentMatchers
|
2
2
|
class IncludeModule < RSpec::RubyContentMatcher
|
3
|
-
attr_reader :module_name
|
3
|
+
attr_reader :module_name, :type
|
4
4
|
|
5
|
-
def initialize module_name
|
5
|
+
def initialize module_name, type=nil
|
6
6
|
@module_name = module_name.to_s.camelize
|
7
|
+
@type = type || :include
|
7
8
|
end
|
8
9
|
|
9
10
|
def matches?(content)
|
10
|
-
|
11
|
-
|
12
|
-
if block_given? && match_res
|
13
|
-
ruby_content = content.extend(RSpec::RubyContent::Helpers)
|
14
|
-
yield ruby_content
|
15
|
-
else
|
16
|
-
match_res
|
17
|
-
end
|
11
|
+
@content = content
|
12
|
+
(content =~ /#{type}\s+#{module_name}/)
|
18
13
|
end
|
19
14
|
|
20
15
|
def failure_message
|
@@ -33,6 +28,10 @@ module RSpec::RubyContentMatchers
|
|
33
28
|
IncludeModule.new(module_name)
|
34
29
|
end
|
35
30
|
|
31
|
+
def extend_module(module_name)
|
32
|
+
IncludeModule.new(module_name, :extend)
|
33
|
+
end
|
34
|
+
|
36
35
|
def be_dm_resource
|
37
36
|
IncludeModule.new 'DataMapper::Resource'
|
38
37
|
end
|
@@ -4,18 +4,12 @@ module RSpec::RubyContentMatchers
|
|
4
4
|
|
5
5
|
def initialize klass
|
6
6
|
@klass = klass.to_s.camelize
|
7
|
+
super @klass
|
7
8
|
end
|
8
9
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
if block_given? && match_res
|
13
|
-
ruby_content = $2.strip.extend(RSpec::RubyContent::Helpers)
|
14
|
-
yield ruby_content
|
15
|
-
else
|
16
|
-
match_res
|
17
|
-
end
|
18
|
-
end
|
10
|
+
def index
|
11
|
+
1
|
12
|
+
end
|
19
13
|
|
20
14
|
def failure_message
|
21
15
|
super
|
@@ -26,6 +20,12 @@ module RSpec::RubyContentMatchers
|
|
26
20
|
super
|
27
21
|
"Did not expect the class to inherit from #{klass}"
|
28
22
|
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def main_expr
|
27
|
+
'class' + SPACES + Q_ANY_GROUP + '<' + OPT_SPACES + "#{klass}" + ANY_GROUP
|
28
|
+
end
|
29
29
|
end
|
30
30
|
|
31
31
|
def inherit_from(klass)
|
@@ -5,15 +5,15 @@
|
|
5
5
|
#
|
6
6
|
|
7
7
|
module RSpec::FileMatchers
|
8
|
-
class GenerateFile
|
9
|
-
|
8
|
+
class GenerateFile
|
10
9
|
attr_accessor :relative_path
|
11
10
|
|
12
11
|
def initialize(relative_path, type = nil)
|
13
12
|
@relative_path = relative_rails_file(relative_path, type)
|
14
13
|
end
|
15
14
|
|
16
|
-
def matches?(generator, &block)
|
15
|
+
def matches?(generator, &block)
|
16
|
+
puts "relative_path"
|
17
17
|
file = File.expand_path(relative_path, generator.class.destination_root)
|
18
18
|
file_exists = File.exists?(file)
|
19
19
|
if block && file_exists
|
@@ -80,32 +80,25 @@ module RSpec::FileMatchers
|
|
80
80
|
def generate_file(relative, type = nil)
|
81
81
|
GenerateFile.new(relative, type)
|
82
82
|
end
|
83
|
-
alias_method :have_file, :generate_file
|
84
83
|
|
85
84
|
def generate_model(relative)
|
86
85
|
GenerateFile.new(relative, :model)
|
87
86
|
end
|
88
|
-
alias_method :have_model, :generate_model
|
89
87
|
|
90
88
|
def generate_controller(relative)
|
91
|
-
puts "Generate controller: #{relative}"
|
92
89
|
GenerateFile.new(relative, :controller)
|
93
90
|
end
|
94
|
-
alias_method :have_controller, :generate_controller
|
95
91
|
|
96
92
|
def generate_helper(relative)
|
97
93
|
GenerateFile.new(relative, :helper)
|
98
94
|
end
|
99
|
-
alias_method :have_helper, :generate_helper
|
100
95
|
|
101
96
|
def generate_view(relative, action, ext)
|
102
97
|
GenerateFile.new("#{relative}/#{action}.#{ext}", :view)
|
103
98
|
end
|
104
|
-
alias_method :have_view, :generate_view
|
105
99
|
|
106
100
|
def generate_observer(relative)
|
107
101
|
GenerateFile.new(relative, :observer)
|
108
|
-
end
|
109
|
-
alias_method :have_observer, :generate_observer
|
102
|
+
end
|
110
103
|
end
|
111
104
|
|
@@ -41,11 +41,7 @@ module RSpec
|
|
41
41
|
dirname = migration_dir
|
42
42
|
file_name = relative.sub(/\.rb$/, '')
|
43
43
|
migrations = Dir.glob("#{dirname}/[0-9]*_*.rb")
|
44
|
-
|
45
|
-
migrations.grep(/\d+_#{file_name}\.rb$/).first
|
46
|
-
else
|
47
|
-
false
|
48
|
-
end
|
44
|
+
!migrations.empty? ? migrations.grep(/\d+_#{file_name}\.rb$/).first : false
|
49
45
|
end
|
50
46
|
|
51
47
|
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# Asserts a given file exists. You need to supply an absolute path or a path relative
|
2
|
+
# to the configured destination:
|
3
|
+
#
|
4
|
+
# generator.should have_generated_file "app/controller/products_controller.rb"
|
5
|
+
#
|
6
|
+
|
7
|
+
module RSpec::FileMatchers
|
8
|
+
class HaveFile
|
9
|
+
attr_accessor :relative_path
|
10
|
+
|
11
|
+
def initialize(relative_path, type = nil)
|
12
|
+
@relative_path = relative_rails_file(relative_path, type)
|
13
|
+
end
|
14
|
+
|
15
|
+
def matches?(generator, &block)
|
16
|
+
file = File.expand_path(relative_path, Rails.root)
|
17
|
+
file_exists = File.exists?(file)
|
18
|
+
if block && file_exists
|
19
|
+
read = File.read(file)
|
20
|
+
ruby_content = read.extend(RSpec::RubyContent::Helpers)
|
21
|
+
yield ruby_content
|
22
|
+
else
|
23
|
+
file_exists
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def failure_message
|
28
|
+
"Expected file #{relative_path} to have been generated, but it was not"
|
29
|
+
end
|
30
|
+
|
31
|
+
def negative_failure_message
|
32
|
+
"Did not expected file #{relative_path} to have been generated, but it was"
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def relative_rails_file path, type = nil
|
38
|
+
path = path.to_s
|
39
|
+
f_name = file_name(path, type)
|
40
|
+
return File.join(::Rails.root, base_dir(type), folder(type), f_name) if type
|
41
|
+
File.join(::Rails.root, path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def file_name path, type
|
45
|
+
return "#{path}#{postfix(type)}.rb" if !path.include? '.'
|
46
|
+
path
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def postfix type
|
51
|
+
"_#{type}" if [:helper, :controller, :observer].include?(type)
|
52
|
+
end
|
53
|
+
|
54
|
+
def folder type
|
55
|
+
case type
|
56
|
+
when :observer
|
57
|
+
'models'
|
58
|
+
else
|
59
|
+
type.to_s.pluralize
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def base_dir type
|
64
|
+
case type
|
65
|
+
when :model, :controller, :view, :helper, :observer, :mailer
|
66
|
+
'app'
|
67
|
+
when :migration
|
68
|
+
'db'
|
69
|
+
when :javascript, :stylesheet
|
70
|
+
'public'
|
71
|
+
when :initializer, :locale
|
72
|
+
'config'
|
73
|
+
else
|
74
|
+
''
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def have_file(relative, type = nil)
|
80
|
+
HaveFile.new(relative, type)
|
81
|
+
end
|
82
|
+
alias_method :contain_file, :have_file
|
83
|
+
|
84
|
+
def have_model(relative)
|
85
|
+
HaveFile.new(relative, :model)
|
86
|
+
end
|
87
|
+
alias_method :contain_model, :have_model
|
88
|
+
|
89
|
+
def have_controller(relative)
|
90
|
+
HaveFile.new(relative, :controller)
|
91
|
+
end
|
92
|
+
alias_method :contain_controller, :have_controller
|
93
|
+
|
94
|
+
def have_helper(relative)
|
95
|
+
HaveFile.new(relative, :helper)
|
96
|
+
end
|
97
|
+
alias_method :contain_helper, :have_helper
|
98
|
+
|
99
|
+
def have_view(relative, action, ext='html.erb')
|
100
|
+
HaveFile.new("#{relative}/#{action}.#{ext}", :view)
|
101
|
+
end
|
102
|
+
alias_method :contain_view, :have_view
|
103
|
+
|
104
|
+
def have_observer(relative)
|
105
|
+
HaveFile.new(relative, :observer)
|
106
|
+
end
|
107
|
+
alias_method :contain_observer, :have_observer
|
108
|
+
|
109
|
+
def have_mailer(relative)
|
110
|
+
HaveFile.new(relative, :mailer)
|
111
|
+
end
|
112
|
+
alias_method :contain_mailer, :have_mailer
|
113
|
+
|
114
|
+
end
|
115
|
+
|
@@ -1,38 +1,36 @@
|
|
1
|
-
module RSpec
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
f.puts controller_content(name, content)
|
13
|
-
end
|
1
|
+
module RSpec::Rails
|
2
|
+
module Controller
|
3
|
+
include RSpec::Rails::App
|
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)
|
14
12
|
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def controller_content name, content=nil
|
18
|
-
%Q{class #{name.to_s.camelize}Controller < ActionController::Base
|
19
|
-
#{content}
|
20
|
-
end}
|
21
13
|
end
|
14
|
+
end
|
22
15
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
16
|
+
def controller_content name, content=nil
|
17
|
+
%Q{class #{name.to_s.camelize}Controller < ActionController::Base
|
18
|
+
#{content}
|
19
|
+
end}
|
20
|
+
end
|
27
21
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def controller_file_name name
|
33
|
-
File.join(controller_dir, "#{name}_controller.rb")
|
34
|
-
end
|
35
|
-
|
22
|
+
def remove_controller name
|
23
|
+
file = controller_file_name(name)
|
24
|
+
FileUtils.rm_f(file) if File.exist?(file)
|
36
25
|
end
|
26
|
+
|
27
|
+
def remove_controllers *names
|
28
|
+
names.each{|name| remove_controller name }
|
29
|
+
end
|
30
|
+
|
31
|
+
def controller_file_name name
|
32
|
+
File.join(controller_dir, "#{name}_controller.rb")
|
33
|
+
end
|
34
|
+
|
37
35
|
end
|
38
|
-
end
|
36
|
+
end
|
@@ -6,7 +6,8 @@ module RSpec::Rails
|
|
6
6
|
file = model_file_name(name)
|
7
7
|
unless File.exist?(file)
|
8
8
|
FileUtils.mkdir_p File.dirname(file)
|
9
|
-
File.open(file, 'w') do |f|
|
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
|
10
11
|
f.puts file_content(name, type)
|
11
12
|
yield f if block_given?
|
12
13
|
end
|
@@ -2,7 +2,8 @@ module RSpec::Rails
|
|
2
2
|
module View
|
3
3
|
include RSpec::Rails::App
|
4
4
|
|
5
|
-
def create_view name, action,
|
5
|
+
def create_view name, action='show', *args
|
6
|
+
type, content = parse_args(*args)
|
6
7
|
file = view_file_name(name, action, type)
|
7
8
|
unless File.exist?(file)
|
8
9
|
FileUtils.mkdir_p File.dirname(file)
|
@@ -14,12 +15,27 @@ module RSpec::Rails
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
+
def parse_args *args
|
19
|
+
type='html.erb'
|
20
|
+
content=nil
|
21
|
+
if args && args[0]
|
22
|
+
case args[0]
|
23
|
+
when String
|
24
|
+
content = args[0]
|
25
|
+
when Symbol
|
26
|
+
type = args[0]
|
27
|
+
content = args[1] if args.size > 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
[type, content]
|
31
|
+
end
|
32
|
+
|
33
|
+
def remove_view name, action='show', type='html.erb'
|
18
34
|
file = view_file_name(name, action, type)
|
19
35
|
FileUtils.rm_f(file) if File.exist?(file)
|
20
36
|
end
|
21
37
|
|
22
|
-
def view_file_name name, action, type
|
38
|
+
def view_file_name name, action='show', type='html.erb'
|
23
39
|
File.join(view_dir, name.to_s, "#{action}.#{type}")
|
24
40
|
end
|
25
41
|
|
data/spec/generator_spec/{controller_generator_spec.rb → generators/controller_generator_spec.rb}
RENAMED
File without changes
|
File without changes
|
data/spec/generator_spec/{migration_generator_spec.rb → generators/migration_generator_spec.rb}
RENAMED
File without changes
|
File without changes
|
data/spec/generator_spec/{observer_generator_spec.rb → generators/observer_generator_spec.rb}
RENAMED
File without changes
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe 'class_self matcher' do
|
4
|
+
context "content without class << self" do
|
5
|
+
not_class_self = %q{
|
6
|
+
def hello
|
7
|
+
end}
|
8
|
+
|
9
|
+
it "should not have class << self" do
|
10
|
+
not_class_self.should_not have_class_self do |content|
|
11
|
+
puts content
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "content with class << self" do
|
17
|
+
class_self = %q{
|
18
|
+
class << self
|
19
|
+
def hello
|
20
|
+
end
|
21
|
+
end # class self}
|
22
|
+
|
23
|
+
it "should have class << self" do
|
24
|
+
class_self.should have_class_self do |content|
|
25
|
+
puts "content: #{content}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|