aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators/generators_test_helper.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-06-25 10:18:00 +0200
committerJosé Valim <jose.valim@gmail.com>2009-06-25 10:39:44 +0200
commitf596495556f871650ed6b7a67128e4fd13cd3773 (patch)
tree95315a6040f5f5f0fb53b0815e3314a1dfbd0383 /railties/test/generators/generators_test_helper.rb
parenta748bb796145981c65cb6d342b4b3b02ef4c0ba0 (diff)
downloadrails-f596495556f871650ed6b7a67128e4fd13cd3773.tar.gz
rails-f596495556f871650ed6b7a67128e4fd13cd3773.tar.bz2
rails-f596495556f871650ed6b7a67128e4fd13cd3773.zip
Tests for plugin generator.
Diffstat (limited to 'railties/test/generators/generators_test_helper.rb')
-rw-r--r--railties/test/generators/generators_test_helper.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb
new file mode 100644
index 0000000000..9f9b48264b
--- /dev/null
+++ b/railties/test/generators/generators_test_helper.rb
@@ -0,0 +1,53 @@
+require 'test/unit'
+require 'fileutils'
+
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
+require 'generators'
+
+class GeneratorsTestCase < 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