如何编写测试来检查表单上的路径?
我正在尝试这个:
it "has a proper form path given subdomains" do
@event = Factory :event
get events_path(@event), nil, {'HTTP_HOST' => 'staging.example.com' }
page.should have_selector "form", :action => "secure.staging.example.com"
end
但看起来我的测试看起来并不合适:
Failure/Error: page.should have_selector "form", :action => "secure.staging.example.com"
expected css "form" to return something
# ./spec/requests/events_spec.rb:18:in `block (3 levels) in <top (required)>'
答案 0 :(得分:1)
我在解决这个问题时学到了很多,就像page and response variables之间的差异一样。
我真正需要做的是编写a helper spec来测试我的url_for辅助方法是否正确地预先添加子域。但我也想出了视图规范代码:
it "has a proper form path given subdomains" do
assign :event, Factory(:event)
controller.request.host = "staging.example.com"
render
assert_select "form[action*=?]", "secure.staging.example.com"
end