Add some test coverage for RailsControllerGenerator.
This commit is contained in:
parent
3a0d8adcf2
commit
4562a5b57f
|
@ -172,8 +172,15 @@ class GeneratorTestCase < Test::Unit::TestCase
|
|||
# It takes a path without the <tt>.rb</tt> part and an optional super class.
|
||||
# the contents of the class source file is passed to a block.
|
||||
def assert_generated_class(path, parent = nil)
|
||||
# FIXME: Sucky way to detect namespaced classes
|
||||
if path.split('/').size > 3
|
||||
path =~ /\/?(\d+_)?(\w+)\/(\w+)$/
|
||||
class_name = "#{$2.camelize}::#{$3.camelize}"
|
||||
else
|
||||
path =~ /\/?(\d+_)?(\w+)$/
|
||||
class_name = $2.camelize
|
||||
end
|
||||
|
||||
assert_generated_file("#{path}.rb") do |body|
|
||||
assert_match /class #{class_name}#{parent.nil? ? '':" < #{parent}"}/, body, "the file '#{path}.rb' should be a class"
|
||||
yield body if block_given?
|
||||
|
@ -184,8 +191,15 @@ class GeneratorTestCase < Test::Unit::TestCase
|
|||
# It takes a path without the <tt>.rb</tt> part.
|
||||
# the contents of the class source file is passed to a block.
|
||||
def assert_generated_module(path)
|
||||
# FIXME: Sucky way to detect namespaced modules
|
||||
if path.split('/').size > 3
|
||||
path =~ /\/?(\w+)\/(\w+)$/
|
||||
module_name = "#{$1.camelize}::#{$2.camelize}"
|
||||
else
|
||||
path =~ /\/?(\w+)$/
|
||||
module_name = $1.camelize
|
||||
end
|
||||
|
||||
assert_generated_file("#{path}.rb") do |body|
|
||||
assert_match /module #{module_name}/, body, "the file '#{path}.rb' should be a module"
|
||||
yield body if block_given?
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
require 'generators/generator_test_helper'
|
||||
|
||||
class RailsControllerGeneratorTest < GeneratorTestCase
|
||||
|
||||
def test_controller_generates_controller
|
||||
run_generator('controller', %w(products))
|
||||
|
||||
assert_generated_controller_for :products
|
||||
assert_generated_functional_test_for :products
|
||||
assert_generated_helper_for :products
|
||||
end
|
||||
|
||||
def test_controller_generates_namespaced_controller
|
||||
run_generator('controller', %w(admin::products))
|
||||
|
||||
assert_generated_controller_for "admin::products"
|
||||
assert_generated_functional_test_for "admin::products"
|
||||
assert_generated_helper_for "admin::products"
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue