0

这是相关的测试:

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

那么我错过了什么?

4

1 回答 1

2

你的语法have_selector是错误的。尝试这个:

it { should have_selector('title', :text => "Editing #{post.title}" ) }
于 2012-08-08T01:01:51.067 回答