Skip to content

Commit

Permalink
Update Sprockets::Utils#duplicable? for Ruby 2.4+
Browse files Browse the repository at this point in the history
This is very similar to rails/rails@2cb8558.
  • Loading branch information
maclover7 committed Dec 18, 2016
1 parent d62bf7b commit d47639f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/sprockets/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ module Utils
#
# Returns false if .dup would raise a TypeError, otherwise true.
def duplicable?(obj)
case obj
when NilClass, FalseClass, TrueClass, Symbol, Numeric
false
else
if RUBY_VERSION >= "2.4.0"
true
else
case obj
when NilClass, FalseClass, TrueClass, Symbol, Numeric
false
else
true
end
end
end

Expand Down
19 changes: 18 additions & 1 deletion test/test_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@
class TestUtils < MiniTest::Test
include Sprockets::Utils

def test_duplicable
def test_duplicable_pre_ruby_2_4
skip if RUBY_VERSION >= "2.4"

objs = [nil, true, false, 1, "foo", :foo, [], {}]
objs.each do |obj|
begin
obj.dup
rescue TypeError
refute duplicable?(obj), "can't dup: #{obj.inspect}"
else
assert duplicable?(obj), "can dup: #{obj.inspect}"
end
end
end

def test_duplicable_post_ruby_2_4
skip if RUBY_VERSION < "2.4"

objs = [nil, true, false, 1, "foo", :foo, [], {}]
objs.each do |obj|
begin
Expand Down

0 comments on commit d47639f

Please sign in to comment.