如何在Rails中测试助手? [英] How do I test helpers in Rails?

查看:82
本文介绍了如何在Rails中测试助手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to build some unit tests for testing my Rails helpers, but I can never remember how to access them. Annoying. Suggestions?

推荐答案

在rails 3中,您可以执行此操作(实际上这是生成器创建的):

In rails 3 you can do this (and in fact it's what the generator creates):

require 'test_helper'

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

当然, Matt Darby的rspec变体也可以在Rails 3中使用

And of course the rspec variant by Matt Darby works in rails 3 too

这篇关于如何在Rails中测试助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