diff options
Diffstat (limited to 'railties/test/generator')
-rw-r--r-- | railties/test/generator/actions_test.rb | 184 | ||||
-rw-r--r-- | railties/test/generator/app_test.rb | 132 | ||||
-rw-r--r-- | railties/test/generator/generator_test_helper.rb | 55 |
3 files changed, 0 insertions, 371 deletions
diff --git a/railties/test/generator/actions_test.rb b/railties/test/generator/actions_test.rb deleted file mode 100644 index 60db8905d7..0000000000 --- a/railties/test/generator/actions_test.rb +++ /dev/null @@ -1,184 +0,0 @@ -require 'abstract_unit' -require 'generator/generator_test_helper' - -class ActionsTest < GeneratorTestCase - def setup - super - @git_plugin_uri = 'git://github.com/technoweenie/restful-authentication.git' - @svn_plugin_uri = 'svn://svnhub.com/technoweenie/restful-authentication/trunk' - end - - def test_apply_loads_and_evaluates_a_template - template = <<-TEMPLATE - @foo = "FOO" - TEMPLATE - template.instance_eval "def read; self; end" # Make the string respond to read - - generator.expects(:open).with("http://gist.github.com/103208.txt").returns(template) - action :apply, "http://gist.github.com/103208.txt" - assert_equal generator.instance_variable_get("@foo"), "FOO" - end - - def test_file_should_write_data_to_file_path - action :file, 'lib/test_file.rb', 'heres test data' - assert_file 'lib/test_file.rb', 'heres test data' - end - - def test_file_should_write_block_contents_to_file_path - action(:file, 'lib/test_file.rb'){ 'heres block data' } - assert_file 'lib/test_file.rb', 'heres block data' - end - - def test_plugin_with_git_option_should_run_plugin_install - generator.expects(:run).once.with("ruby script/plugin install #{@git_plugin_uri}", false) - action :plugin, 'restful-authentication', :git => @git_plugin_uri - end - - def test_plugin_with_svn_option_should_run_plugin_install - generator.expects(:run).once.with("ruby script/plugin install #{@svn_plugin_uri}", false) - action :plugin, 'restful-authentication', :svn => @svn_plugin_uri - end - - def test_plugin_with_git_option_and_submodule_should_use_git_scm - generator.expects(:run).with("git submodule add #{@git_plugin_uri} vendor/plugins/rest_auth", false) - action :plugin, 'rest_auth', :git => @git_plugin_uri, :submodule => true - end - - def test_plugin_with_no_options_should_skip_method - generator.expects(:run).never - action :plugin, 'rest_auth', {} - end - - def test_gem_should_put_gem_dependency_in_enviroment - run_generator - action :gem, 'will-paginate' - assert_file 'config/environment.rb', /config\.gem 'will\-paginate'/ - end - - def test_gem_with_options_should_include_options_in_gem_dependency_in_environment - run_generator - action :gem, 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com' - - regexp = /#{Regexp.escape("config.gem 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com'")}/ - assert_file 'config/environment.rb', regexp - end - - def test_gem_with_env_string_should_put_gem_dependency_in_specified_environment - run_generator - action :gem, 'rspec', :env => 'test' - assert_file 'config/environments/test.rb', /config\.gem 'rspec'/ - end - - def test_gem_with_env_array_should_put_gem_dependency_in_specified_environments - run_generator - action :gem, 'quietbacktrace', :env => %w[ development test ] - assert_file 'config/environments/development.rb', /config\.gem 'quietbacktrace'/ - assert_file 'config/environments/test.rb', /config\.gem 'quietbacktrace'/ - end - - def test_gem_with_lib_option_set_to_false_should_put_gem_dependency_in_enviroment_correctly - run_generator - action :gem, 'mislav-will-paginate', :lib => false - assert_file 'config/environment.rb', /config\.gem 'mislav\-will\-paginate'\, :lib => false/ - end - - def test_environment_should_include_data_in_environment_initializer_block - run_generator - load_paths = 'config.load_paths += %w["#{RAILS_ROOT}/app/extras"]' - action :environment, load_paths - assert_file 'config/environment.rb', /#{Regexp.escape(load_paths)}/ - end - - def test_environment_with_block_should_include_block_contents_in_environment_initializer_block - run_generator - - action :environment do - '# This wont be added' - '# This will be added' - end - - assert_file 'config/environment.rb', /# This will be added/ - end - - def test_git_with_symbol_should_run_command_using_git_scm - generator.expects(:run).once.with('git init') - action :git, :init - end - - def test_git_with_hash_should_run_each_command_using_git_scm - generator.expects(:run).times(2) - action :git, :rm => 'README', :add => '.' - end - - def test_vendor_should_write_data_to_file_in_vendor - action :vendor, 'vendor_file.rb', '# vendor data' - assert_file 'vendor/vendor_file.rb', '# vendor data' - end - - def test_lib_should_write_data_to_file_in_lib - action :lib, 'my_library.rb', 'class MyLibrary' - assert_file 'lib/my_library.rb', 'class MyLibrary' - end - - def test_rakefile_should_write_date_to_file_in_lib_tasks - action :rakefile, 'myapp.rake', 'task :run => [:environment]' - assert_file 'lib/tasks/myapp.rake', 'task :run => [:environment]' - end - - def test_initializer_should_write_date_to_file_in_config_initializers - action :initializer, 'constants.rb', 'MY_CONSTANT = 42' - assert_file 'config/initializers/constants.rb', 'MY_CONSTANT = 42' - end - - def test_generate_should_run_script_generate_with_argument_and_options - generator.expects(:run).once.with('ruby script/generate model MyModel', false) - action :generate, 'model', 'MyModel' - end - - def test_rake_should_run_rake_command_with_development_env - generator.expects(:run).once.with('rake log:clear RAILS_ENV=development', false) - action :rake, 'log:clear' - end - - def test_rake_with_env_option_should_run_rake_command_in_env - generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', false) - action :rake, 'log:clear', :env => 'production' - end - - def test_rake_with_sudo_option_should_run_rake_command_with_sudo - generator.expects(:run).once.with('sudo rake log:clear RAILS_ENV=development', false) - action :rake, 'log:clear', :sudo => true - end - - def test_capify_should_run_the_capify_command - generator.expects(:run).once.with('capify .', false) - action :capify! - end - - def test_freeze_should_freeze_rails_edge - generator.expects(:run).once.with('rake rails:freeze:edge', false) - action :freeze! - end - - def test_route_should_add_data_to_the_routes_block_in_config_routes - run_generator - route_command = "map.route '/login', :controller => 'sessions', :action => 'new'" - action :route, route_command - assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/ - end - - protected - - def run_generator - silence(:stdout) { Rails::Generators::App.start [destination_root] } - end - - def generator(config={}) - @generator ||= Rails::Generators::Base.new([], {}, { :root => destination_root }.merge!(config)) - end - - def action(*args, &block) - silence(:stdout){ generator.send(*args, &block) } - end - -end diff --git a/railties/test/generator/app_test.rb b/railties/test/generator/app_test.rb deleted file mode 100644 index af1be03e59..0000000000 --- a/railties/test/generator/app_test.rb +++ /dev/null @@ -1,132 +0,0 @@ -require 'abstract_unit' -require 'generator/generator_test_helper' - -class AppTest < GeneratorTestCase - - def test_application_skeleton_is_created - run_generator - - %w( - app/controllers - app/helpers - app/models - app/views/layouts - config/environments - config/initializers - config/locales - db - doc - lib - lib/tasks - log - public/images - public/javascripts - public/stylesheets - script/performance - test/fixtures - test/functional - test/integration - test/performance - test/unit - vendor - vendor/plugins - tmp/sessions - tmp/sockets - tmp/cache - tmp/pids - ).each{ |path| assert_file path } - end - - def test_invalid_database_option_raises_an_error - content = capture(:stderr){ run_generator(["-d", "unknown"]) } - assert_match /Invalid value for \-\-database option/, content - end - - def test_dispatchers_are_not_added_by_default - run_generator - assert_no_file "config.ru" - assert_no_file "public/dispatch.cgi" - assert_no_file "public/dispatch.fcgi" - end - - def test_dispatchers_are_added_if_required - run_generator ["--with-dispatchers"] - assert_file "config.ru" - assert_file "public/dispatch.cgi" - assert_file "public/dispatch.fcgi" - end - - def test_config_database_is_added_by_default - run_generator - assert_file "config/database.yml", /sqlite3/ - end - - def test_config_database_is_not_added_if_skip_activerecord_is_given - run_generator ["--skip-activerecord"] - assert_no_file "config/database.yml" - end - - def test_activerecord_is_removed_from_frameworks_if_skip_activerecord_is_given - run_generator ["--skip-activerecord"] - assert_file "config/environment.rb", /config\.frameworks \-= \[ :active_record \]/ - end - - def test_prototype_and_test_unit_are_added_by_default - run_generator - assert_file "public/javascripts/prototype.js" - assert_file "test" - end - - def test_prototype_and_test_unit_are_skipped_if_required - run_generator ["--skip-prototype", "--skip-testunit"] - assert_no_file "public/javascripts/prototype.js" - assert_no_file "test" - end - - def test_shebang_is_added_to_files - run_generator ["--ruby", "foo/bar/baz"] - - %w( - about - console - dbconsole - destroy - generate - plugin - runner - server - ).each { |path| assert_file "script/#{path}", /#!foo\/bar\/baz/ } - end - - def test_rails_is_frozen - generator(:freeze => true, :database => "sqlite3").expects(:run).with("rake rails:freeze:edge", false) - silence(:stdout){ generator.invoke(:all) } - assert_file 'config/environment.rb', /# RAILS_GEM_VERSION/ - end - - def test_template_raises_an_error_with_invalid_path - content = capture(:stderr){ run_generator(["-m", "non/existant/path"]) } - assert_match /The template \[.*\] could not be loaded/, content - assert_match /non\/existant\/path/, content - end - - def test_template_is_executed_when_supplied - path = "http://gist.github.com/103208.txt" - template = %{ say "It works!" } - template.instance_eval "def read; self; end" # Make the string respond to read - - generator(:template => path, :database => "sqlite3").expects(:open).with(path).returns(template) - assert_match /It works!/, silence(:stdout){ generator.invoke(:all) } - end - - protected - - def run_generator(args=[]) - silence(:stdout) { Rails::Generators::AppGenerator.start [destination_root].concat(args) } - end - - def generator(options={}) - @generator ||= Rails::Generators::AppGenerator.new([destination_root], options, :root => destination_root) - end - -end diff --git a/railties/test/generator/generator_test_helper.rb b/railties/test/generator/generator_test_helper.rb deleted file mode 100644 index ebd3547e5e..0000000000 --- a/railties/test/generator/generator_test_helper.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'test/unit' -require 'fileutils' - -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib" - -# For this while, let's load all generators by hand -require 'generator/generators/app/app_generator' - -class GeneratorTestCase < Test::Unit::TestCase - include FileUtils - - def destination_root - @destination_root ||= File.expand_path("#{File.dirname(__FILE__)}/../fixtures/tmp") - end - - def setup - mkdir_p(destination_root) - rm_rf(destination_root) - end - - def test_truth - # don't complain, test/unit - end - - def capture(stream) - begin - stream = stream.to_s - eval "$#{stream} = StringIO.new" - yield - result = eval("$#{stream}").string - ensure - eval("$#{stream} = #{stream.upcase}") - end - - result - end - alias :silence :capture - - def assert_file(relative, content=nil) - absolute = File.join(destination_root, relative) - assert File.exists?(absolute) - - case content - when String - assert_equal content, File.read(absolute) - when Regexp - assert_match content, File.read(absolute) - end - end - - def assert_no_file(relative, content=nil) - absolute = File.join(destination_root, relative) - assert !File.exists?(absolute) - end -end |