appdev-projects / rps-html-v1

2 stars 1.05k forks source link

Tests don't always check what you think they do #7

Closed jelaniwoods closed 4 years ago

jelaniwoods commented 4 years ago

This: https://github.com/appdev-projects/rps-html/blob/6eba09cc555233c98722f8145bb8517378b3abba/spec/features/4_index_spec.rb#L578

Actually doesn't check if the paragraph and image are in the same <div>. This is checked by the "has all the elements in the right order test"

See https://gitpod.io/#snapshot/31b85df7-f8cc-4dc5-b485-3c991a8bb558

jelaniwoods commented 4 years ago

Apparently, I misunderstood how rspec-html-matchers is suppose to work. The have_tag/with_tag combo block is not supposed to care about checking the same parent element.

github.com/kucaahbe/rsp ec-html-matchers/issues/41#issuecomment-2742341911 It was suggested to do something like:

    rendered = "<div> <foo /> </div> <div> <bar /> </div> <div> <foo /> <bar /> </div>"
    expect(rendered).to have_tag 'div', count: 3
    expect(rendered).to have_tag 'div' do
      with_tag 'foo'
      with_tag 'bar'
    end
    expect(rendered).to have_tag 'div' do
      with_tag 'foo'
      without_tag 'bar'
    end
    expect(rendered).to have_tag 'div' do
      without_tag 'foo'
      with_tag 'bar'
    end

but that still fails for me. Maybe I'm misreading the example?