我有一个视图助手方法,它通过查看request.domain和request.port_string来生成一个url。如何模拟RSpec帮助程序测试的请求对象?
module ApplicationHelper
def root_with_subdomain(subdomain)
subdomain += "." unless subdomain.empty?
[subdomain, request.domain, request.port_string].join
end
end
我想用rspec来测试这个方法。
describe ApplicationHelper do
it "should prepend subdomain to host" do
root_with_subdomain("test").should = "test.xxxx:xxxx"
end
end
但是当我运行这个使用RSpec,我得到这个:
Failure/Error: root_with_subdomain("test").should = "test.xxxx:xxxx" `undefined local variable or method `request' for #<RSpec::Core::ExampleGroup::Nested_3:0x98b668c>`
任何人都可以请帮我找出我应该怎么做才能解决这个问题? 我该如何嘲笑这个例子中的'request'对象?
有没有更好的方法来生成使用子域名的网址?
在此先感谢。
它给错误:遇到异常:#
shailesh
2013-04-23 04:34:37