如何与rspec和capyabara协调动画的计时

如何与rspec和capyabara协调动画的计时,rspec,capybara,Rspec,Capybara,我无法在不呼叫睡眠的情况下让rspec测试正常工作: it 'should allow deleting of foo brand attributes', :js => true do @foo.brand_attributes << BrandAttribute.new(key: :tes

我无法在不呼叫睡眠的情况下让rspec测试正常工作:

it 'should allow deleting of foo brand attributes', :js => true do                                                                                            
  @foo.brand_attributes << BrandAttribute.new(key: :test, value: :test)                                                                                 
  @foo.save!                                                                                                                                            
  @foo.brand_attributes.length.should eq 1                                                                                                              
  visit('/admin')                                                                                                                                         
  expect(page).to have_content 'Test Foo'                                                                                                               
  click_link 'Edit'    
  # Edit opens a modal edit form with a list of attribute fields                                                                                                                                   
  page.should have_selector('#edit-modal-div', visible: true)                                                                                            
  page.should have_selector('.attribute_fields', visible: true)
  page.should have_selector('.attribute_fields input[type=hidden]') 
  # 1st sleep:
  sleep 0.3                                                                                      
  within(:css, "#edit-modal-div") do   
    # should update hidden input with destroy value                                                                                                                  
    click_link 'Delete'                                                                                                                                   
  end
  # 2nd sleep                                                                                                                                               
  sleep 0.3                                                                                                                                               
  page.should have_selector('.attribute_fields', visible: false)                                                                                          

  within(:css, "#edit-modal-div") do                                                                                                                     
    click_button 'Save'                                                                                                                                   
  end                                                                                                                                                     

  page.find('.alert').should have_content 'successfully updated'                                                                                          
  @foo = Foo.find(@food.id)                                                                                                                          
  @foo.brand_attributes.length.should eq 0 
it'应该允许删除foo品牌属性',:js=>true do

@foo.brand_属性
have_…
匹配器可用于大多数以前使用过
wait_的情况。当“删除”按钮准备就绪时,页面上是否有某些内容同时出现/消失?这三个选项都有。。。在我的示例中,选择器都会检查删除按钮出现时出现的元素。但是,即使是附加到Delete按钮的简单onclick也不会执行。
<a class="destroy_link" href="#" onclick="x = 4; return false;">Delete</a>