button_to表单提交在浏览器中工作但是没有rspec / capybara测试,路由错误
我正在使用rspec和capybara编写集成测试,用于覆盖现有function的rails4应用程序(当我第一次编写应用程序时,我很懒)。 以下提交按钮在浏览器(Chrome)中正常工作,并重定向到成功页面(如预期的那样)
"open-contacts-dialog-btn", :class => "inbox-sf-add-btn tip", :style => "background:lightgreen" %>
但是,以下测试失败,
describe "should show confirmation message after submitting the form" do it "should go to success message when form submitted" do click_link 'See more details' click_button 'Sign Me Up!' fill_in 'Email', with: "simon@example.com" fill_in 'attendee_name', with: "Simon T" fill_in 'attendee_phone', with: "1234567890" fill_in 'attendee_num_guests', with: "1" click_on 'RSVP Now' page.should have_content("Awesome! You're signed up.") end end
出现以下错误:
Failure/Error: click_on 'RSVP Now' ActionController::RoutingError: No route matches [POST] "/events/%23%3CActionView::Helpers::FormBuilder:0x007ff9d7e003c0%3E/attendees/new"
我的路线看起来像这样: https : //gist.github.com/srt32/6076872
我有点迷失,因为从用户的角度来看,这个动作是有效的,但是我无法通过测试来复制这个行为。 任何帮助,将不胜感激。 谢谢!
你想要一个常规的提交标签。
如果使用表单助手块:
<%= f.submit "RSVP Now" %>
或者使用独立标记助手:
<%= submit_tag "RSVP Now" %>
阅读有关button_to
如何工作的文档 。 它主要用作应该POST的链接,例如以某种方式更改数据的操作。 它不适用于普通forms。