File: test_faker_birthday_in_leap_year.rb

package info (click to toggle)
ruby-faker 1.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 4,088 kB
  • sloc: ruby: 11,588; makefile: 6
file content (40 lines) | stat: -rw-r--r-- 948 bytes parent folder | download
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
31
32
33
34
35
36
37
38
39
40
require_relative 'test_helper'

class TestFakerBirthdayInLeapYear < Test::Unit::TestCase
  def setup
    @tester = Faker::Date
    @today = Date.parse('2016-02-29')
    @min = 18
    @max = 65
  end

  def teardown
    Timecop.return
  end

  def test_birthday_in_leap_year
    Timecop.freeze(@today)
    assert_nothing_raised ArgumentError do
      @tester.birthday
    end

    # The error raised here is changed in Ruby 2.7.
    if RUBY_VERSION < '2.7'
      assert_raise ArgumentError do
        ::Date.new(@today.year - @min, @today.month, @today.day)
      end

      assert_raise ArgumentError do
        ::Date.new(@today.year - @max, @today.month, @today.day)
      end
    elsif RUBY_VERSION >= '2.7'
      assert_raise Date::Error do
        ::Date.new(@today.year - @min, @today.month, @today.day)
      end

      assert_raise Date::Error do
        ::Date.new(@today.year - @max, @today.month, @today.day)
      end
    end
  end
end