2011-06-12 29 views
4

我想在Rails 3.0.8中使用水豚(頭)和Selen寫一個集成測試。我想測試一下,當用戶點擊我網頁上的某個項目的刪除按鈕時,該項目實際上被刪除。等網頁,我隱藏使用jQuery項目片斷我怎樣才能測試一個項目從水豚和硒的頁面中刪除?

$('#interaction').fadeOut(); 

我用的是後續RSpec的測試,並Capybara.default_wait_time設置爲5秒,但似乎沒有給我一個測試通過。我如何正確測試這個?

describe "A User adding an Interaction" do 
    describe "when looking at an Item detail page" do 
    it "should be able to delete and existing interaction", :js => true do 
     sign_in_and_view_item 
     page.should have_content "ITEM DETAILS - #{@item.name}" 
     fill_in "interaction-input", :with => "My Interaction" 
     click_button "item-interaction-submit" 
     page.should have_content "My Interaction" 
     click_link "Delete Interaction" 
     wait_until do 
     page.evaluate_script('$.active') == 0 
     end 
     #page.should_not have_content "My Interaction" 
     page.should have_no_content "My Interaction" 
    end 
    end 
end 

回答

3

我結束了使用該規範

需要 'spec_helper'

describe "A User adding an Interaction" do 
    describe "when looking at an Item detail page" do 
    it "should be able to delete and existing interaction", :js => true do 
     sign_in_and_view_item 
     page.should have_content "ITEM DETAILS - #{@item.name}" 
     fill_in "interaction-input", :with => "My Interaction" 
     click_button "Save" 
     page.should have_content "My Interaction" 
     click_link "Delete Interaction" 
     should_be_hidden "My Interaction" 
    end 
    end 
end 

使用此功能should_be_hidden一起加入這行來我的規格/ spec_helper.rb

Capybara.ignore_hidden_elements = false 

def should_be_hidden text, selector='' 
    sleep Capybara.default_wait_time 
    its_hidden = page.evaluate_script("$('#{selector}:contains(#{text})').is(':hidden');") 
    its_not_in_dom = page.evaluate_script("$('#{selector}:contains(#{text})').length == 0;") 
    (its_hidden || its_not_in_dom).should be_true 
end 
相關問題