我正在尝试为帮助者编写测试。目前我的代码如下:
application_helper_test.rb
require File.dirname(__FILE__) + '/../test_helper'
class ApplicationHelper < ActiveSupport::TestCase
def test_title
assert_equal "Test", title
end
end
application_helper.rb
module ApplicationHelper
def title
controller_name.humanize
end
end
但是我的终端出现了这个错误,有什么帮助吗?
Run options: --seed 4320
# Running:
E
Finished in 0.022048s, 45.3556 runs/s, 0.0000 assertions/s.
1) Error:
ApplicationHelper#test_title:
NameError: undefined local variable or method `title' for #<ApplicationHelper:0x007fd4eef00760>
application_helper_test.rb:7:in `test_title'
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
答案 0 :(得分:0)
我猜你的断言就是问题所在。它应该是:
assert_equal "Test", ApplicationHelper.title
另外,一条建议是将您的测试类名称从ApplicationHelper重命名为ApplicationHelperTest。
<强>更新强>: 您的模块应略有改变:
module ApplicaitonHelper
def self.title
controller_name.humanize
end
end