rapid-core 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/.gitignore +7 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +11 -0
  4. data/Gemfile.lock +53 -0
  5. data/Rakefile +61 -0
  6. data/cucumber.yml +3 -0
  7. data/doc/plan.txt +89 -0
  8. data/doc/scaffold/controller.rb +83 -0
  9. data/doc/scaffold/helper.rb +2 -0
  10. data/doc/scaffold/model.rb +5 -0
  11. data/doc/scaffold/rapid_scaffold.rb +5 -0
  12. data/doc/scaffold/views/_form.html.erb +25 -0
  13. data/doc/scaffold/views/edit.html.erb +6 -0
  14. data/doc/scaffold/views/index.html.erb +25 -0
  15. data/doc/scaffold/views/new.html.erb +5 -0
  16. data/doc/scaffold/views/show.html.erb +15 -0
  17. data/features/settings/boolean/default.feature +36 -0
  18. data/features/settings/double-nested/default.feature +50 -0
  19. data/features/settings/double-nested/if.feature +41 -0
  20. data/features/settings/double-nested/unless.feature +39 -0
  21. data/features/settings/double-nested/validates/exclusion_of.feature +30 -0
  22. data/features/settings/double-nested/validates/format_of.feature +30 -0
  23. data/features/settings/double-nested/validates/inclusion_of.feature +30 -0
  24. data/features/settings/double-nested/validates/length_of.feature +30 -0
  25. data/features/settings/double-nested/validates/presence_of.feature +37 -0
  26. data/features/settings/double-nested/validates/size_of.feature +30 -0
  27. data/features/settings/integer/default.feature +49 -0
  28. data/features/settings/nested/default.feature +50 -0
  29. data/features/settings/nested/if.feature +53 -0
  30. data/features/settings/nested/unless.feature +32 -0
  31. data/features/settings/nested/validates/exclusion_of.feature +30 -0
  32. data/features/settings/nested/validates/format_of.feature +30 -0
  33. data/features/settings/nested/validates/inclusion_of.feature +30 -0
  34. data/features/settings/nested/validates/length_of.feature +30 -0
  35. data/features/settings/nested/validates/presence_of.feature +37 -0
  36. data/features/settings/nested/validates/size_of.feature +30 -0
  37. data/features/settings/not_found.feature +33 -0
  38. data/features/settings/string/default.feature +36 -0
  39. data/features/settings/string/validates/exclusion_of.feature +30 -0
  40. data/features/settings/string/validates/format_of.feature +30 -0
  41. data/features/settings/string/validates/inclusion_of.feature +30 -0
  42. data/features/settings/string/validates/length_of.feature +30 -0
  43. data/features/settings/string/validates/presence_of.feature +37 -0
  44. data/features/settings/string/validates/size_of.feature +30 -0
  45. data/features/step_definitions/settings_steps.rb +92 -0
  46. data/features/step_definitions/skeleton_steps.rb +68 -0
  47. data/features/step_definitions/template_steps.rb +39 -0
  48. data/features/support/env.rb +6 -0
  49. data/features/templates/comment_if.feature +55 -0
  50. data/features/templates/comment_unless.feature +56 -0
  51. data/features/templates/for/for.feature +51 -0
  52. data/features/templates/if/else.feature +60 -0
  53. data/features/templates/if/elsif.feature +82 -0
  54. data/features/templates/if/if.feature +55 -0
  55. data/features/templates/namespaces/exist.feature +54 -0
  56. data/features/templates/static.feature +37 -0
  57. data/features/templates/variables.feature +61 -0
  58. data/lib/rapid/check.rb +162 -0
  59. data/lib/rapid/core.rb +37 -0
  60. data/lib/rapid/error.rb +84 -0
  61. data/lib/rapid/module.rb +35 -0
  62. data/lib/rapid/railtie.rb +18 -0
  63. data/lib/rapid/setting/base.rb +35 -0
  64. data/lib/rapid/setting/boolean_setting.rb +17 -0
  65. data/lib/rapid/setting/class_hash.rb +34 -0
  66. data/lib/rapid/setting/comments.rb +25 -0
  67. data/lib/rapid/setting/definer.rb +151 -0
  68. data/lib/rapid/setting/instance_hash.rb +132 -0
  69. data/lib/rapid/setting/instance_root.rb +107 -0
  70. data/lib/rapid/setting/integer_setting.rb +24 -0
  71. data/lib/rapid/setting/namespace/base.rb +113 -0
  72. data/lib/rapid/setting/namespace/instance.rb +84 -0
  73. data/lib/rapid/setting/nested_validations.rb +86 -0
  74. data/lib/rapid/setting/string_setting.rb +13 -0
  75. data/lib/rapid/settings.rb +129 -0
  76. data/lib/rapid/skeleton/base.rb +164 -0
  77. data/lib/rapid/skeleton/helpers/directory.rb +53 -0
  78. data/lib/rapid/skeleton/helpers/gem.rb +133 -0
  79. data/lib/rapid/skeleton/helpers/migration.rb +46 -0
  80. data/lib/rapid/skeleton/helpers/route.rb +115 -0
  81. data/lib/rapid/skeleton/helpers/script.rb +33 -0
  82. data/lib/rapid/skeleton/helpers/template.rb +73 -0
  83. data/lib/rapid/skeleton/helpers/view.rb +35 -0
  84. data/lib/rapid/spec/template.rb +104 -0
  85. data/lib/rapid/spec.rb +1 -0
  86. data/lib/rapid/tasks.rb +29 -0
  87. data/lib/rapid/template/base.rb +49 -0
  88. data/lib/rapid/template/node/base.rb +43 -0
  89. data/lib/rapid/template/node/comment_node.rb +42 -0
  90. data/lib/rapid/template/node/if_node.rb +109 -0
  91. data/lib/rapid/template/node/root.rb +51 -0
  92. data/lib/rapid/template/node/static.rb +29 -0
  93. data/lib/rapid/template/node/variable.rb +86 -0
  94. data/lib/rapid/template/parser.rb +167 -0
  95. data/lib/rapid/template/pulling/base.rb +91 -0
  96. data/lib/rapid/template/pulling/explicit.rb +92 -0
  97. data/lib/rapid/template/pulling/forgiving.rb +58 -0
  98. data/lib/rapid/version.rb +3 -0
  99. data/lib/rapid.rb +37 -0
  100. data/rapid-core.gemspec +26 -0
  101. data/spec/rapid/check_spec.rb +119 -0
  102. data/spec/rapid/error_spec.rb +14 -0
  103. data/spec/rapid/module_spec.rb +28 -0
  104. data/spec/rapid/setting/base_spec.rb +17 -0
  105. data/spec/rapid/setting/definer_spec.rb +318 -0
  106. data/spec/rapid/setting/instance_root_spec.rb +161 -0
  107. data/spec/rapid/setting/namespace/base_spec.rb +93 -0
  108. data/spec/rapid/setting/namespace/instance_spec.rb +12 -0
  109. data/spec/rapid/setting/nested_validations_spec.rb +72 -0
  110. data/spec/rapid/settings_spec.rb +51 -0
  111. data/spec/rapid/skeleton/base_spec.rb +224 -0
  112. data/spec/rapid/skeleton/helpers/directory_spec.rb +104 -0
  113. data/spec/rapid/skeleton/helpers/gem_spec.rb +180 -0
  114. data/spec/rapid/skeleton/helpers/migration_spec.rb +23 -0
  115. data/spec/rapid/skeleton/helpers/route_spec.rb +120 -0
  116. data/spec/rapid/skeleton/helpers/script_spec.rb +57 -0
  117. data/spec/rapid/skeleton/helpers/template_spec.rb +142 -0
  118. data/spec/rapid/skeleton/helpers/view_spec.rb +54 -0
  119. data/spec/rapid/spec/template_spec.rb +168 -0
  120. data/spec/rapid/template/base_spec.rb +290 -0
  121. data/spec/rapid/template/node/base_spec.rb +9 -0
  122. data/spec/rapid/template/node/comment_node_spec.rb +46 -0
  123. data/spec/rapid/template/node/if_node_spec.rb +28 -0
  124. data/spec/rapid/template/node/root_spec.rb +9 -0
  125. data/spec/rapid/template/node/static_spec.rb +17 -0
  126. data/spec/rapid/template/node/variable_spec.rb +87 -0
  127. data/spec/rapid/template/parser_spec.rb +187 -0
  128. data/spec/rapid/template/pulling/base_spec.rb +81 -0
  129. data/spec/rapid/template/pulling/explicit_spec.rb +33 -0
  130. data/spec/rapid/template/pulling/forgiving_spec.rb +132 -0
  131. data/spec/spec_helper.rb +10 -0
  132. metadata +325 -0
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ describe Rapid::Skeleton::Helpers::Script do
4
+
5
+ before do
6
+ Object.class_eval do
7
+ class MyClass
8
+ include Rapid::Skeleton::Helpers::Template
9
+ include Rapid::Skeleton::Helpers::Script
10
+
11
+ attr_accessor :templates_path, :project_path, :get_binding
12
+ end
13
+ end
14
+
15
+ @instance = MyClass.new
16
+ end
17
+
18
+ after do
19
+ Object.send(:remove_const, :MyClass) rescue nil
20
+ end
21
+
22
+ describe "push_script" do
23
+
24
+ before do
25
+ @instance.project_path = 'tmp'
26
+
27
+ @instance.stub!(:pushing?).and_return(true)
28
+ @instance.stub!(:pulling?).and_return(false)
29
+ end
30
+
31
+ it "should push_template and chmod it executable" do
32
+ @instance.should_receive(:push_template).with("script/test", {})
33
+ File.should_receive(:chmod).with(0755, 'tmp/script/test')
34
+
35
+ @instance.send :script, "script/test"
36
+ end
37
+
38
+ end
39
+
40
+ describe "pull_script" do
41
+
42
+ before do
43
+ @instance.project_path = 'tmp'
44
+
45
+ @instance.stub!(:pushing?).and_return(false)
46
+ @instance.stub!(:pulling?).and_return(true)
47
+ end
48
+
49
+ it "should delegate to pull_template" do
50
+ @instance.should_receive(:pull_template).with("script/test", {})
51
+
52
+ @instance.send :script, "script/test"
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,142 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ describe Rapid::Skeleton::Helpers::Template do
4
+
5
+ before do
6
+ Object.class_eval do
7
+ class MyClass
8
+ include Rapid::Skeleton::Helpers::Template
9
+
10
+ attr_accessor :templates_path, :project_path, :get_binding
11
+ end
12
+ end
13
+
14
+ @test_path = File.join 'tmp', 'test'
15
+ @templates_path = File.join @test_path, 'templates'
16
+ @project_path = File.join @test_path, 'project'
17
+
18
+ @instance = MyClass.new
19
+ @instance.templates_path = @templates_path
20
+ @instance.project_path = @project_path
21
+ end
22
+
23
+ after do
24
+ Object.send(:remove_const, :MyClass) rescue nil
25
+ FileUtils.rm_rf @test_path
26
+ end
27
+
28
+ def create_template filename, content
29
+ template_path = File.join @templates_path, filename
30
+
31
+ FileUtils.mkdir_p File.dirname(template_path)
32
+ File.open(template_path, 'w') {|f| f.write content }
33
+ end
34
+
35
+ def create_output filename, content
36
+ output_path = File.join @project_path, filename
37
+
38
+ FileUtils.mkdir_p File.dirname(output_path)
39
+ File.open(output_path, 'w') {|f| f.write content }
40
+ end
41
+
42
+ describe "push_template" do
43
+
44
+ before do
45
+ @instance.stub!(:pushing?).and_return(true)
46
+ @instance.stub!(:pulling?).and_return(false)
47
+ end
48
+
49
+ it "should render the template and write it to the given file" do
50
+ create_template 'db/migrate/01_create_users.rb', 'foo <%= 3 %> bar'
51
+ @instance.send :template, "db/migrate/01_create_users.rb", :to => "db/migrate/20120202030406_create_users.rb"
52
+
53
+ output_path = File.join @project_path, "db/migrate/20120202030406_create_users.rb"
54
+ File.open(output_path) {|f| f.read }.should == "foo 3 bar"
55
+ end
56
+
57
+ it "should write the rendered template to the template path if :to option is not given" do
58
+ create_template 'config/initializers/airbrake.rb', 'foo <%= 3 %> bar'
59
+ @instance.send :template, "config/initializers/airbrake.rb"
60
+
61
+ output_path = File.join @project_path, "config/initializers/airbrake.rb"
62
+ File.open(output_path) {|f| f.read }.should == "foo 3 bar"
63
+ end
64
+
65
+ it "should raise a template not found error when told to push an non-existing template" do
66
+ lambda { @instance.send :template, "db/migrate/01_create_users.rb", :to => "db/migrate/20120202030406_create_users.rb" }.should raise_error(Rapid::TemplateNotFoundError)
67
+ end
68
+
69
+ it "should push when :if is true" do
70
+ create_template 'foo.rb', 'hi'
71
+ @instance.should_receive(:set?).with('foo').and_return(true)
72
+
73
+ @instance.send :template, "foo.rb", :if => 'foo'
74
+
75
+ output_path = File.join @project_path, "foo.rb"
76
+ File.open(output_path) {|f| f.read }.should == "hi"
77
+ end
78
+
79
+ it "should not push when :if is false" do
80
+ @instance.should_receive(:set?).with('foo').and_return(false)
81
+
82
+ @instance.send :template, "foo.rb", :if => 'foo'
83
+
84
+ output_path = File.join @project_path, "foo.rb"
85
+ File.exists?(output_path).should == false
86
+ end
87
+
88
+ end
89
+
90
+ describe "pull_template" do
91
+
92
+ before do
93
+ @instance.stub!(:pushing?).and_return(false)
94
+ @instance.stub!(:pulling?).and_return(true)
95
+ end
96
+
97
+ it "should report an error when the template does not exist" do
98
+ create_template 'config/initializers/airbrake.rb', 'foo <%= 3 %> bar'
99
+ @instance.should_receive(:error).with("config/initializers/airbrake.rb", "doesn't exist")
100
+
101
+ @instance.send :template, "config/initializers/airbrake.rb"
102
+ end
103
+
104
+ it "should report an error when the template doesn't pull" do
105
+ create_template 'config/initializers/airbrake.rb', 'foo <%= 3 %> bar'
106
+ create_output 'config/initializers/airbrake.rb', 'hi'
107
+
108
+ @instance.should_receive(:exception)
109
+
110
+ @instance.send :template, "config/initializers/airbrake.rb"
111
+ end
112
+
113
+ it "should report ok when the template pulls" do
114
+ create_template 'config/initializers/airbrake.rb', 'foo <%= name %> bar'
115
+ create_output 'config/initializers/airbrake.rb', 'foo Dan bar'
116
+
117
+ @instance.should_receive(:ok).with("config/initializers/airbrake.rb", "is good")
118
+
119
+ @instance.send :template, "config/initializers/airbrake.rb"
120
+ end
121
+
122
+ it "should set the 'if' setting false if the project file is missing" do
123
+ create_template 'foo.rb', 'foo <%= name %> bar'
124
+
125
+ @instance.should_receive(:[]=).with('foo', false)
126
+
127
+ @instance.send :template, 'foo.rb', :if => 'foo'
128
+ end
129
+
130
+ it "should set the 'if' setting true if the project file is there" do
131
+ create_template 'foo.rb', 'foo <%= name %> bar'
132
+ create_output 'foo.rb', 'foo Dan bar'
133
+
134
+ @instance.should_receive(:ok)
135
+ @instance.should_receive(:[]=).with('foo', true)
136
+
137
+ @instance.send :template, 'foo.rb', :if => 'foo'
138
+ end
139
+
140
+ end
141
+
142
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ describe Rapid::Skeleton::Helpers::View do
4
+
5
+ before do
6
+ Object.class_eval do
7
+ class MyClass
8
+ include Rapid::Skeleton::Helpers::Template
9
+ include Rapid::Skeleton::Helpers::View
10
+
11
+ attr_accessor :templates_path, :project_path, :get_binding
12
+ end
13
+ end
14
+
15
+ @instance = MyClass.new
16
+ end
17
+
18
+ after do
19
+ Object.send(:remove_const, :MyClass) rescue nil
20
+ end
21
+
22
+ describe "push_view" do
23
+
24
+ before do
25
+ @instance.stub!(:pushing?).and_return(true)
26
+ @instance.stub!(:pulling?).and_return(false)
27
+ end
28
+
29
+ it "should render the template into the rapid/views directory" do
30
+ @instance.project_path = 'tmp'
31
+ @instance.should_receive(:push_template).with('app/views/users/show.html.erb', :to => 'lib/rapid/views/users/show.html.erb')
32
+
33
+ @instance.send :view, 'users/show.html.erb'
34
+ end
35
+
36
+ end
37
+
38
+ describe "pull_view" do
39
+
40
+ before do
41
+ @instance.stub!(:pushing?).and_return(false)
42
+ @instance.stub!(:pulling?).and_return(true)
43
+ end
44
+
45
+ it "should delegate to pull_template" do
46
+ @instance.project_path = 'tmp'
47
+ @instance.should_receive(:pull_template).with('app/views/users/show.html.erb', :to => 'lib/rapid/views/users/show.html.erb')
48
+
49
+ @instance.send :view, 'users/show.html.erb'
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,168 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Rapid::Spec::Template do
4
+
5
+ before do
6
+ Object.class_eval do
7
+ class MyClass
8
+ include Rapid::Spec::Template
9
+ end
10
+ end
11
+
12
+ @instance = MyClass.new
13
+ end
14
+
15
+ after do
16
+ Object.send(:remove_const, :MyClass) rescue nil
17
+ end
18
+
19
+ it "should expose templates_path" do
20
+ @instance.templates_path.should == nil
21
+ end
22
+
23
+ it "should expose template_path" do
24
+ @instance.template_path.should == nil
25
+ end
26
+
27
+ it "should expose template_name" do
28
+ @instance.template_name.should == nil
29
+ end
30
+
31
+ it "should expose template_content" do
32
+ @instance.template_content.should == nil
33
+ end
34
+
35
+ describe "template_spec" do
36
+
37
+ before do
38
+ FileUtils.mkdir_p 'tmp/test/templates'
39
+ end
40
+
41
+ after do
42
+ FileUtils.rm_rf 'tmp/test/templates'
43
+ end
44
+
45
+ it "should raise an error when the template file is not found" do
46
+ lambda { MyClass.template_spec 'foo.rb' }.should raise_error
47
+ lambda { MyClass.template_spec '/spec/templates/foo_spec.rb' }.should raise_error
48
+ lambda { MyClass.template_spec '/spec/foo.rb' }.should raise_error
49
+ end
50
+
51
+ it "should call before on the spec" do
52
+ MyClass.should_receive(:before)
53
+ File.open("tmp/test/templates/my.rb", "w") {|f| f.write "foo" }
54
+ MyClass.template_spec 'tmp/test/spec/templates/my_spec.rb'
55
+ end
56
+
57
+ end
58
+
59
+ describe "find" do
60
+
61
+ before do
62
+ FileUtils.mkdir_p 'tmp/test/templates'
63
+ end
64
+
65
+ after do
66
+ FileUtils.rm_rf 'tmp/test/templates'
67
+ end
68
+
69
+ def find spec_path
70
+ @templates_path, @template_path, @template_name = Rapid::Spec::Template.find spec_path
71
+ end
72
+
73
+ it "should figure out ruby files" do
74
+ File.open("tmp/test/templates/my.rb", "w") {|f| f.write "foo" }
75
+ find "tmp/test/spec/templates/my_spec.rb"
76
+
77
+ @templates_path.should == 'tmp/test/templates'
78
+ @template_path.should == 'tmp/test/templates/my.rb'
79
+ @template_name.should == 'my.rb'
80
+ end
81
+
82
+ it "should figure out files without extensions" do
83
+ FileUtils.mkdir_p 'tmp/test/templates/script'
84
+ File.open("tmp/test/templates/script/rails", "w") {|f| f.write "foo" }
85
+ find "tmp/test/spec/templates/script/rails_spec.rb"
86
+
87
+ @templates_path.should == 'tmp/test/templates'
88
+ @template_path.should == 'tmp/test/templates/script/rails'
89
+ @template_name.should == 'script/rails'
90
+ end
91
+
92
+ it "should figure out with extensions other than rb" do
93
+ FileUtils.mkdir_p 'tmp/test/templates/lib/tasks'
94
+ File.open("tmp/test/templates/lib/tasks/build.rake", "w") {|f| f.write "foo" }
95
+ find "tmp/test/spec/templates/lib/tasks/build.rake_spec.rb"
96
+
97
+ @templates_path.should == 'tmp/test/templates'
98
+ @template_path.should == 'tmp/test/templates/lib/tasks/build.rake'
99
+ @template_name.should == 'lib/tasks/build.rake'
100
+ end
101
+
102
+ end
103
+
104
+ describe "push" do
105
+
106
+ after do
107
+ Rapid::Spec::Template.skeleton_class = nil
108
+ end
109
+
110
+ it "should allow custom implementation of build_skeleton" do
111
+ @settings = mock("settings", :get_binding => nil)
112
+ @settings.should_receive(:load_hash).with("foo" => true)
113
+ @skeleton = Rapid::Skeleton::Base.new @settings
114
+
115
+ @instance = MyClass.new
116
+ @instance.should_receive(:respond_to?).with(:build_skeleton).and_return(true)
117
+ @instance.should_receive(:build_skeleton).and_return(@skeleton)
118
+ @instance.should_receive(:template_content).and_return("<% if true %>a<% else %>b<% end %>")
119
+
120
+ @instance.push("foo" => true)
121
+
122
+ @instance.instance_variable_get(:@skeleton).should == @skeleton
123
+ @instance.instance_variable_get(:@template).class.should == Rapid::Template::Base
124
+ @instance.instance_variable_get(:@result).should == "a"
125
+ end
126
+
127
+ it "should allow the Rapid::Spec::Template.skeleton_class be set" do
128
+ @settings = mock("settings", :get_binding => nil)
129
+ @skeleton = Rapid::Skeleton::Base.new @settings
130
+
131
+ Rapid::Spec::Template.skeleton_class = Rapid::Skeleton::Base
132
+ Rapid::Skeleton::Base.should_receive(:new).with.and_return(@skeleton)
133
+ @instance.should_receive(:template_content).and_return("hi")
134
+ @instance.push
135
+ end
136
+
137
+ it "should raise an error when the skeleton is unknown" do
138
+ lambda { @instance.push }.should raise_error
139
+ end
140
+
141
+ end
142
+
143
+ describe "pull" do
144
+
145
+ before do
146
+ @instance.stub!(:template_content).and_return('<% if true %>a<% else %>b<% end %>')
147
+ end
148
+
149
+ it "should accept a hash" do
150
+ @instance.should_receive(:push).with('foo' => true).and_return('a')
151
+ @instance.pull 'foo' => true
152
+
153
+ @instance.instance_variable_get(:@content).should == "a"
154
+ @instance.instance_variable_get(:@template).class.should == Rapid::Template::Base
155
+ @instance.instance_variable_get(:@result).should == {'true' => true}
156
+ end
157
+
158
+ it "should access content" do
159
+ @instance.pull 'a'
160
+
161
+ @instance.instance_variable_get(:@content).should == "a"
162
+ @instance.instance_variable_get(:@template).class.should == Rapid::Template::Base
163
+ @instance.instance_variable_get(:@result).should == {'true' => true}
164
+ end
165
+
166
+ end
167
+
168
+ end