test/test_controller_generator.rb in padrino-gen-0.9.25 vs test/test_controller_generator.rb in padrino-gen-0.9.26
- old
+ new
@@ -3,11 +3,11 @@
class TestControllerGenerator < Test::Unit::TestCase
def setup
@apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
`mkdir -p #{@apptmp}`
@controller_path = "#{@apptmp}/sample_project/app/controllers/demo_items.rb"
- @controller_test_path = "#{@apptmp}/sample_project/test/controllers/demo_items_controller_test.rb"
+ @controller_test_path = "#{@apptmp}/sample_project/test/app/controllers/demo_items_controller_test.rb"
end
def teardown
`rm -rf #{@apptmp}`
end
@@ -23,10 +23,11 @@
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
assert_match_in_file(/SampleProject.controllers :demo_items do/m, @controller_path)
assert_match_in_file(/SampleProject.helpers do/m, "#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
assert_file_exists("#{@apptmp}/sample_project/app/views/demo_items")
+ assert_file_exists(@controller_test_path)
end
should "generate controller within existing project with weird name" do
silence_logger { generate(:project, 'warepedia', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/warepedia") }
@@ -54,54 +55,60 @@
assert_no_file_exists("#{@apptmp}/sample_project/test")
end
should "generate controller test for bacon" do
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
- assert_match_in_file(/describe "DemoItemsController" do/m, @controller_test_path)
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
+ silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
+ assert_match_in_file(/describe "DemoItemsController" do/m, @controller_test_path.gsub('app','subby'))
end
should "generate controller test for riot" do
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=riot') }
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
- assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path)
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
+ silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
+ assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path.gsub('app','subby'))
end
should "generate controller test for testspec" do
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=testspec') }
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
- assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path)
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
+ silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
+ assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path.gsub('app','subby'))
end
should "generate controller test for rspec" do
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
- assert_match_in_file(/describe "DemoItemsController" do/m, "#{@apptmp}/sample_project/spec/controllers/demo_items_controller_spec.rb")
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
+ silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
+ assert_match_in_file(/describe "DemoItemsController" do/m, "#{@apptmp}/sample_project/spec/subby/controllers/demo_items_controller_spec.rb")
end
should "generate controller test for shoulda" do
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=shoulda') }
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
+ silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
expected_pattern = /class DemoItemsControllerTest < Test::Unit::TestCase/m
- assert_match_in_file(expected_pattern, @controller_test_path)
- assert_file_exists("#{@apptmp}/sample_project/test/controllers/demo_items_controller_test.rb")
+ assert_match_in_file(expected_pattern, @controller_test_path.gsub('app','subby'))
+ assert_file_exists("#{@apptmp}/sample_project/test/subby/controllers/demo_items_controller_test.rb")
end
should "generate controller test for cucumber" do
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=cucumber') }
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
- assert_match_in_file(/describe "DemoItemsController" do/m, "#{@apptmp}/sample_project/spec/controllers/demo_items_controller_spec.rb")
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
+ silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
+ assert_match_in_file(/describe "DemoItemsController" do/m, "#{@apptmp}/sample_project/spec/subby/controllers/demo_items_controller_spec.rb")
assert_match_in_file(/Capybara.app = /, "#{@apptmp}/sample_project/features/support/env.rb")
end
should "correctly generate file names" do
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
assert_file_exists("#{@apptmp}/sample_project/app/views/demo_items")
assert_file_exists("#{@apptmp}/sample_project/app/controllers/demo_items.rb")
assert_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
- assert_file_exists("#{@apptmp}/sample_project/spec/controllers/demo_items_controller_spec.rb")
+ assert_file_exists("#{@apptmp}/sample_project/spec/app/controllers/demo_items_controller_spec.rb")
end
# Controller action generation
should "generate actions for get:test post:yada" do
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=shoulda') }
@@ -125,9 +132,19 @@
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
silence_logger { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project") }
silence_logger { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project",'-d') }
assert_no_file_exists(@controller_path)
assert_no_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
- assert_no_file_exists("#{@apptmp}/sample_project/spec/controllers/demo_items_controller_spec.rb")
+ assert_no_file_exists("#{@apptmp}/sample_project/spec/app/controllers/demo_items_controller_spec.rb")
end
+
+ should "destroy controller files in sub apps" do
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
+ silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
+ silence_logger { generate(:controller, 'demo_items',"-a=/subby","-r=#{@apptmp}/sample_project") }
+ silence_logger { generate(:controller, 'demo_items',"-a=/subby","-r=#{@apptmp}/sample_project",'-d') }
+ assert_no_file_exists(@controller_path.gsub('app','subby'))
+ assert_no_file_exists(@controller_test_path.gsub('app','subby'))
+ assert_no_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
+ end
end
-end
\ No newline at end of file
+end