即使save_and_open_page正确,Rspec测试也会失败并与水豚失败

时间:2012-08-07 23:28:16

标签: ruby-on-rails ruby-on-rails-3 capybara rspec2

以下是相关测试:

#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页面。我仔细检查了模板与测试中的任何拼写错误,并且匹配起来。

那么我错过了什么?

1 个答案:

答案 0 :(得分:2)

have_selector的语法错误。试试这个:

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