1

I'm a bit unsure about this. Here's my spec:

it 'hides the "Load more" link when the last page is reached', js: true, focus: true do
  within "table.#{model.model_name.underscore.pluralize}" do
    click_link 'Mehr laden'
  end

  page.should have_selector('.load_more a', visible: false)
end

This works, but I'm actually testing the implementation, which is not good practice. So I rewrote the spec like this:

it 'hides the "Load more" link when the last page is reached', js: true, focus: true do
  within "table.#{model.model_name.underscore.pluralize}" do
    click_link 'Mehr laden'
  end

  find_link("Mehr laden").should_not be_visible
end

But sadly, find_link does not wait for the AJAX request to complete, so it fails. If I put a sleep 1 in front of it, it works.

How can I tell find_link to wait (like has_selector?)? I don't want to change any global configuration for this, and wait_until will be deprecated in Capybara 2.

Thanks a lot for help, Josh

4

1 回答 1

0

解决方案实际上非常简单:

page.should have_link('Mehr laden', visible: false)

不知道能不能用上visible: true|falsehave_link很高兴知道。

更新

我不知道这是否普遍正确,但我认为你应该尽可能只使用have_XXX匹配器,而不是像早期find()all()等待内容出现的方法,而后面的不。

于 2013-05-02T06:53:49.467 回答