问题描述
**通过测试的辅助方法**
module ApplicationHelper
def full_title(page_title= '')
base_title = 'Tweeter_clone'
if page_title.empty?
base_title
else
page_title + " | " + base_title
end
end
end
**不通过测试并返回空字符串“” **
的辅助方法module ApplicationHelper
def full_title(page_title= '')
base_title = 'Tweeter_clone'
if page_title.empty?
base_title
else
`#{page_title} | #{base_title}`
end
end
end
以下是实际测试。我真的不明白为什么在这种情况下字符串插值不起作用,但是串联却不能。
require 'test_helper'
class ApplicationHelperTest < ActionView::TestCase
test "full title helper" do
assert_equal 'Tweeter_clone',full_title
assert_equal "Help | Tweeter_clone",full_title("Help")
end
end
我确实在test_helper.rb中包含了applicationHelper
解决方法
语法问题。在Ruby中使用双引号,在Javascript中使用反引号。