Rspec 如何将find should转换为新的expect语法?

Rspec 如何将find should转换为新的expect语法?,rspec,cucumber,capybara,Rspec,Cucumber,Capybara,我将如何修改下面的代码以使用新的expect语法而不是不推荐的should语法 find("#iframe").should be_visible 我试着用 expect("#iframe").to be_visible 但在运行它时,我不断得到一个未达到的期望。由于这是一个iframe,我想我需要先使用find,然后才能检测到iframe,但我不确定如何使用expect实现find。直接翻译为: expect(find('#iframe')).to be_visible 但是,最好是:

我将如何修改下面的代码以使用新的expect语法而不是不推荐的should语法

find("#iframe").should be_visible
我试着用

expect("#iframe").to be_visible

但在运行它时,我不断得到一个未达到的期望。由于这是一个iframe,我想我需要先使用find,然后才能检测到iframe,但我不确定如何使用expect实现find。

直接翻译为:

expect(find('#iframe')).to be_visible
但是,最好是:

expect(page).to have_selector('#iframe')

这两种方法将给出相同的通过/失败结果。但是,使用
find
的方法的错误消息具有误导性。
find
方法将引发ElementNotFound异常,而不是允许测试断言失败。

的工作非常有效。非常感谢。