Skip to content

Conversation

koenpunt
Copy link
Contributor

@koenpunt koenpunt commented Jul 5, 2016

This fixes #273

@koenpunt koenpunt changed the title Testing multiple version of Rails Testing multiple versions of Rails Jul 5, 2016
@koenpunt
Copy link
Contributor Author

koenpunt commented Jul 5, 2016

And I'm not sure why the Travis build isn't being triggered for this PR..? it is, but it doesn't update here on GitHub: https://travis-ci.org/bootstrap-ruby/rails-bootstrap-forms/builds/142603928

@mattbrictson
Copy link
Contributor

mattbrictson commented Jul 6, 2016

Thanks for taking a first shot at this. I'll try to review later today.

I would like to sort out the Travis issue, but unfortunately I'm not a project owner, just a contributor. That means I cannot see or edit the Travis config.

@potenza @carloslopes Can you help us turn on Travis for PRs?

@mattbrictson
Copy link
Contributor

This is an excellent start! I like the use of the appraisal gem, and it is hooked up nicely with Travis.

Clearly we have some work to do in order to get tests passing on 4.1+.

My concerns so far are:

  1. How do we do this in a piecemeal fashion so that we can merge into master sooner rather than later, but at the same time keep Travis green? Maybe work on getting 4.0 and 4.1 passing first, merge, then fix 4.2 and 5.0 in a separate PR?
  2. The output from rails-dom-testing when an assertion fails is very hard to interpret (it seems to just call #inspect on the DOM nodes). Can we do better in terms of the output for failing DOM assertions?
 25) Failure:
BootstrapFormTest#test_the_field_is_wrapped_with_div.field_with_errors_when_form_for_is_used [/home/travis/build/bootstrap-ruby/rails-bootstrap-forms/test/bootstrap_form_test.rb:175]:
--- expected
+++ actual
@@ -1 +1 @@
-#<HTML::Node:0xXXXXXX @parent=nil, @children=[#<HTML::Tag:0xXXXXXX @parent=#<HTML::Node:0xXXXXXX ...>, @children=[#<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[#<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[], @line=1, @position=137, @name="input", @attributes={"name"=>"utf8", "type"=>"hidden", "value"=>"&#x2713;"}, @closing=:self>], @line=1, @position=90, @name="div", @attributes={"style"=>"margin:0;padding:0;display:inline"}, @closing=nil>, #<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[#<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[#<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[#<HTML::Text:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[], @line=1, @position=315, @content="Email">], @line=1, @position=260, @name="label", @attributes={"class"=>"control-label required", "for"=>"user_email"}, @closing=nil>], @line=1, @position=229, @name="div", @attributes={"class"=>"field_with_errors"}, @closing=nil>, #<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[#<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[], @line=1, @position=365, @name="input", @attributes={"class"=>"form-control", "id"=>"user_email", "name"=>"user[email]", "type"=>"text"}, @closing=:self>], @line=1, @position=334, @name="div", @attributes={"class"=>"field_with_errors"}, @closing=nil>, #<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[#<HTML::Text:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[], @line=1, @position=473, @content="can&#39;t be blank, is too short (minimum is 5 characters)">], @line=1, @position=448, @name="span", @attributes={"class"=>"help-block"}, @closing=nil>], @line=1, @position=195, @name="div", @attributes={"class"=>"form-group has-error"}, @closing=nil>], @line=1, @position=0, @name="form", @attributes={"accept-charset"=>"UTF-8", "action"=>"/users", "class"=>"new_user", "id"=>"new_user", "method"=>"post"}, @closing=nil>], @line=0, @position=0>
+#<HTML::Node:0xXXXXXX @parent=nil, @children=[#<HTML::Tag:0xXXXXXX @parent=#<HTML::Node:0xXXXXXX ...>, @children=[#<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[#<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[], @line=1, @position=116, @name="input", @attributes={"name"=>"utf8", "type"=>"hidden", "value"=>"&#x2713;"}, @closing=:self>], @line=1, @position=90, @name="div", @attributes={"style"=>"display:none"}, @closing=nil>, #<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[#<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[#<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[#<HTML::Text:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[], @line=1, @position=294, @content="Your e-mail address">], @line=1, @position=239, @name="label", @attributes={"class"=>"control-label required", "for"=>"user_email"}, @closing=nil>], @line=1, @position=208, @name="div", @attributes={"class"=>"field_with_errors"}, @closing=nil>, #<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[#<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[], @line=1, @position=358, @name="input", @attributes={"class"=>"form-control", "id"=>"user_email", "name"=>"user[email]", "type"=>"text"}, @closing=:self>], @line=1, @position=327, @name="div", @attributes={"class"=>"field_with_errors"}, @closing=nil>, #<HTML::Tag:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[#<HTML::Text:0xXXXXXX @parent=#<HTML::Tag:0xXXXXXX ...>, @children=[], @line=1, @position=466, @content="can&#39;t be blank, is too short (minimum is 5 characters)">], @line=1, @position=441, @name="span", @attributes={"class"=>"help-block"}, @closing=nil>], @line=1, @position=174, @name="div", @attributes={"class"=>"form-group has-error"}, @closing=nil>], @line=1, @position=0, @name="form", @attributes={"accept-charset"=>"UTF-8", "action"=>"/users", "class"=>"new_user", "id"=>"new_user", "method"=>"post"}, @closing=nil>], @line=0, @position=0>

