RSpec 功能规范中未呈现的链接
Links not rendering in RSpec feature spec
下面的代码应该呈现一些链接,但是当在 RSpec 中做一个功能规范来测试它时,链接在 save_and_open_screenshot
中不存在,即使在长时间睡眠之后它们仍然存在不会出现。执行 save_and_open_page
确实显示链接存在。
%nav#sidebar
= form_with url: entries_path, local: true, method: :get do |f|
= f.text_field :search
= button_tag type: 'submit' do
%i.fas.fa-search
%ul.nav.flex-column.pb-5.mb-5
- months.each do |month|
%li.nav-item
.nav-link{class: (current_page?(entries_path(month: month.to_date)) && 'active')}
= link_to month.strftime('%b-%Y'), entries_path(month: month.to_date)
CSS 在边栏上:
@import 'bootstrap'
@import 'fontawesome'
#sidebar
padding: 10px 0 30px 0
border-right: 1px solid #ddd
width: 200px
border-radius: 0 0 0 4px
transition: margin .3s
@include media-breakpoint-down(md)
position: absolute
top: 0
bottom: 0
z-index: 9
margin-left: -200px
&.visible
margin-left: 0
.nav-link
@extend .d-flex
@extend .align-items-center
height: 40px
padding: 0 30px
&.active
position: relative
font-weight: bold
我也在这个项目中使用了 turbolinks,不知道这是否会以任何方式干扰规范中链接的呈现。
@include media-breakpoint-down(md)
部分中的 margin-left: -200px
看起来很可能是罪魁祸首。给定特定的屏幕尺寸(无法确定这些尺寸来自您发布的内容),侧边栏将隐藏在屏幕的左边缘(因此不可见)。您可能需要为 运行.
的测试正确设置浏览器的 window 大小
下面的代码应该呈现一些链接,但是当在 RSpec 中做一个功能规范来测试它时,链接在 save_and_open_screenshot
中不存在,即使在长时间睡眠之后它们仍然存在不会出现。执行 save_and_open_page
确实显示链接存在。
%nav#sidebar
= form_with url: entries_path, local: true, method: :get do |f|
= f.text_field :search
= button_tag type: 'submit' do
%i.fas.fa-search
%ul.nav.flex-column.pb-5.mb-5
- months.each do |month|
%li.nav-item
.nav-link{class: (current_page?(entries_path(month: month.to_date)) && 'active')}
= link_to month.strftime('%b-%Y'), entries_path(month: month.to_date)
CSS 在边栏上:
@import 'bootstrap'
@import 'fontawesome'
#sidebar
padding: 10px 0 30px 0
border-right: 1px solid #ddd
width: 200px
border-radius: 0 0 0 4px
transition: margin .3s
@include media-breakpoint-down(md)
position: absolute
top: 0
bottom: 0
z-index: 9
margin-left: -200px
&.visible
margin-left: 0
.nav-link
@extend .d-flex
@extend .align-items-center
height: 40px
padding: 0 30px
&.active
position: relative
font-weight: bold
我也在这个项目中使用了 turbolinks,不知道这是否会以任何方式干扰规范中链接的呈现。
@include media-breakpoint-down(md)
部分中的 margin-left: -200px
看起来很可能是罪魁祸首。给定特定的屏幕尺寸(无法确定这些尺寸来自您发布的内容),侧边栏将隐藏在屏幕的左边缘(因此不可见)。您可能需要为 运行.