File: 0004-Fix-failing-tests-against-Ruby-2.7.patch

package info (click to toggle)
ruby-faker 1.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,088 kB
  • sloc: ruby: 11,588; makefile: 6
file content (68 lines) | stat: -rw-r--r-- 2,342 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
From: Lucas Kanashiro <lucas.kanashiro@canonical.com>
Date: Wed, 18 Mar 2020 16:33:07 -0300
Subject: Fix failing tests against Ruby 2.7

Two tests expect an ArgumentError exception but in Ruby 2.7 it was
changed to Date::Error. This patch is based on this upstream commit:

https://github.com/faker-ruby/faker/commit/54a1bbfc1e7f92f6230dfeefa893e17edfcb3802
---
 test/test_faker_birthday_in_leap_year.rb | 21 ++++++++++++++++-----
 test/test_faker_date.rb                  | 11 +++++++++--
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/test/test_faker_birthday_in_leap_year.rb b/test/test_faker_birthday_in_leap_year.rb
index baa59d5..8b262d7 100644
--- a/test/test_faker_birthday_in_leap_year.rb
+++ b/test/test_faker_birthday_in_leap_year.rb
@@ -18,12 +18,23 @@ class TestFakerBirthdayInLeapYear < Test::Unit::TestCase
       @tester.birthday
     end
 
-    assert_raise ArgumentError do
-      ::Date.new(@today.year - @min, @today.month, @today.day)
-    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 ArgumentError do
-      ::Date.new(@today.year - @max, @today.month, @today.day)
+      assert_raise Date::Error do
+        ::Date.new(@today.year - @max, @today.month, @today.day)
+      end
     end
   end
 end
diff --git a/test/test_faker_date.rb b/test/test_faker_date.rb
index 7766bc7..ed2c8db 100644
--- a/test/test_faker_date.rb
+++ b/test/test_faker_date.rb
@@ -77,8 +77,15 @@ class TestFakerDate < Test::Unit::TestCase
   end
 
   def test_invalid_date
-    assert_raise ArgumentError do
-      @tester.between('9999-99-99', '9999-99-99')
+    # The error raised here is changed in Ruby 2.7.
+    if RUBY_VERSION < '2.7'
+      assert_raise ArgumentError do
+        @tester.between('9999-99-99', '9999-99-99')
+      end
+    elsif RUBY_VERSION >= '2.7'
+      assert_raise Date::Error do
+        @tester.between('9999-99-99', '9999-99-99')
+      end
     end
   end