我用的水豚测试此代码位于我的评价模型后隐藏(5分钟是常规):Link不一段时间豚
def editable?
self.created_at < (Time.now - 5.minute)
end
链接的观点:
- unless comment.editable?
= link_to 'Edit', edit_category_theme_comment_path(@category, @theme, comment)
所以5分钟后链接编辑必须从页面隐藏(但我们需要刷新页面)。这是我在RSpec的代码创建的意见和测试链路隐藏功能:
def create_comment(options={})
options[:content] ||= 'I am a comment'
visit category_theme_path(category, theme)
within '.comment-form' do
fill_in 'Content', with: options[:content]
click_button 'Submit'
end
end
context 'Comment has content' do
before(:each) { create_comment }
it 'hides the edit symbol due 5 minutes after comment was created' do
using_wait_time 400 do
visit category_theme_path(category, theme)
save_and_open_page
expect(page).to have_no_css('.comment-edit')
end
end
end
但我得到:Failure/Error: expect(page).to have_no_css('.comment-edit')expected #has_no_css?(".comment-edit") to return true, got false
我也尝试使用page.reload!
,expect(page).to have_no_css('.comment-edit', wait: 400)
和其他相关人员,但水豚不要”我不想等。也许我用using_wait_time
来说明一个错误的地方,如果那样的话 - 我该如何测试?
有你的测试等待5分钟,声音不能接受我。任何其他方式可以测试这种行为? –
仍处于亏损状态...... – k1r8r0wn
你可以显示你的'create_comment'方法吗? –