Skip to content

Commit

Permalink
Work around upcoming minitest insanity
Browse files Browse the repository at this point in the history
Minitest 6 will not allow assert_equal to compare for equality
with nil and minitest 5 has already started warning about it.

That's fine if you're comparing with a nil constant, but if you're
comparing with an expression that is sometimes nil and sometimes
not nil it's an absolute pain in the rear end.
  • Loading branch information
tomhughes committed Dec 2, 2016
1 parent c8f2659 commit b9b255f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 35 deletions.
2 changes: 1 addition & 1 deletion test/integration/oauth_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def get_request_token(client, options = {})
assert_not_nil token.created_at
assert_nil token.authorized_at
assert_nil token.invalidated_at
assert_equal options[:oauth_callback], token.callback_url
assert_equal_allowing_nil options[:oauth_callback], token.callback_url
assert_allowed token, client.permissions

token
Expand Down
8 changes: 4 additions & 4 deletions test/lib/bounding_box_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ def check_expand(bbox, array_string, margin = 0, result = nil)
end

def check_bbox(bbox, result)
assert_equal result[0], bbox.min_lon, "min_lon"
assert_equal result[1], bbox.min_lat, "min_lat"
assert_equal result[2], bbox.max_lon, "max_lon"
assert_equal result[3], bbox.max_lat, "max_lat"
assert_equal_allowing_nil result[0], bbox.min_lon, "min_lon"
assert_equal_allowing_nil result[1], bbox.min_lat, "min_lat"
assert_equal_allowing_nil result[2], bbox.max_lon, "max_lon"
assert_equal_allowing_nil result[3], bbox.max_lat, "max_lat"
end
end
54 changes: 27 additions & 27 deletions test/lib/locale_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,39 @@ def test_language
end

def test_script
assert_equal EN.script, Locale.tag("en").script
assert_equal EN_GB.script, Locale.tag("en-GB").script
assert_equal FR.script, Locale.tag("fr").script
assert_equal ZH_HANS.script, Locale.tag("zh-Hans").script
assert_equal ZH_HANT_TW.script, Locale.tag("zh-Hant-TW").script
assert_equal ZH_YUE.script, Locale.tag("zh-yue").script
assert_equal ZH_YUE.script, Locale.tag("zh-YUE").script
assert_equal BE_TARASK.script, Locale.tag("be-tarask").script
assert_equal BE_TARASK.script, Locale.tag("be-Tarask").script
assert_equal_allowing_nil EN.script, Locale.tag("en").script
assert_equal_allowing_nil EN_GB.script, Locale.tag("en-GB").script
assert_equal_allowing_nil FR.script, Locale.tag("fr").script
assert_equal_allowing_nil ZH_HANS.script, Locale.tag("zh-Hans").script
assert_equal_allowing_nil ZH_HANT_TW.script, Locale.tag("zh-Hant-TW").script
assert_equal_allowing_nil ZH_YUE.script, Locale.tag("zh-yue").script
assert_equal_allowing_nil ZH_YUE.script, Locale.tag("zh-YUE").script
assert_equal_allowing_nil BE_TARASK.script, Locale.tag("be-tarask").script
assert_equal_allowing_nil BE_TARASK.script, Locale.tag("be-Tarask").script
end

def test_region
assert_equal EN.region, Locale.tag("en").region
assert_equal EN_GB.region, Locale.tag("en-GB").region
assert_equal FR.region, Locale.tag("fr").region
assert_equal ZH_HANS.region, Locale.tag("zh-Hans").region
assert_equal ZH_HANT_TW.region, Locale.tag("zh-Hant-TW").region
assert_equal ZH_YUE.region, Locale.tag("zh-yue").region
assert_equal ZH_YUE.region, Locale.tag("zh-YUE").region
assert_equal BE_TARASK.region, Locale.tag("be-tarask").region
assert_equal BE_TARASK.region, Locale.tag("be-Tarask").region
assert_equal_allowing_nil EN.region, Locale.tag("en").region
assert_equal_allowing_nil EN_GB.region, Locale.tag("en-GB").region
assert_equal_allowing_nil FR.region, Locale.tag("fr").region
assert_equal_allowing_nil ZH_HANS.region, Locale.tag("zh-Hans").region
assert_equal_allowing_nil ZH_HANT_TW.region, Locale.tag("zh-Hant-TW").region
assert_equal_allowing_nil ZH_YUE.region, Locale.tag("zh-yue").region
assert_equal_allowing_nil ZH_YUE.region, Locale.tag("zh-YUE").region
assert_equal_allowing_nil BE_TARASK.region, Locale.tag("be-tarask").region
assert_equal_allowing_nil BE_TARASK.region, Locale.tag("be-Tarask").region
end

def test_variant
assert_equal EN.variant, Locale.tag("en").variant
assert_equal EN_GB.variant, Locale.tag("en-GB").variant
assert_equal FR.variant, Locale.tag("fr").variant
assert_equal ZH_HANS.variant, Locale.tag("zh-Hans").variant
assert_equal ZH_HANT_TW.variant, Locale.tag("zh-Hant-TW").variant
assert_equal ZH_YUE.variant, Locale.tag("zh-yue").variant
assert_equal ZH_YUE.variant, Locale.tag("zh-YUE").variant
assert_equal BE_TARASK.variant, Locale.tag("be-tarask").variant
assert_equal BE_TARASK.variant, Locale.tag("be-Tarask").variant
assert_equal_allowing_nil EN.variant, Locale.tag("en").variant
assert_equal_allowing_nil EN_GB.variant, Locale.tag("en-GB").variant
assert_equal_allowing_nil FR.variant, Locale.tag("fr").variant
assert_equal_allowing_nil ZH_HANS.variant, Locale.tag("zh-Hans").variant
assert_equal_allowing_nil ZH_HANT_TW.variant, Locale.tag("zh-Hant-TW").variant
assert_equal_allowing_nil ZH_YUE.variant, Locale.tag("zh-yue").variant
assert_equal_allowing_nil ZH_YUE.variant, Locale.tag("zh-YUE").variant
assert_equal_allowing_nil BE_TARASK.variant, Locale.tag("be-tarask").variant
assert_equal_allowing_nil BE_TARASK.variant, Locale.tag("be-Tarask").variant
end

def test_list
Expand Down
6 changes: 3 additions & 3 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_friends_with

def test_user_preferred_editor
user = users(:normal_user)
assert_equal nil, user.preferred_editor
assert_nil user.preferred_editor
user.preferred_editor = "potlatch"
assert_equal "potlatch", user.preferred_editor
user.save!
Expand Down Expand Up @@ -244,8 +244,8 @@ def test_delete
user.delete
assert_equal "user_#{user.id}", user.display_name
assert user.description.blank?
assert_equal nil, user.home_lat
assert_equal nil, user.home_lon
assert_nil user.home_lat
assert_nil user.home_lon
assert_equal false, user.image.file?
assert_equal "deleted", user.status
assert_equal false, user.visible?
Expand Down
13 changes: 13 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ def with_controller(new_controller)
end
end

##
# work round minitest insanity that causes it to tell you
# to use assert_nil to test for nil, which is fine if you're
# comparing to a nil constant but not if you're comparing
# an expression that might be nil sometimes
def assert_equal_allowing_nil(exp, act, msg = nil)
if exp.nil?
assert_nil act, msg
else
assert_equal exp, act, msg
end
end

##
# for some reason assert_equal a, b fails when the relations are
# actually equal, so this method manually checks the fields...
Expand Down

0 comments on commit b9b255f

Please sign in to comment.