2013-02-05 40 views
0

你好,我有一個Rspec +水豚的問題。我想測試我的ajax評論可以發佈。我的錯誤是因爲帖子沒有創建。使用Rspec進行Ajax評論

Failure/Error: page.should have_content('Could') 

當我輸出@post我看到

#<Post id: 1, title: "Deploying through ssh", body: "This is post about ssh", slug: deploying-through-ssh, published: nil, published_at: nil, created_at: "2013-02-05 17:37:39", updated_at: "2013-02-05 17:37:39", user_id: nil, meta_desc: nil> 

describe "Sending Comments" do 
     before(:each) do 
     @post = FactoryGirl.create(:post) 
     end 
     it "should allow user to post new comment", :js => true do 
     visit post_path(@post) 
     page.should have_content('Could') 
     fill_in 'comment[name]', :with => "name" 
     fill_in 'comment_email', :with => "[email protected]" 
     fill_in 'comment_content', :with => "content" 
     end 
    end 

回答

0

如果你不這樣做正確的設置,你的測試,你的服務器,用於與硒(:js => true)測試,將使用兩個不同的數據庫連接並將測試包裝到事務中。 這導致了這種情況,即您在測試中看到的@post在瀏覽器中不存在,因爲事務中的更改未提交。

您可以使用描述爲here或不使用事務性清理策略的共享連接。看看database-cleaner