0

我有一些测试在我可以手动验证应该通过的非常简单的请求上失败。

it { should have_selector('title', text: app_title('Sign in')) }

输出:

expected css "title" with text "CredSimple - Sign in" to return something

除了无法通过测试的消息之外,我想 rspec 告诉我它遇到了什么。是否有一个指令可以用来告诉引擎输出它看到的页面?就像是:

expected css "title" with text "CredSimple - Sign in" to return something **instead returned text "Wrong Page Title"** 
4

1 回答 1

1

我在 rspec 中找到了一种使用save_and_open_page语句的方法。这将创建一个可以在编辑器或浏览器中查看的 HTML 转储,以便您可以确定测试源中的内容。

为了实现这一点,我采取了以下步骤

  • 将 gem 'launchy' 添加到 Gemfile
  • $捆绑安装
  • 将 save_and_open_page 插入我正在尝试调试的测试的 it { } 块中
  • 位置很重要:

    它 { save_and_open_page 应该有_selector('div.alert') }

于 2012-11-15T21:52:00.783 回答