aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/duplicable_test.rb
blob: e48e6a7c4556597218f8e0303265ea9f5225ea0c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'abstract_unit'
require 'bigdecimal'
require 'active_support/core_ext/object/duplicable'
require 'active_support/core_ext/numeric/time'

class DuplicableTest < Test::Unit::TestCase
  RAISE_DUP  = [nil, false, true, :symbol, 1, 2.3, BigDecimal.new('4.56'), 5.seconds]
  YES = ['1', Object.new, /foo/, [], {}, Time.now]
  NO = [Class.new, Module.new]

  def test_duplicable
    (RAISE_DUP + NO).each do |v|
      assert !v.duplicable?
    end

    YES.each do |v|
      assert v.duplicable?
    end

    (YES + NO).each do |v|
      assert_nothing_raised { v.dup }
    end

    RAISE_DUP.each do |v|
      assert_raises(TypeError) do
        v.dup
      end
    end
  end
end