【发布时间】:2012-05-02 03:19:52
【问题描述】:
我已经谷歌并阅读了大约 4 小时的 stackoverflow,但无法理解,为什么类似于 rails 教程的测试失败。
测试很简单:
# encoding: utf-8
require 'spec_helper'
describe "StaticPages" do
subject { page }
describe "Contacts page" do
before { visit contacts_path }
it { should have_selector(:title, text: "|") }
end
end
所以,我添加了 save_and_open_page 来看看我的联系人页面有什么问题,但它看起来不错。存在标题标签并包含“|”。
我不明白,怎么了。我已经:
- 尝试获取而不是访问;
- 改为响应页面;
- 在正文中永久检查其他内容(body.should have_selector(:h1))。
我还试图了解如何将 rspec 输出提高到更多信息。现在我看到了:
Failure/Error: it { should have_selector(:title, text: "|") }
expected id :title with text "|" to return something
【问题讨论】:
-
没有人问我怎么做。我问为什么 have_selector 不起作用。我发现,如果我使用字符串“title”而不是 symbol :title - 我的示例工作正常。
标签: ruby-on-rails rspec