Ruby on rails Rails应用程序中的帮助程序测试错误

Ruby on rails Rails应用程序中的帮助程序测试错误,ruby-on-rails,ruby,testing,ruby-on-rails-4,helpers,Ruby On Rails,Ruby,Testing,Ruby On Rails 4,Helpers,我正在尝试为助手编写一个测试。目前我的代码如下所示: 应用程序帮助程序测试.rb require File.dirname(__FILE__) + '/../test_helper' class ApplicationHelper < ActiveSupport::TestCase def test_title assert_equal "Test", title end end 但是我的终端出现了这个错误,有什么帮助吗 Run options: --seed 432

我正在尝试为助手编写一个测试。目前我的代码如下所示:

应用程序帮助程序测试.rb

require File.dirname(__FILE__) + '/../test_helper'

class ApplicationHelper < ActiveSupport::TestCase

  def test_title
    assert_equal "Test", title
  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
运行选项:--seed 4320
#运行:
E
以0.022048s、45.3556次运行/秒、0.0000次断言/秒的速度完成。
1) 错误:
ApplicationHelper#测试_标题:
NameError:未定义的局部变量或方法“title”#
应用程序\u helper\u test.rb:7:in'test\u title'
1次运行,0次断言,0次失败,1次错误,0次跳过

我想你的断言就是问题所在。应该是:

assert_equal "Test", ApplicationHelper.title
另外,一个建议是将测试类名从ApplicationHelper重命名为ApplicationHelperTest

更新: 您的模块应稍作更改:

module ApplicaitonHelper
   def self.title
      controller_name.humanize
   end
end

'NoMethodError:ApplicationHelper:Module'的未定义方法'title'无法修复it@siaw23:更新了我的答案。尝试一下,因为我没有在这台机器上安装ruby。答案完全是根据我的经验得出的:我发现问题在于测试中方法的名称。但是为什么呢?我不明白。
module ApplicaitonHelper
   def self.title
      controller_name.humanize
   end
end