我是测试新手,我正在尝试在links_spec.rb
.
describe "Links" do
before :each do
activate_authlogic
@company = Factory.build(:company)
# next line creates errors
@user = Factory.build(:user, :user_type => "Company", :user_type_id => @company.id)
UserSession.create( @company.user )
end
it "redirects to index after create" do
link = Factory.build(:link)
post "links"
response.should redirect_to(links_path)
end
end
首先,该@user = Factory.build(...)
行抛出一个错误,因为它说用户是重复的——我不知道用户是在哪里创建的,因为公司和用户没有适当的多态关系(这是另一个故事),而 Company.rb 没有创建时自动创建用户。
所以,当我删除那条线时,一切似乎都很好,除非它到达这response.should redirect...
条线。而不是重定向到links_path
,测试失败并告诉我:
Failure/Error: response.should redirect_to(links_path)
Expected response to be a redirect to <http://www.example.com/links> but was a redirect to <http://www.example.com/home>
# ./spec/requests/links_spec.rb:13:in `block (2 levels) in <top (required)>'
我不明白为什么会发生这种情况或如何解决它。