aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/generators/test_unit
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/generators/test_unit')
-rw-r--r--railties/lib/generators/test_unit/mailer/mailer_generator.rb18
-rw-r--r--railties/lib/generators/test_unit/mailer/templates/fixture3
-rw-r--r--railties/lib/generators/test_unit/mailer/templates/unit_test.rb20
-rw-r--r--railties/lib/generators/test_unit/observer/observer_generator.rb9
-rw-r--r--railties/lib/generators/test_unit/observer/templates/unit_test.rb8
-rw-r--r--railties/lib/generators/test_unit/plugin/plugin_generator.rb9
-rw-r--r--railties/lib/generators/test_unit/plugin/templates/test/%file_name%_test.rb8
-rw-r--r--railties/lib/generators/test_unit/plugin/templates/test/test_helper.rb3
8 files changed, 78 insertions, 0 deletions
diff --git a/railties/lib/generators/test_unit/mailer/mailer_generator.rb b/railties/lib/generators/test_unit/mailer/mailer_generator.rb
new file mode 100644
index 0000000000..125371b173
--- /dev/null
+++ b/railties/lib/generators/test_unit/mailer/mailer_generator.rb
@@ -0,0 +1,18 @@
+module TestUnit
+ module Generators
+ class MailerGenerator < Base
+ argument :actions, :type => :array, :default => []
+
+ def create_test_files
+ template "unit_test.rb", File.join('test', 'unit', class_path, "#{file_name}_test.rb")
+ end
+
+ def create_fixtures_files
+ actions.each do |action|
+ @action, @path = action, File.join(file_path, action)
+ template "fixture", File.join("test", "fixtures", @path)
+ end
+ end
+ end
+ end
+end
diff --git a/railties/lib/generators/test_unit/mailer/templates/fixture b/railties/lib/generators/test_unit/mailer/templates/fixture
new file mode 100644
index 0000000000..fcce7bd805
--- /dev/null
+++ b/railties/lib/generators/test_unit/mailer/templates/fixture
@@ -0,0 +1,3 @@
+<%= class_name %>#<%= @action %>
+
+Find me in app/views/<%= @path %>
diff --git a/railties/lib/generators/test_unit/mailer/templates/unit_test.rb b/railties/lib/generators/test_unit/mailer/templates/unit_test.rb
new file mode 100644
index 0000000000..4de94076e9
--- /dev/null
+++ b/railties/lib/generators/test_unit/mailer/templates/unit_test.rb
@@ -0,0 +1,20 @@
+require 'test_helper'
+
+class <%= class_name %>Test < ActionMailer::TestCase
+<% for action in actions -%>
+ test "<%= action %>" do
+ @expected.subject = '<%= class_name %>#<%= action %>'
+ @expected.body = read_fixture('<%= action %>')
+ @expected.date = Time.now
+
+ assert_equal @expected.encoded, <%= class_name %>.create_<%= action %>(@expected.date).encoded
+ end
+
+<% end -%>
+<% if actions.blank? -%>
+ # replace this with your real tests
+ test "the truth" do
+ assert true
+ end
+<% end -%>
+end
diff --git a/railties/lib/generators/test_unit/observer/observer_generator.rb b/railties/lib/generators/test_unit/observer/observer_generator.rb
new file mode 100644
index 0000000000..adfd90a086
--- /dev/null
+++ b/railties/lib/generators/test_unit/observer/observer_generator.rb
@@ -0,0 +1,9 @@
+module TestUnit
+ module Generators
+ class ObserverGenerator < Base
+ def create_test_files
+ template 'unit_test.rb', File.join('test', 'unit', class_path, "#{file_name}_observer_test.rb")
+ end
+ end
+ end
+end
diff --git a/railties/lib/generators/test_unit/observer/templates/unit_test.rb b/railties/lib/generators/test_unit/observer/templates/unit_test.rb
new file mode 100644
index 0000000000..03f6d5666e
--- /dev/null
+++ b/railties/lib/generators/test_unit/observer/templates/unit_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class <%= class_name %>ObserverTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/railties/lib/generators/test_unit/plugin/plugin_generator.rb b/railties/lib/generators/test_unit/plugin/plugin_generator.rb
new file mode 100644
index 0000000000..427a7bd8f5
--- /dev/null
+++ b/railties/lib/generators/test_unit/plugin/plugin_generator.rb
@@ -0,0 +1,9 @@
+module TestUnit
+ module Generators
+ class PluginGenerator < Base
+ def create_test_files
+ directory 'test'
+ end
+ end
+ end
+end
diff --git a/railties/lib/generators/test_unit/plugin/templates/test/%file_name%_test.rb b/railties/lib/generators/test_unit/plugin/templates/test/%file_name%_test.rb
new file mode 100644
index 0000000000..3e0bc29d3a
--- /dev/null
+++ b/railties/lib/generators/test_unit/plugin/templates/test/%file_name%_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class <%= class_name %>Test < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/railties/lib/generators/test_unit/plugin/templates/test/test_helper.rb b/railties/lib/generators/test_unit/plugin/templates/test/test_helper.rb
new file mode 100644
index 0000000000..cf148b8b47
--- /dev/null
+++ b/railties/lib/generators/test_unit/plugin/templates/test/test_helper.rb
@@ -0,0 +1,3 @@
+require 'rubygems'
+require 'active_support'
+require 'active_support/test_case' \ No newline at end of file