如何测试id为'foo'的表行是否具有某个类?

jpw*_*ynn 3 rspec capybara

对于我的rails 3.0应用程序,我已经在字段中填写了rspec + capybara,单击按钮,并在页面的任何位置测试是否存在大量文本.

但我找不到任何解释如何将断言(有值,包含或具有类)应用于我知道其ID的元素.

例如,我正在尝试测试一个表行id=row_1002(其中包含的类highlightrow(可能在其他类中))

我还想并且还测试行中是否id=row_1002包含文本"Foobar".

在我试过的很多事情中,抛出错误的是:

find('tr', id: "row_1002")[:class].should include('highlightrow')
Run Code Online (Sandbox Code Playgroud)

Chr*_*erg 5

你应该能够做到这一点:

find('td#row_1002')[:class].should include('highlightrow')
Run Code Online (Sandbox Code Playgroud)

并且要查找行中包含文本"Foobar"的id的行:

find('td#row_1002').text.should include('Foobar')
Run Code Online (Sandbox Code Playgroud)