以下是相关测试:
#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 :(得分:2)
have_selector
的语法错误。试试这个:
it { should have_selector('title', :text => "Editing #{post.title}" ) }