Soften this test since YAML.dump may produce keys in other orders. #26860

Merged
merged 1 commit into from Oct 21, 2016

Projects

None yet

6 participants

@headius
Contributor
headius commented Oct 21, 2016

Summary

JRuby's YAML engine is not libyaml, and may produce keys in a different order. That led to this failure (the SOLE failure) in actionpack:

  1) Failure:
ParametersSerializationTest#test_yaml_serialization [/Users/headius/projects/rails/actionpack/test/controller/parameters/serialization_test.rb:17]:
--- expected
+++ actual
@@ -1,5 +1,5 @@
 "--- !ruby/object:ActionController::Parameters
+permitted: false
 parameters: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
   key: :value
-permitted: false
 "

This patch modifies the test to use regexp matching for key lines rather than a string comparison.

@kaspth kaspth was assigned by rails-bot Oct 21, 2016
@rails-bot

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @kaspth (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

+ yaml_dump = YAML.dump(params)
+ assert_match /--- !ruby\/object:ActionController::Parameters/, yaml_dump
+ assert_match /parameters: !ruby\/hash:ActiveSupport::HashWithIndifferentAccess\n +key: :value/, yaml_dump
+ assert_match /permitted: false/, yaml_dump
@kaspth
kaspth Oct 21, 2016 edited Member

Let's wrap these in parens so they don't generate warnings on MRI 😁

@headius
headius Oct 21, 2016 Contributor

Can do!

@headius headius Soften this test since YAML.dump may produce keys in other orders.
fe09e7b
@headius
Contributor
headius commented Oct 21, 2016

Repushed a cleaner version.

@tenderlove
Member

Just wanted to comment that this difference is not due to the YAML back ends. The reason it's different is that this example is serializing a Ruby object to YAML, and the order in which JRuby returns instance variables is allowed to differ from the order which MRI returns instance variables. Since Psych is just asking for a list of instance variables, the output may be different depending on your Ruby implementation.

@kaspth kaspth merged commit 5dce39e into rails:master Oct 21, 2016

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
codeclimate Code Climate didn't find any new or fixed issues.
Details
@kaspth
Member
kaspth commented Oct 21, 2016

Thanks, @headius!

@rafaelfranca
Member

Backported in 5c9b16c

@headius headius deleted the headius:soft_ordering_in_yaml_dump branch Oct 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment