Rspec:如何在辅助规范中规范 request.env?

编程入门 行业动态 更新时间:2024-10-26 01:32:55
本文介绍了Rspec:如何在辅助规范中规范 request.env?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的辅助模块中,我有:

In my helper module, I have:

def abc(url) ... if request.env['HTTP_USER_AGENT'] do something end end

在我的规范文件中,我有:

In my spec file, I have:

describe "#abc" do before(:each) do @meth = :abc helper.request.env['HTTP_USER_AGENT'] = "..." end it "should return the webstart jnlp file" do @obj.send(@meth, "some_url").should .... end end

运行规范时出现此错误:

When I run the spec I have this error:

undefined local variable or method `request' for <ObjectWithDocHelperMixedIn:0x00000103b5a7d0>

如何在我的规范中存根 request.env['...']?

How do I stub for request.env['...'] in my specs?

谢谢.

推荐答案

如果您正在使用 rspec-rails,您或许可以在辅助测试中使用 controller.request.

If you're using rspec-rails, you might be able to use controller.request in your helper tests.

更多推荐

Rspec:如何在辅助规范中规范 request.env?

本文发布于:2023-11-23 09:05:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620870.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Rspec   env   request

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!