我有一个视图助手方法,它通过查看请求的域名和端口字符串来生成一个URL。
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'对象?是否有更好的方法生成使用子域的URL?谢谢。
expect (helper.request.subdomain).to eq('merchant')
- shailesh