如何在Rails中实现request.subdomains的存根或模拟功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计125个文字,预计阅读时间需要1分钟。
我尝试在我的rails应用中编写一些功能测试,在`application_controller.rb`中我添加了如下代码:
rubybefore_filter :current_accountdef current_account @current_account=Account.find_by_subdomain!(request.subdomains.first)end
我试图在我的rails应用程序中编写一些功能测试,在application_controller.rb中我有:before_filter :current_account def current_account @current_account ||= Account.find_by_subdomain!(request.subdomians.first) end
运行测试时,request.subdomains不包含我正在寻找的有效子域,因此无法运行任何功能测试.
是否可以存根current_account方法或模拟request.subdomains对象?
在你的功能测试中你应该能够做到(使用mocha):@request.expects(:subdomains).returns(['www'])
本文共计125个文字,预计阅读时间需要1分钟。
我尝试在我的rails应用中编写一些功能测试,在`application_controller.rb`中我添加了如下代码:
rubybefore_filter :current_accountdef current_account @current_account=Account.find_by_subdomain!(request.subdomains.first)end
我试图在我的rails应用程序中编写一些功能测试,在application_controller.rb中我有:before_filter :current_account def current_account @current_account ||= Account.find_by_subdomain!(request.subdomians.first) end
运行测试时,request.subdomains不包含我正在寻找的有效子域,因此无法运行任何功能测试.
是否可以存根current_account方法或模拟request.subdomains对象?
在你的功能测试中你应该能够做到(使用mocha):@request.expects(:subdomains).returns(['www'])

