ruby-on-rails - 我如何在 Rails 中测试助手?

标签 ruby-on-rails ruby helpers

我正在尝试构建一些单元测试来测试我的 Rails 助手,但我永远不记得如何访问它们。恼人的。有什么建议吗?

最佳答案

在 Rails 3 中,您可以这样做(实际上这是生成器创建的内容):

require 'test_helper'

class YourHelperTest < ActionView::TestCase
  test "should work" do
    assert_equal "result", your_helper_method
  end
end

当然还有the rspec variant by Matt Darby也适用于 Rails 3

关于ruby-on-rails - 我如何在 Rails 中测试助手?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/440571/

相关文章:

ruby - Ruby 中的 Enumerable#each 和 Enumerable#each_entry 之间有区别吗?

ruby - 使用标准库仅提取 Ruby 中正则表达式的第二个匹配项

ruby-on-rails - 多次渲染 - 在 rails 中双重渲染

ruby-on-rails - Xcode 4.4 和 OSX 10.8 安装后 - 安装 libv8 时为 'Failed to build gem native extension'

ruby-on-rails - 在运行包更新时避免 RSA key 指纹

php - 如何从 CakePHP 中的 Controller 访问助手?

ruby - 如何检索内容的 HTML?

ruby-on-rails - rails 5 : NoMethodError: undefined method `helper' for MyMailer

ruby-on-rails - Hartl Rails 教程的 Users#index 中的 ArgumentError

url - 自定义错误页面中的 Silex 和 Twig 助手