我正在使用 Capybara 2.x 对大型 Rails/AngularJS 应用程序进行一些集成测试,并且我遇到了一个测试,我需要在其中休眠以使其正常工作。
我的测试:
describe "#delete", js: true do
it "deletes a costing" do
costing = Costing.make!
visit "/api#/costings"
page.should have_content("General")
click_link "Delete" # Automatically skips the confirm box when in capybara
sleep 0.4
page.should_not have_content("General")
end
end
它测试的代码使用 ng-table ,它需要一秒钟的时间来更新,没有睡眠它会失败。Capybara 曾经为此有一个 wait_until 方法,但它已被取出。我找到了这个网站:http ://www.elabs.se/blog/53-why-wait_until-was-removed-from-capybara但无法获得任何推荐的替代方案来解决这个问题。
这是我正在测试的代码。
# --------------------------------------------------------------------------------
# Delete
# --------------------------------------------------------------------------------
$scope.destroy = (id) ->
Costing.delete (id: id), (response) -> # Success
$scope.tableParams.reload()
flash("notice", "Costing deleted", 2000)
这会更新 ng-table(tableParams 变量),即此代码
$scope.tableParams = new ngTableParams({
page: 1,
count: 10,
sorting: {name: 'asc'}
},{
total: 0,
getData: ($defer, params) ->
Costing.query {}, (data) ->
# Once successfully returned from the server with my data process it.
params.total(data.length)
# Filter
filteredData = (if params.filter then $filter('filter')(data, params.filter()) else data)
# Sort
orderedData = (if params.sorting then $filter('orderBy')(filteredData, params.orderBy()) else data)
# Paginate
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()))
})