Rspec:如何在辅助规范中规范 request.env? [英] Rspec: how to spec request.env in a helper spec?

查看:69
本文介绍了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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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