2014-09-13 41 views
0

我刚刚做了save_and_open_page,所以这里是我想要点击进行集成测试的html。无法检查水豚中的复选框

<input id="tos" name="tos" type="checkbox" value="{:id=>"tos"}"> 
<label for="tos">I have read and agree to the <a href="/termsofservice" style="color:#428bca" target="_blank">Terms of Service</a>.</label> 

,代码:

<%= check_box_tag :tos, id: "tos" %> 
<%= label_tag "tos", "I have read and agree to the #{link_to 'Terms of Service', terms_path, { style: "color:#428bca", target: "_blank" }}.".html_safe %> 

下面是检查我试图

find(:xpath, "//*[@id='tos']").set(true) 
check 'tos' 
find("#tos").set(true) 
check 'I have read and agree to the Terms of Service' 
check 'I have read and agree to the "<a href="/termsofservice" style="color:#428bca" target="_blank">Terms of Service</a>".'    
find(:css, "#tos[value='{:id=>&quot;tos&quot;}']").set(true) 
find(:css, "#tos[value='{:id=>'tos'}']").set(true) 

的东西的所有失败的方式这是为什么这么难?

确定更多相关内容:

该规范的完整流程是:

 describe "something" do 

     before do 
      visit '/original' 
      page.check("tos") 
      fill_in 'signup_email1', :with => "[email protected]" 
      click_button 'lend' 
      save_and_open_page 
      fill_in 'inventory_1', :with => 1 
      click_button 'submit_lend' 
     end 

     it "should achieve some result" do 
     ... 
     end 

     end 

之后每次尝试我试过到目前为止,该错误信息只是

Failure/Error: fill_in 'inventory_1', :with => 1 
Capybara::ElementNotFound: 
    Unable to find field "inventory_1" 

因为它反映的是,当再click_button 'lend'发生,用户不会被导向页面借出有inventory_1的东西,因为他们得到的/original页面会重新呈现,并显示错误(通过save_and_open_page确认),指出在继续之前必须同意服务条款。

+1

你没有显示错误消息,您的任何企图。尝试'page.check(“tos”)'并显示输出。 – pawel7318 2014-09-13 11:58:44

+0

试过了,没有工作,我发布了更多的上下文和错误消息,对不起,我遗漏了它,因为它似乎在这种情况下不会太有用。 – james 2014-09-15 01:14:19

回答

0

好吧,它的工作......也许充其量,这是一个不良开关实践的提醒。在我为页面写出代码后,我写了测试(反过来我知道......)。在这种情况下,当我写测试并写出check 'tos'时,我回到视图中,并将id: 'tos'添加到。这是错误的,的第二个参数是值,所以通过增加我使得始终取值为tos而不是1(如果选中),并且0如果不是。

基本上,规范,check 'tos'工作正常,如果在视图中你就必须<%= check_box_tag "tos %>