如何在 Rails 集成测试中测试所有带 class 的 div 是否也有 class 两个?

How to test if all divs with class one has also class two in Rails integration test?

我想在我的 Rails 集成测试中进行测试,如果所有带有 class 的 div 也有 class 两个,如果没有,则失败。

可能还有其他 class 与本次测试无关。

这应该通过:

<div class="one two">...</div>
<div class="one three two">...</div>
<div class="two one">...</div>

这应该会失败:

<div class="one two">...</div>
<div class="one three">...</div>
<div class="one">...</div>

谢谢!

你可以用水豚来做。

let(:items) { page.find('div.one') }

it "items has both classes" do
  items.each do |item|
    expect(item[:class]).to match(/two/)
  end
end