ruby-on-rails - RSpec Controller 测试屏幕上的文本失败
问题描述
我在 h1 元素中有一个带有“设置”的索引视图。
<div id="settings-main-container">
<div id="settings-main-title">
<h1 id="settings-title">Settings</h1>
</div>
<%=link_to admin_clients_index_path do%>
<div class="settings-button">
Select Active Client
</div>
<%end%>
<%=link_to admin_settings_assign_users_to_clients_index_path do%>
<div class="settings-button">
Assign Users to Clients
</div>
<%end%>
<%=link_to destroy_user_session_path, method: :delete do%>
<div class="settings-button">
Logout
</div>
<%end%>
</div>
我有我的测试设置
describe "GET index" do
render_views
...
it "should have text on the screen" do
get :index
response.should have_text("Settings")
end
end
我不断收到错误
Failure/Error: response.should have_text("Settings")
expected to find text "Settings" in "#"
任何帮助将不胜感激。
解决方案
response
包含标头、响应代码和响应正文等内容。因此,如果您想检查渲染视图 - 您应该检查response.body
:
response.body.should have_text("Settings")
推荐阅读
- java - 处理扩展类中频繁逻辑变化的设计模式
- javascript - Firebase 实时数据库查询字段
- amazon-web-services - 从 Redshift 中的用户定义函数返回表
- html - 如何从主应用程序中分离出包含 css 导入的 html 正文的电子邮件
- python-3.x - 如何在无头模式下运行相机 Kivy 应用程序?
- sql - SQL查询检查另一个表中是否不存在记录
- java - Apache Jena - QueryFactory.create() 非常慢
- amazon-web-services - 如何获得基于 CloudFront URL 模式请求计数的 CloudWatch 指标?
- c - 无辜的输入打破了缓冲区溢出漏洞?
- ios - 当有分页列表时如何测试列表?