2009-06-26 03:53:53 -04:00
|
|
|
require 'generators/generators_test_helper'
|
2010-03-23 08:40:19 -04:00
|
|
|
require 'rails/generators/rails/helper/helper_generator'
|
2009-06-26 03:53:53 -04:00
|
|
|
|
|
|
|
ObjectHelper = Class.new
|
2009-06-26 04:40:02 -04:00
|
|
|
AnotherObjectHelperTest = Class.new
|
2009-06-26 03:53:53 -04:00
|
|
|
|
2010-01-18 18:07:11 -05:00
|
|
|
class HelperGeneratorTest < Rails::Generators::TestCase
|
|
|
|
include GeneratorsTestHelper
|
2010-01-03 10:34:32 -05:00
|
|
|
arguments %w(admin)
|
2009-06-26 03:53:53 -04:00
|
|
|
|
|
|
|
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
|
2012-10-08 00:59:42 -04:00
|
|
|
assert_file "test/helpers/admin_helper_test.rb", /class AdminHelperTest < ActionView::TestCase/
|
2009-06-26 03:53:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_logs_if_the_test_framework_cannot_be_found
|
2009-07-08 06:55:50 -04:00
|
|
|
content = run_generator ["admin", "--test-framework=rspec"]
|
2011-05-18 07:37:57 -04:00
|
|
|
assert_match(/rspec \[not found\]/, content)
|
2009-06-26 03:53:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_check_class_collision
|
|
|
|
content = capture(:stderr){ run_generator ["object"] }
|
2011-05-18 07:37:57 -04:00
|
|
|
assert_match(/The name 'ObjectHelper' is either already used in your application or reserved/, content)
|
2009-06-26 03:53:53 -04:00
|
|
|
end
|
|
|
|
|
2009-06-26 04:40:02 -04:00
|
|
|
def test_check_class_collision_on_tests
|
|
|
|
content = capture(:stderr){ run_generator ["another_object"] }
|
2011-05-18 07:37:57 -04:00
|
|
|
assert_match(/The name 'AnotherObjectHelperTest' is either already used in your application or reserved/, content)
|
2009-06-26 04:40:02 -04:00
|
|
|
end
|
|
|
|
|
2009-06-27 07:03:07 -04:00
|
|
|
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
|
2009-06-26 03:53:53 -04:00
|
|
|
end
|