2012-05-01 12 views
0

我谷歌和讀取約4個小時的stackoverflow,但不明白,爲什麼類似於鐵路教程測試失敗。RSpec:應該has_selector失敗,但標題存在

測試很簡單:


# encoding: utf-8 

require 'spec_helper' 

describe "StaticPages" do 
    subject { page } 

    describe "Contacts page" do 
    before { visit contacts_path } 

    it { should have_selector(:title, text: "|") } 
    end 
end

所以,我想補充save_and_open_page看看,有什麼錯我的聯繫人頁面,但它看起來不錯。標題標籤存在幷包含「|」。

我不明白,怎麼了。我有:

  • tryed get instead visit;
  • 反應頁面;
  • 檢查其他物體永久性(body.should have_selector(:h1))。

此外,我試着瞭解,如何提高rspec輸出到更多infomative。在現在我明白了:

Failure/Error: it { should have_selector(:title, text: "|") } 
     expected id :title with text "|" to return something 
+0

提問和回答的http://stackoverflow.com/questions/5129423/capybara-how-to-test-the-title-of-a-page –

+1

我不是問怎麼樣。我問爲什麼have_selector不起作用。我發現,如果我使用字符串「標題」,而不是符號:標題 - 我的示例工作正常。 – Kulti

回答

1

據我所知have_selector是水豚匹配,並根據tutorial作爲第一個參數,你可以使用引號引起來的html元素名稱或XPath符號,而不是象徵。

+0

謝謝,我在4個小時前給自己清楚:)但是,這是正確的答案,我標記它。 – Kulti

相關問題