diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-07-30 14:18:53 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-07-30 14:18:53 +0100 |
commit | 915cf5747a78f28f2b25c48574031db60c3a18ae (patch) | |
tree | 048746387ddaaed418670c86451856675b8d369f /railties/test/generators/helper_generator_test.rb | |
parent | 23f5e7e966defaaa1511eca57bd8de47f95cb7d9 (diff) | |
parent | d83b1828577c268de56e1b3942e16002c9efdd57 (diff) | |
download | rails-915cf5747a78f28f2b25c48574031db60c3a18ae.tar.gz rails-915cf5747a78f28f2b25c48574031db60c3a18ae.tar.bz2 rails-915cf5747a78f28f2b25c48574031db60c3a18ae.zip |
Merge commit 'mainstream/master'
Conflicts:
railties/guides/source/active_support_overview.textile
Diffstat (limited to 'railties/test/generators/helper_generator_test.rb')
-rw-r--r-- | railties/test/generators/helper_generator_test.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/railties/test/generators/helper_generator_test.rb b/railties/test/generators/helper_generator_test.rb new file mode 100644 index 0000000000..3d655016f1 --- /dev/null +++ b/railties/test/generators/helper_generator_test.rb @@ -0,0 +1,60 @@ +require 'abstract_unit' +require 'generators/generators_test_helper' +require 'generators/rails/helper/helper_generator' + +ObjectHelper = Class.new +AnotherObjectHelperTest = Class.new + +class HelperGeneratorTest < GeneratorsTestCase + + def test_helper_skeleton_is_created + run_generator + assert_file "app/helpers/admin_helper.rb", /module AdminHelper/ + end + + def test_invokes_default_test_framework + run_generator + assert_file "test/unit/helpers/admin_helper_test.rb", /class AdminHelperTest < ActionView::TestCase/ + end + + def test_logs_if_the_test_framework_cannot_be_found + content = run_generator ["admin", "--test-framework=rspec"] + assert_match /rspec \[not found\]/, content + end + + def test_check_class_collision + content = capture(:stderr){ run_generator ["object"] } + assert_match /The name 'ObjectHelper' is either already used in your application or reserved/, content + end + + def test_check_class_collision_on_tests + content = capture(:stderr){ run_generator ["another_object"] } + assert_match /The name 'AnotherObjectHelperTest' is either already used in your application or reserved/, content + end + + def test_namespaced_and_not_namespaced_helpers + run_generator ["products"] + + # We have to require the generated helper to show the problem because + # the test helpers just check for generated files and contents but + # do not actually load them. But they have to be loaded (as in a real environment) + # to make the second generator run fail + require "#{destination_root}/app/helpers/products_helper" + + assert_nothing_raised do + begin + run_generator ["admin::products"] + ensure + # cleanup + Object.send(:remove_const, :ProductsHelper) + end + end + end + + protected + + def run_generator(args=["admin"]) + silence(:stdout) { Rails::Generators::HelperGenerator.start args, :destination_root => destination_root } + end + +end |