2012-08-07 93 views
0

以下是相關測試:Rspec的測試與水豚即使save_and_open_page未能正確

#spec/requests/posts_spec.rb 
require 'spec_helper' 
describe "Posts pages" do 
    subject { page } 
    describe "edit" do 
    let (:post) { Post.order('release_date desc').first } 
    before do 
     visit posts_path 
     within(:css, "div#post_#{post.id}") { click_link "Edit" } 
     save_and_open_page # has correct title 
    end 

    it { should have_selector('title', "Editing #{post.title}") } # fails 
    end 
end 

失敗消息:

1) Posts pages edit 
Failure/Error: it { should have_selector('title', "Editing #{post.title}") } 
    expected css "Editing unde inventore illo accusamus" to return something 

然而,當頁面在瀏覽器中通過save_and_open_page打開,標題是正確的,它已打開正確的edit頁面。我仔細檢查模板中的任何拼寫錯誤與測試,並且匹配。

那麼我錯過了什麼?

+0

嘗試使用調試器,並與您的數據一起玩,以確定是否丟失或不正確。 – 2012-08-07 23:36:18

回答

2

您的語法錯誤have_selector是錯誤的。試試這個:

it { should have_selector('title', :text => "Editing #{post.title}") } 
+0

善良。我感覺這很簡單。我真的需要在一天結束時停止編碼。謝謝! – 2012-08-08 14:43:47