-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.rb
60 lines (45 loc) · 1.43 KB
/
test.rb
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
# frozen_string_literal: true
require "simplecov"
SimpleCov.command_name "Ruby tests"
SimpleCov.start
require_relative File.join("lib", "aw")
# It is expected to equal 42
raise unless 42.equal?(Aw.fork! { 6 * 7 })
# It is expected to eql 'bar'
raise unless "bar".eql?(Aw.fork! { "bar" })
# It is expected to be nil
# rubocop:disable Lint/EmptyBlock
raise unless (Aw.fork! {}).nil?
# rubocop:enable Lint/EmptyBlock
# It prevents from side effects
arr = ["foo"]
raise unless (Aw.fork! { arr << "FUU" }) == %w[foo FUU]
raise unless arr == ["foo"]
# It is expected to raise a generic error
begin
Aw.fork! { raise "BOOM" }
rescue RuntimeError
raise unless $ERROR_INFO.message == "BOOM"
end
# It is expected to initiate the termination of the script
begin
Aw.fork! { exit(1) }
rescue SystemExit
raise unless $ERROR_INFO.message == "exit"
end
# It is expected to return true
raise unless true.equal?(Aw.fork? { 6 * 7 })
# It is expected to return true
raise unless true.equal?(Aw.fork? { "bar" })
# It is expected to return true
# rubocop:disable Lint/EmptyBlock
raise unless true.equal?(Aw.fork? {})
# rubocop:enable Lint/EmptyBlock
# It is expected to prevent side effects and return true
arr = ["foo"]
raise unless true.equal?(Aw.fork? { arr << "FUU" })
raise unless arr == ["foo"]
# It is expected to return false
raise unless false.equal?(Aw.fork? { raise "BOOM" })
# It is expected to return false
raise unless false.equal?(Aw.fork? { exit(1) })