| | 121 | |
|---|
| | 122 | describe "a controller generator" do |
|---|
| | 123 | include RubiGen::GeneratorTestHelper |
|---|
| | 124 | |
|---|
| | 125 | before :all do |
|---|
| | 126 | module Kernel |
|---|
| | 127 | alias_method :old_dependency, :dependency |
|---|
| | 128 | undef dependency |
|---|
| | 129 | end |
|---|
| | 130 | end |
|---|
| | 131 | |
|---|
| | 132 | after :all do |
|---|
| | 133 | module Kernel |
|---|
| | 134 | alias_method :dependency, :old_dependency |
|---|
| | 135 | end |
|---|
| | 136 | end |
|---|
| | 137 | |
|---|
| | 138 | before do |
|---|
| | 139 | @generator = build_generator('controller', ["my_posts"], sources, {}) |
|---|
| | 140 | end |
|---|
| | 141 | |
|---|
| | 142 | after do |
|---|
| | 143 | bare_teardown # Cleans up the temporary application directory that gets created as part of the test. |
|---|
| | 144 | end |
|---|
| | 145 | |
|---|
| | 146 | it "should be get created" do |
|---|
| | 147 | @generator.should_not be_nil |
|---|
| | 148 | end |
|---|
| | 149 | |
|---|
| | 150 | it "should be a ControllerGenerator" do |
|---|
| | 151 | @generator.should be_an_instance_of(ControllerGenerator) |
|---|
| | 152 | end |
|---|
| | 153 | |
|---|
| | 154 | it "should create directory structure" do |
|---|
| | 155 | silence_generator do |
|---|
| | 156 | @generator.command(:create).invoke! |
|---|
| | 157 | end |
|---|
| | 158 | %w{ |
|---|
| | 159 | app |
|---|
| | 160 | app/controllers |
|---|
| | 161 | app/helpers |
|---|
| | 162 | app/views |
|---|
| | 163 | app/views/my_posts |
|---|
| | 164 | }.each{|dir| directory_should_be_created(dir)} |
|---|
| | 165 | end |
|---|
| | 166 | |
|---|
| | 167 | it "should create files from templates" do |
|---|
| | 168 | silence_generator do |
|---|
| | 169 | @generator.command(:create).invoke! |
|---|
| | 170 | end |
|---|
| | 171 | %w{ |
|---|
| | 172 | app/controllers/my_posts.rb |
|---|
| | 173 | app/helpers/my_posts_helper.rb |
|---|
| | 174 | app/views/my_posts/index.html.erb |
|---|
| | 175 | }.each{|file| file_should_be_created(file)} |
|---|
| | 176 | end |
|---|
| | 177 | |
|---|
| | 178 | def sources |
|---|
| | 179 | [ |
|---|
| | 180 | RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__),"../../", "merb_generators")), |
|---|
| | 181 | RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__),"../../", "rspec_generators")) |
|---|
| | 182 | ] |
|---|
| | 183 | end |
|---|
| | 184 | end |
|---|
| | 185 | |
|---|
| | 186 | describe "a part_controller generator" do |
|---|
| | 187 | include RubiGen::GeneratorTestHelper |
|---|
| | 188 | |
|---|
| | 189 | before :all do |
|---|
| | 190 | module Kernel |
|---|
| | 191 | alias_method :old_dependency, :dependency |
|---|
| | 192 | undef dependency |
|---|
| | 193 | end |
|---|
| | 194 | end |
|---|
| | 195 | |
|---|
| | 196 | after :all do |
|---|
| | 197 | module Kernel |
|---|
| | 198 | alias_method :dependency, :old_dependency |
|---|
| | 199 | end |
|---|
| | 200 | end |
|---|
| | 201 | |
|---|
| | 202 | before do |
|---|
| | 203 | @generator = build_generator('part_controller', ["my_posts"], sources, {}) |
|---|
| | 204 | end |
|---|
| | 205 | |
|---|
| | 206 | after do |
|---|
| | 207 | bare_teardown # Cleans up the temporary application directory that gets created as part of the test. |
|---|
| | 208 | end |
|---|
| | 209 | |
|---|
| | 210 | it "should be get created" do |
|---|
| | 211 | @generator.should_not be_nil |
|---|
| | 212 | end |
|---|
| | 213 | |
|---|
| | 214 | it "should be a PartControllerGenerator" do |
|---|
| | 215 | @generator.should be_an_instance_of(PartControllerGenerator) |
|---|
| | 216 | end |
|---|
| | 217 | |
|---|
| | 218 | it "should create directory structure" do |
|---|
| | 219 | silence_generator do |
|---|
| | 220 | @generator.command(:create).invoke! |
|---|
| | 221 | end |
|---|
| | 222 | %w{ |
|---|
| | 223 | app |
|---|
| | 224 | app/parts/controllers |
|---|
| | 225 | app/parts/helpers |
|---|
| | 226 | app/parts/views |
|---|
| | 227 | app/parts/views/my_posts_part |
|---|
| | 228 | }.each{|dir| directory_should_be_created(dir)} |
|---|
| | 229 | end |
|---|
| | 230 | |
|---|
| | 231 | it "should create files from templates" do |
|---|
| | 232 | silence_generator do |
|---|
| | 233 | @generator.command(:create).invoke! |
|---|
| | 234 | end |
|---|
| | 235 | %w{ |
|---|
| | 236 | app/parts/controllers/my_posts_part.rb |
|---|
| | 237 | app/parts/helpers/my_posts_part_helper.rb |
|---|
| | 238 | app/parts/views/my_posts_part/index.html.erb |
|---|
| | 239 | }.each{|file| file_should_be_created(file)} |
|---|
| | 240 | end |
|---|
| | 241 | |
|---|
| | 242 | def sources |
|---|
| | 243 | [ |
|---|
| | 244 | RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__),"../../", "merb_generators")), |
|---|
| | 245 | RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__),"../../", "rspec_generators")) |
|---|
| | 246 | ] |
|---|
| | 247 | end |
|---|
| | 248 | end |
|---|