我不会将 capybara 测试与 HTML linting 纠缠在一起。此刻它看起来很聪明,因为您会获得一个 URL 列表,以便在每次测试中免费检查,但是:
- 您可能会对每个 URL 进行几次 lint,因为有些测试会通过它
- 您可能会因为 HTML 不完美而失败,即使您正在测试的功能实际上还可以。
您可能有类似 sitemap.xml 或所有可用 URL 的其他来源。我会用它来做一个单独的检查,这很简单:请求 URL,检查响应。冲洗并重复。
如果仍然不相信,请尝试使用page.html
并做某事
expect(page.html).to pass_linter
https://github.com/teamcapybara/capybara#debugging
然后,您可以根据需要将其添加around
为每个type: :feature
规范的挂钩。
编辑:这是另一种解决方法,可以让每个访问的路径。如果访问路径,只需解析服务器日志文件(像这样cat log/devlopment.log | grep path
)以获取完整列表:
method=POST path=/users/login format=html controller=SessionsController action=create
status=302 duration=256.82 view=0.00 db=52.29 location=http://0.0.0.0:3000/platform/admin/dashboard params={"utf8"=>"✓", "authenticity_token"=>"ubGnWKOq8gbUE5C/aK375QQn5DpjHarUYxHtBLglGe6Lr9Ie3O5XPq90k5gr/SZbIPoDiiasvY0mGlwhzD/MsQ==", "user"=>{"email"=>"alex-3d51048235c9d1a8@toptal.io", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"} uid=983 remote_ip=127.0.0.1 x_forwarded_for= x_request_id=
method=GET path=/admin/dashboard format=html controller=XXX action=show status=200 duration=3285.54 view=1051.32 db=2016.87 params={} uid=983 remote_ip=127.0.0.1 x_forwarded_for= x_request_id=
并将其用于棉绒。