【发布时间】:2010-10-27 03:59:24
【问题描述】:
我有一个视图助手方法,它通过查看 request.domain 和 request.port_string 来生成一个 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>`
谁能帮我弄清楚我应该怎么做才能解决这个问题? 我如何模拟此示例的“请求”对象?
有没有更好的方法来生成使用子域的 url?
提前致谢。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 rspec rspec2 view-helpers