2011-06-28 34 views
0

我用ajax提交表格。當表單提交時出現錯誤時,表單再次使用jQuery,jQuery進行呈現。水豚和阿賈克斯測試不起作用

我想如下測試與水豚和Rspec的這種行爲:

形容「板創建失敗」:類型=>:請求做

 it "should not create a birthday board" do 
     Capybara.default_wait_time = 5 
      lambda do 
       visit root_path 
       fill_in "Name",  :with => "" 
       select('1967', :from => "board_birthday_1i") 
       select('October', :from => "board_birthday_2i") 
       select('30', :from => "board_birthday_3i") 
       click_button("Start the surprise") 
       page.should have_selector('div#error_explanation') 
       page.find_field('Name').value 
      end.should_not change(Board, :count) 
     end 
    end 

結果如下:

Failure/Error: page.should have_selector('div#error_explanation') 
     expected following output to contain a <div#error_explanation/> tag: 

但是我確實在頁面上有一個error_explanation div。

爲什麼測試失敗?

預先感謝您。

+0

您是否在某處添加了:js => true選項,以便執行ajax? – grzuy

+0

我在我的寶石文件中同時擁有水豚和網頁。我認爲webrat和水豚之間存在衝突,導致問題 – chell

回答

0

你有沒有試過等待幾秒鐘,直到響應到達。

再次添加sleep(3)

page.should have_selector('div#error_explanation') 

線和測試。 這可能有幫助。