Ruby on rails 3 编写rspec测试以检查表单路径

Ruby on rails 3 编写rspec测试以检查表单路径,ruby-on-rails-3,rspec,integration-testing,Ruby On Rails 3,Rspec,Integration Testing,如何编写测试来检查表单上的路径 我正在尝试这个: 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.examp

如何编写测试来检查表单上的路径

我正在尝试这个:

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)>'
失败/错误:page.should_选择器“form”,:action=>“secure.staging.example.com”
期望css“表单”返回某些内容
#./spec/requests/events_spec.rb:18:in'block(3层)in'

在解决这一问题时,我学到了很多关于测试的知识,比如它们之间的区别

我真正需要做的是编写测试我的url\u for helper方法是否正确地预先设置了子域。但我也算出了视图规范代码:

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

我学到了很多关于测试的知识,在解决这个问题的过程中,我发现了它们之间的区别

我真正需要做的是编写测试我的url\u for helper方法是否正确地预先设置了子域。但我也算出了视图规范代码:

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