aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators/generators_test_helper.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-03 15:13:54 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-03 17:14:49 +0100
commit441227a10f42fcd28b65ab416495ff8f4fc45b52 (patch)
tree4e84b9672f6ed7ca4d5300059f7216f009185e04 /railties/test/generators/generators_test_helper.rb
parente88ea3255ff90baa28d30908e1fcb5fa7f7133a8 (diff)
downloadrails-441227a10f42fcd28b65ab416495ff8f4fc45b52.tar.gz
rails-441227a10f42fcd28b65ab416495ff8f4fc45b52.tar.bz2
rails-441227a10f42fcd28b65ab416495ff8f4fc45b52.zip
Create Rails::Generators::TestCase.
Diffstat (limited to 'railties/test/generators/generators_test_helper.rb')
-rw-r--r--railties/test/generators/generators_test_helper.rb90
1 files changed, 7 insertions, 83 deletions
diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb
index 4ce48a453b..b3a810634e 100644
--- a/railties/test/generators/generators_test_helper.rb
+++ b/railties/test/generators/generators_test_helper.rb
@@ -10,93 +10,17 @@ end
Rails.application.config.root = Rails.root
require 'rails/generators'
+require 'rails/generators/test_case'
+
require 'rubygems'
require 'active_record'
require 'action_dispatch'
-CURRENT_PATH = File.expand_path(Dir.pwd)
-Rails::Generators.no_color!
-
-class GeneratorsTestCase < ActiveSupport::TestCase
- include FileUtils
-
- def destination_root
- File.join(Rails.root, "tmp")
- end
-
- def setup
- cd CURRENT_PATH
- rm_rf(destination_root)
- mkdir_p(destination_root)
- end
+class GeneratorsTestCase < Rails::Generators::TestCase
+ destination File.join(Rails.root, "tmp")
+ setup :prepare_destination
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
+ # Don't cry test unit
end
- alias :silence :capture
-
- def assert_file(relative, *contents)
- absolute = File.join(destination_root, relative)
- assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not"
-
- read = File.read(absolute) if block_given? || !contents.empty?
- yield read if block_given?
-
- contents.each do |content|
- case content
- when String
- assert_equal content, read
- when Regexp
- assert_match content, read
- end
- end
- end
-
- def assert_no_file(relative)
- absolute = File.join(destination_root, relative)
- assert !File.exists?(absolute), "Expected file #{relative.inspect} to not exist, but does"
- end
-
- def assert_migration(relative, *contents, &block)
- file_name = migration_file_name(relative)
- assert file_name, "Expected migration #{relative} to exist, but was not found"
- assert_file File.join(File.dirname(relative), file_name), *contents, &block
- end
-
- def assert_no_migration(relative)
- file_name = migration_file_name(relative)
- assert_nil file_name, "Expected migration #{relative} to not exist, but found #{file_name}"
- end
-
- def assert_class_method(content, method, &block)
- assert_instance_method content, "self.#{method}", &block
- end
-
- def assert_instance_method(content, method)
- assert content =~ /def #{method}(\(.+\))?(.*?)\n end/m, "Expected to have method #{method}"
- yield $2.strip if block_given?
- end
-
- protected
-
- def migration_file_name(relative)
- absolute = File.join(destination_root, relative)
- dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
-
- migration = Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
- File.basename(migration) if migration
- end
-end
+end \ No newline at end of file