2014-04-08 41 views
3

我使用的水豚2.x的一些集成測試了很大的Rails/AngularJS應用程序,我已經遇到一個測試中,我需要把睡眠得到它的工作。水豚等AJAX不使用的睡眠

我的測試:

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 

它使用納克 - 表,這需要一秒來更新測試的代碼,而無需睡眠它將失敗。水豚以前有一個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-表(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())) 
    }) 

回答

0

嘗試碰撞的Capybara.default_wait_time長達3秒鐘或4.

如果失敗,嘗試改變spec在查看是否已從頁面中刪除項目之前查找Flash通知消息。 (假設閃光燈消息中的HTML身體得到渲染)

describe "#delete", js: true do 
    it "deletes a costing" do 
    costing = Costing.make! 

    visit "/api#/costings" 
    page.should have_content("General") 

    click_link "Delete" 

    page.should have_content("Costing deleted") 
    page.should_not have_content("General") 
    end 
end 

編輯 - 刪除解釋,因爲這是不正確的。

+0

它仍然在should_not測試中斷,它通過了flash消息測試。我也嘗試將缺省的等待時間提高到5秒,但它沒有幫助。我仍然需要睡覺。 – map7