2012-08-17 53 views
4

我正在嘗試使用Capybara編寫Rspec請求規範。似乎所有東西都正常工作除了水豚看到頁面爲空白。爲什麼Capybara無法看到此頁面的內容?

好的跡象:

  • 該頁面加載在瀏覽器中
  • 尾礦日誌精細顯示,正確的觀點是試運行期間呈現
  • 任何記錄語句我把意見執行
  • 如果我使用assert_select "h1", :text => "hello world",測試通過。

不良苗頭:

  • 如果我使用page.should have_content('hello world'),它失敗了,說Capybara::ElementNotFound: Unable to find xpath "/html"
  • 如果我做$stdout.puts page.html,這是除了一個DOCTYPE

我的測試看起來像空這個:

describe "working with foos" do 
    it "should have a 'new foo' form" do 
    get '/foos/new' 
    assert_select 'h1', text: 'hello world' # passes 
    page.should have_content('hello world') # fails 
    $stdout.puts page.html     # empty except for a doctype 
    end 
end 

這裏有什麼問題?

回答

7

額頭拍打答案

......我正在分享以拯救他人同樣的痛苦。

水豚使用visit方法來設置其頁面變量。

visit '/assembly/manage/task_lists/new' 

不要與水豚使用get

get '/assembly/manage/task_lists/new' 
相關問題