shou.com
JP / EN

minitest、assert_selectで複数クラスをテストする

Thu Apr 18, 2019
Thu Apr 18, 2019

minitestのintegrationテストを使って以下のような複数クラスのテストする。

1
2
3
<div class="notification is-danger">
 <p>test</p>
</div>

最初は以下のように書いてしまったが、テストが通らない。

1
2
3
  test "複数クラスのテスト" do
    assert_select 'div.notification is-danger'
  end

正しくは、doで囲む。

1
2
3
4
5
test "複数クラスのテスト" do
  assert_select 'div.notification' do
    assert_select 'div.is-danger'
  end
end
See Also