Skip to content

Commit

Permalink
Tweak the test templates
Browse files Browse the repository at this point in the history
  • Loading branch information
blowmage committed Jun 3, 2011
1 parent f06043d commit 38c73b2
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 27 deletions.
Expand Up @@ -4,4 +4,8 @@ class <%= class_name %>ControllerTest < MiniTest::Rails::Controller
before do
@controller = <%= class_name %>Controller.new
end

it "must be a real test" do
flunk "Need real tests"
end
end
Expand Up @@ -4,8 +4,8 @@
class <%= class_name %>ControllerTest < MiniTest::Rails::Controller

<% if actions.empty? -%>
def test_truth
assert true
def test_sanity
flunk "Need real tests"
end
<% else -%>
<% actions.each do |action| -%>
Expand Down
4 changes: 4 additions & 0 deletions lib/generators/mini_test/helper/templates/helper_spec.rb
Expand Up @@ -4,4 +4,8 @@ class <%= class_name %>HelperTest < MiniTest::Rails::Helper
before do
@helper= <%= class_name %>Helper.new
end

it "must be a real test" do
flunk "Need real tests"
end
end
4 changes: 2 additions & 2 deletions lib/generators/mini_test/helper/templates/helper_test.rb
Expand Up @@ -3,8 +3,8 @@
<% module_namespacing do -%>
class <%= class_name %>HelperTest < MiniTest::Rails::Helper

def test_truth
assert true
def test_sanity
flunk "Need real tests"
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/mini_test/mailer/mailer_generator.rb
Expand Up @@ -10,9 +10,9 @@ class MailerGenerator < Base

def create_test_files
if options[:spec]
template "mailer_spec.rb", "test/mailers/#{file_name}_mailer_test.rb"
template "mailer_spec.rb", "test/mailers/#{file_name}_test.rb"
else
template "mailer_test.rb", "test/mailers/#{file_name}_mailer_test.rb"
template "mailer_test.rb", "test/mailers/#{file_name}_test.rb"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/mini_test/mailer/templates/mailer_spec.rb
Expand Up @@ -2,7 +2,7 @@

class <%= class_name %>Test < MiniTest::Rails::Mailer
<% actions.each do |action| -%>
it "<%= action %>"
it "<%= action %>" do
mail = <%= class_name %>.<%= action %>
mail.subject.must_equal <%= action.to_s.humanize.inspect %>
mail.to.must_equal ["to@example.org"]
Expand All @@ -12,7 +12,7 @@ class <%= class_name %>Test < MiniTest::Rails::Mailer
<% end -%>
<% if actions.blank? -%>
it "must be a real test"
it "must be a real test" do
flunk "Need real tests"
end
<% end -%>
Expand Down
4 changes: 4 additions & 0 deletions lib/generators/mini_test/model/templates/model_spec.rb
Expand Up @@ -9,6 +9,10 @@ class <%= class_name %>Test < MiniTest::Rails::Model
@<%= file_name %>.valid?.must_equal true
end

it "must be a real test" do
flunk "Need real tests"
end

# describe "when doing its thing" do
# it "must be interesting" do
# @<%= file_name %>.blow_minds!
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/mini_test/model/templates/model_test.rb
Expand Up @@ -3,8 +3,8 @@
<% module_namespacing do -%>
class <%= class_name %>Test < MiniTest::Rails::Model

def test_truth
assert true
def test_sanity
flunk "Need real tests"
end

