提交 fb89aba8 编写于 作者: J José Valim

Killing fixtures in mailer before they kill me (they usually lead to very brittle tests).

上级 d289e15a
...@@ -11,7 +11,7 @@ def copy_view_files ...@@ -11,7 +11,7 @@ def copy_view_files
actions.each do |action| actions.each do |action|
@action = action @action = action
@path = filename_with_extensions(File.join(base_path, action)) @path = File.join(base_path, filename_with_extensions(action))
template filename_with_extensions(:view), @path template filename_with_extensions(:view), @path
end end
end end
......
...@@ -9,13 +9,6 @@ class MailerGenerator < Base ...@@ -9,13 +9,6 @@ class MailerGenerator < Base
def create_test_files def create_test_files
template "functional_test.rb", File.join('test/functional', class_path, "#{file_name}_test.rb") template "functional_test.rb", File.join('test/functional', class_path, "#{file_name}_test.rb")
end 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 end
end end
<%= class_name %>#<%= @action %>
Hi, find me in app/views/<%= @path %>
...@@ -3,12 +3,11 @@ ...@@ -3,12 +3,11 @@
class <%= class_name %>Test < ActionMailer::TestCase class <%= class_name %>Test < ActionMailer::TestCase
<% for action in actions -%> <% for action in actions -%>
test "<%= action %>" do test "<%= action %>" do
@expected.subject = <%= action.to_s.humanize.inspect %> mail = <%= class_name %>.<%= action %>
@expected.to = "to@example.org" assert_equal <%= action.to_s.humanize.inspect %>, mail.subject
@expected.from = "from@example.com" assert_equal ["to@example.org"], mail.to
@expected.body = read_fixture("<%= action %>") assert_equal ["from@example.com"], mail.from
assert_match "Hi, find me in app", mail.body.encoded
assert_equal @expected, <%= class_name %>.<%= action %>
end end
<% end -%> <% end -%>
......
...@@ -28,9 +28,11 @@ def test_check_class_collision ...@@ -28,9 +28,11 @@ def test_check_class_collision
def test_invokes_default_test_framework def test_invokes_default_test_framework
run_generator run_generator
assert_file "test/functional/notifier_test.rb", /class NotifierTest < ActionMailer::TestCase/ assert_file "test/functional/notifier_test.rb" do |test|
assert_file "test/fixtures/notifier/foo", /app\/views\/notifier\/foo$/ assert_match /class NotifierTest < ActionMailer::TestCase/, test
assert_file "test/fixtures/notifier/bar", /app\/views\/notifier\/bar$/ assert_match /test "foo"/, test
assert_match /test "bar"/, test
end
end end
def test_invokes_default_template_engine def test_invokes_default_template_engine
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册