如何从 Rails 中的 RSpec 测试调用应用程序助手方法? [英] How to call an app helper method from an RSpec test in Rails?
本文介绍了如何从 Rails 中的 RSpec 测试调用应用程序助手方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
标题不言自明.
我所尝试的一切都导致了未定义的方法".
Everything I've tried led to a "undefined method".
澄清一下,我不是要测试辅助方法.我正在尝试在集成测试中使用辅助方法.
To clarify, I am not trying to test a helper method. I am trying to use a helper method in an integration test.
推荐答案
你只需要在你的测试中包含相关的 helper 模块来使方法可用:
You just need to include the relevant helper module in your test to make the methods available:
describe "foo" do
include ActionView::Helpers
it "does something with a helper method" do
# use any helper methods here
就这么简单.
这篇关于如何从 Rails 中的 RSpec 测试调用应用程序助手方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文