我正在尝试在我的 rails 应用程序中编写一些功能测试,在 application_controller.rb 中我有这个:
before_filter :current_account
def current_account
@current_account ||= Account.find_by_subdomain!(request.subdomians.first)
end
运行测试时,
request.subdomains
不包含我正在寻找的有效子域,因此无法运行任何功能测试。是否可以 stub
current_account
方法或模拟 request.subdomains
对象? 最佳答案
在您的功能测试中,您应该能够做到(使用 mocha):
@request.expects(:subdomains).returns(['www'])
关于ruby-on-rails - 如何在 Rails 中 stub 或模拟 request.subdomains 方法?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1004832/