LoginSignup
0
0

More than 3 years have passed since last update.

Rails上におけるテストで、「1つのHTML要素に対し、複数のクラスが定義されていること」をテストする正しい書き方

Posted at

alertalert-danger両方のクラスが定義されているdiv要素が存在すること」をテストしようとして、以下のようなテストを書いてもうまくいきません。

test "invalid signup information" do
  assert_select 'div.alert'
  assert_select 'div.alert-danger'
end

上述のテストだと、「alertというクラスが定義されているdiv要素と、alert-dangerというクラスが定義されているdiv要素が別々に存在すること」のテストになってしまうためです。

alertalert-danger両方のクラスが定義されているdiv要素が存在することをテストする」ためには、ブロックを使って、以下のように記述する必要があります。

test "invalid signup information" do
  assert_select 'div.alert' do
    assert_select 'div.alert-danger'
  end
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0