本文介绍了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?
发布评论