rails/rails-dom-testing

rails-dom-testing 1.0.5 causes rspec-rails builds to fail

cupakromer opened this issue · 9 comments

This came up recently where rspec-rails builds started to fail. I've traced it to moving from rails-dom-testing 1.0.4 to 1.0.5. I am unable to reproduce this issue locally on my laptop (Macbook Air) however, Travis-CI consistently fails.

This occurs with Ruby 2.1, Rails 4.2.0-beta4, using rails-dom-testing 1.0.5.

You can compare the "working" build using 1.0.4 to the failing build using 1.0.5. This happens for any view specs which have a test of the form:

RSpec.describe "gadgets/new", :type => :view do
  before(:each) do
    assign(:gadget, Gadget.new())
  end

  it "renders new gadget form" do
    render

    assert_select "form[action=?][method=?]", gadgets_path, "post" do
    end
  end
end

The error raised is:

     Failure/Error: assert_select "form[action=?][method=?]", gadgets_path, "post" do
     Minitest::Assertion:
       Expected at least 1 element matching "form[action="/gadgets"][method="post"]", found 0..
       Expected 0 to be >= 1.
     # /home/travis/build/rspec/bundle/ruby/2.1.0/gems/minitest-5.4.3/lib/minitest/assertions.rb:130:in `assert'
     # /home/travis/build/rspec/bundle/ruby/2.1.0/gems/minitest-5.4.3/lib/minitest/assertions.rb:247:in `assert_operator'
     # /home/travis/build/rspec/bundle/ruby/2.1.0/gems/rails-dom-testing-1.0.5/lib/rails/dom/testing/assertions/selector_assertions.rb:280:in `assert_size_match!'
     # /home/travis/build/rspec/bundle/ruby/2.1.0/gems/rails-dom-testing-1.0.5/lib/rails/dom/testing/assertions/selector_assertions.rb:175:in `block in assert_select'
     # /home/travis/build/rspec/bundle/ruby/2.1.0/gems/rails-dom-testing-1.0.5/lib/rails/dom/testing/assertions/selector_assertions.rb:174:in `tap'
     # /home/travis/build/rspec/bundle/ruby/2.1.0/gems/rails-dom-testing-1.0.5/lib/rails/dom/testing/assertions/selector_assertions.rb:174:in `assert_select'
     # ./spec/views/gadgets/new.html.erb_spec.rb:17:in `block (2 levels) in <top (required)>'

Does it fails if you remove the empty block?

I pushed up two more commits which modify: spec/views/gadgets/new.html.erb_spec.rb.

What does it say if you do the interpolation yourself?

assert_select %(form[action=#{gadgets_path}][method="post"])

I pushed it up to here: https://travis-ci.org/rspec/rspec-rails/builds/42427520

Will need to wait until the prior build completes which could be a while as it's a full build matrix. I'll check back in about an hour.

Manual interpolation has the same error:

     Failure/Error: assert_select %(form[action="#{gadgets_path}"][method="post"])
     Minitest::Assertion:
       Expected at least 1 element matching "form[action="/gadgets"][method="post"]", found 0..
       Expected 0 to be >= 1.
     # /home/travis/build/rspec/bundle/ruby/2.1.0/gems/minitest-5.4.3/lib/minitest/assertions.rb:130:in `assert'
     # /home/travis/build/rspec/bundle/ruby/2.1.0/gems/minitest-5.4.3/lib/minitest/assertions.rb:247:in `assert_operator'
     # /home/travis/build/rspec/bundle/ruby/2.1.0/gems/rails-dom-testing-1.0.5/lib/rails/dom/testing/assertions/selector_assertions.rb:280:in `assert_size_match!'
     # /home/travis/build/rspec/bundle/ruby/2.1.0/gems/rails-dom-testing-1.0.5/lib/rails/dom/testing/assertions/selector_assertions.rb:175:in `block in assert_select'
     # /home/travis/build/rspec/bundle/ruby/2.1.0/gems/rails-dom-testing-1.0.5/lib/rails/dom/testing/assertions/selector_assertions.rb:174:in `tap'
     # /home/travis/build/rspec/bundle/ruby/2.1.0/gems/rails-dom-testing-1.0.5/lib/rails/dom/testing/assertions/selector_assertions.rb:174:in `assert_select'
     # ./spec/views/gadgets/new.html.erb_spec.rb:17:in `block (2 levels) in <top (required)>'

I've been trying to write a failing test, but this passes just fine:

  def test_assert_select_with_multiple_attributes
    render_html '<form action="/gadgets" method="post"></form>'

    assert_select 'form[action="/gadgets"]' # sanity check
    assert_select 'form[action="/gadgets"][method="post"]'
    assert_select 'form[action=?][method=?]', '/gadgets', 'post'
  end

Can you show your html? Mainly how the form tag is defined and what kind parent elements it has.

Actually now that I think about it, the main change in 1.0.5 was how the parsed document was stored. Rails needed to be updated for that and the change was released in rc1 (:heart: @fxn git-rel) and you have beta4. Can you try upgrading to rc1 or rc2?

Sorry for taking so incredibly long to get back to you. You are completely correct. It was a beta only issue. Things pass now.

Cheers! ❤️

No worries. Glad it's working 😁