@koenpunt
Copy link
Contributor Author

koenpunt commented Jul 7, 2016

We might be better of with a custom parser, which only checks a limited set of attributes. Because I already see issues with certain versions of Rails outputting different attributes and additional elements than others.

@mattbrictson
Copy link
Contributor

We might be better of with a custom parser

Rather than risk reinventing the wheel, maybe we can continue using rails-dom-parser, but instead of assert_dom_equal, use assert_select and test for certain CSS expressions?

BTW, thanks for taking the lead on this. If the scope of the work gets overwhelming and you want to split it up somehow, let me know and I'll do my best to help out.

@mattbrictson
Copy link
Contributor

Also: I think Travis integration is working now. Next time you push commits to this PR the Travis build status should get hooked up.

@koenpunt
Copy link
Contributor Author

Cool, will see if I can squeeze in a update somewhere this week

koenpunt and others added 10 commits December 9, 2016 17:19
I added an `assert_equivalent_xml` ActionView::TestCase, and then
I changed all the `assert_equal` to `assert_equivalent_xml`.
this to prevent differences in defaults between rails versions
as of rails 4.2 the utf8 hidden field is no longer wrapped in a div
for some reason EquivalentXml can't handle attributes with dashes, so a
workaround is provided.
since rails 5 the type for a datetime field is `datetime-local` instead
of `datetime`
@koenpunt
Copy link
Contributor Author

koenpunt commented Dec 9, 2016

@mattbrictson I finally got around fixing the tests (with the equivalent-xml gem proposed by @lcreid).

I can imagine that certain logic that is now part of assert_equivalent_xml should be added to specific tests instead, but please have a look and let me know what you think :)

Copy link
Contributor

@mattbrictson mattbrictson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! This looks great. I had one comment about reorganizing require statements. Otherwise, could you add a bit of documentation? Then I think this will be good to merge.

  • Explain in the README how to run appraisals.
  • Mention in the CHANGELOG that the project is now tested against multiple versions of Rails (even though this is not a user-facing feature or bug fix, I think users will be excited to hear it).

Thanks!

@@ -1,4 +1,6 @@
require 'test_helper'
require 'nokogiri'
require 'equivalent-xml'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these require statements should move to test_helper.rb?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason those require statements are there is that's the file I arbitrarily chose to initially do the work. What I checked in yesterday I hadn't even reviewed myself. I didn't realize how quickly you were going to take the commit. :-) I agree the requires should go in test_helper.rb.

@mattbrictson
Copy link
Contributor

@lcreid I tried to invite you as a reviewer to this PR, but apparently GH only allows maintainers (?) to be reviewers. In any case, I would appreciate your 2¢ before merging this if you have time. Thanks!

@lcreid
Copy link
Contributor

lcreid commented Dec 9, 2016

@mattbrictson it looks good to me. @koenpunt obviously knows this issue inside out, to be able to add the special cases so quickly. Let me know if I can help out in any other way.

@koenpunt
Copy link
Contributor Author

koenpunt commented Dec 9, 2016

I've updated per the requested changes. We might consider enabling bundler cache to speed up the build on travis?

@mattbrictson
Copy link
Contributor

@koenpunt Looks great. I don't think we need the bundler cache as part of this PR; we can always add it separately.

Did you want a chance to squash some of the commits? I am fine either way. I'll merge as soon as I get a thumbs-up from you.

@koenpunt
Copy link
Contributor Author

Did you want a chance to squash some of the commits?

No I'm good :shipit:

@mattbrictson mattbrictson merged commit 5512154 into bootstrap-ruby:master Dec 10, 2016
@mattbrictson
Copy link
Contributor

Merged! Thanks for the awesome PR ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrite tests to work on Rails 4.0, 4.1, 4.2, and 5.0
3 participants