我在我的项目中添加了Subdomain-fu。在ApplicationController中,我有before_filter,它检查url,并将app.com重定向到www.app.com,www.subdomain.app.com重定向到subdomain.app.com,并检查帐户是否存在(如果不存在,则重定向到主页):
before_filter :check_uri
def check_uri
if !subdomain?
redirect_to http_protocol + "www." + current_host + request.request_uri if !/^www\./.match(current_host)
elsif /^www\./.match(current_host)
redirect_to http_protocol + current_host.gsub(/^www\./, '') + request.request_uri
elsif !account_subdomain?
redirect_to http_protocol + "www" + current_host.gsub(account_subdomain, '')
end
end上面的代码运行得很好。但是在添加了这个片段之后,我的Cucumber测试,例如。这一条:
Scenario: Successful sign up
Given I am an anonymous user
And an Accept Language header
And I am on the home page
When I follow "Join now!"
And ...失败并返回错误:
Webrat::NotFoundError: Could not find link with text or title or id "Join now!"
(eval):2:in `/^I follow "([^\"]*)"$/'
features/manage_users.feature:10:in `When I follow "Join now!"'如果我注释这个before_filter,一切都运行得很好。有人知道为什么吗?
发布于 2009-12-28 15:58:54
我可以看出Webrat非常喜欢域名"example.com“,并模仿它的所有步骤。
所以如果你不使用子域,你可以在你的步骤中写道:
Before do
host! "example.com"
end而且你所有的重定向都应该可以工作(我不检查)。有了Subdomain-fu,情况就更糟了。所有你应该做的事情--正确地配置你的subdomain-fu配置文件:
SubdomainFu.tld_sizes = {:development => 0,
:test => 1, # not 0, even if you use *.localhost in development
:production => 1}并且在没有任何主机的情况下使用重定向进行测试!"example.com"。
https://stackoverflow.com/questions/1959561
复制相似问题