end
Expand Down
6 changes: 4 additions & 2 deletions test/test_controller_generator.rb
Expand Up @@ -18,7 +18,8 @@ def test_controller_generator
assert_match(/create test\/controllers\/user_controller_test.rb/m, text)
assert File.exists? "test/controllers/user_controller_test.rb"
contents = open("test/controllers/user_controller_test.rb").read
assert_match(/class UserControllerTest < MiniTest::Rails::ControllerTestCase/m, contents)
assert_match(/class UserControllerTest < MiniTest::Rails::Controller/m, contents)
assert_match(/def test_sanity/m, contents)
ensure
# TODO: Don"t write the files
# I agree, it would be better to mock the file getting written
Expand All @@ -32,7 +33,8 @@ def test_controller_generator_spec
assert_match(/create test\/controllers\/user_controller_test.rb/m, text)
assert File.exists? "test/controllers/user_controller_test.rb"
contents = open("test/controllers/user_controller_test.rb").read
assert_match(/describe UserController do/m, contents)
assert_match(/class UserControllerTest < MiniTest::Rails::Controller/m, contents)
assert_match(/it "must be a real test"/m, contents)
ensure
FileUtils.rm_r "test/controllers"
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper_generator.rb
Expand Up @@ -18,7 +18,7 @@ def test_helper_generator
assert_match(/create test\/helpers\/user_helper_test.rb/m, text)
assert File.exists? "test/helpers/user_helper_test.rb"
contents = open("test/helpers/user_helper_test.rb").read
assert_match(/class UserHelperTest < MiniTest::Rails::HelperTestCase/m, contents)
assert_match(/class UserHelperTest < MiniTest::Rails::Helper/m, contents)
ensure
# TODO: Don"t write the files
# I agree, it would be better to mock the file getting written
Expand All @@ -32,7 +32,7 @@ def test_helper_generator_spec
assert_match(/create test\/helpers\/user_helper_test.rb/m, text)
assert File.exists? "test/helpers/user_helper_test.rb"
contents = open("test/helpers/user_helper_test.rb").read
assert_match(/describe UserHelper do/m, contents)
assert_match(/class UserHelperTest < MiniTest::Rails::Helper/m, contents)
ensure
FileUtils.rm_r "test/helpers"
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_install_generator.rb
Expand Up @@ -18,7 +18,7 @@ def test_install_generator
assert_match(/create test\/minitest_helper.rb/m, text)
assert File.exists? "test/minitest_helper.rb"
contents = open("test/minitest_helper.rb").read
assert_match(/class MiniTest::Rails::TestCase/m, contents)
assert_match(/class MiniTest::Rails::Spec/m, contents)
ensure
# TODO: Don"t write the files
# I agree, it would be better to mock the file getting written
Expand Down
20 changes: 10 additions & 10 deletions test/test_mailer_generator.rb
Expand Up @@ -13,12 +13,12 @@ class TestMailerGenerator < MiniTest::Unit::TestCase

def test_mailer_generator
text = capture(:stdout) do
MiniTest::Generators::MailerGenerator.start ["UserWelcome"]
MiniTest::Generators::MailerGenerator.start ["notification"]
end
assert_match(/create test\/mailers\/user_welcome_mailer_test.rb/m, text)
assert File.exists? "test/mailers/user_welcome_mailer_test.rb"
contents = open("test/mailers/user_welcome_mailer_test.rb").read
assert_match(/class UserWelcomeMailerTest < MiniTest::Rails::MailerTestCase/m, contents)
assert_match(/create test\/mailers\/notification_test.rb/m, text)
assert File.exists? "test/mailers/notification_test.rb"
contents = open("test/mailers/notification_test.rb").read
assert_match(/class NotificationTest < MiniTest::Rails::Mailer/m, contents)
ensure
# TODO: Don"t write the files
# I agree, it would be better to mock the file getting written
Expand All @@ -27,12 +27,12 @@ def test_mailer_generator

def test_mailer_generator_spec
text = capture(:stdout) do
MiniTest::Generators::MailerGenerator.start ["UserWelcome", "--spec"]
MiniTest::Generators::MailerGenerator.start ["notification", "--spec"]
end
assert_match(/create test\/mailers\/user_welcome_mailer_test.rb/m, text)
assert File.exists? "test/mailers/user_welcome_mailer_test.rb"
contents = open("test/mailers/user_welcome_mailer_test.rb").read
assert_match(/describe UserWelcomeMailer do/m, contents)
assert_match(/create test\/mailers\/notification_test.rb/m, text)
assert File.exists? "test/mailers/notification_test.rb"
contents = open("test/mailers/notification_test.rb").read
assert_match(/class NotificationTest < MiniTest::Rails::Mailer/m, contents)
ensure
FileUtils.rm_r "test/mailers"
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_model_generator.rb
Expand Up @@ -18,7 +18,7 @@ def test_model_generator
assert_match(/create test\/models\/user_test.rb/m, text)
assert File.exists? "test/models/user_test.rb"
contents = open("test/models/user_test.rb").read
assert_match(/class UserTest < MiniTest::Rails::ModelTestCase/m, contents)
assert_match(/class UserTest < MiniTest::Rails::Model/m, contents)
ensure
# TODO: Don"t write the files
# I agree, it would be better to mock the file getting written
Expand All @@ -32,7 +32,7 @@ def test_model_generator_spec
assert_match(/create test\/models\/user_test.rb/m, text)
assert File.exists? "test/models/user_test.rb"
contents = open("test/models/user_test.rb").read
assert_match(/describe User do/m, contents)
assert_match(/class UserTest < MiniTest::Rails::Model/m, contents)
ensure
FileUtils.rm_r "test/models"
end
Expand Down

0 comments on commit 38c73b2

Please sign in to comment.