-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_runner_test.rb
163 lines (148 loc) · 4.39 KB
/
test_runner_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
require "test_helper"
class TestRunnerTest < Minitest::Test
def test_pass
assert_fixture(
:pass,
{
version: 2,
status: :pass,
message: nil,
tests: [
{
name: "No name given",
status: :pass,
test_code: %(assert_equal "One for you, one for me.", TwoFer.two_fer)
},
{
name: 'A name given',
test_code: 'assert_equal "One for Alice, one for me.", TwoFer.two_fer("Alice")',
status: :pass
},
{
name: "Another name given",
status: :pass,
test_code: 'assert_equal "One for Bob, one for me.", TwoFer.two_fer("Bob")'
}
]
}
)
end
def test_pass_ruby_3
assert_fixture(
:pass_ruby_3_syntax,
{
version: 2,
status: :pass,
message: nil,
tests: [
{
name: "Rightward assign",
status: :pass,
test_code: %(assert_equal Ruby3Syntax.rightward_assign, 'is fun')
},
{
name: "Endless method def",
status: :pass,
test_code: %(assert_equal Ruby3Syntax.endless_methods, 'are fun')
}
]
}
)
end
def test_fail
assert_fixture(
:fail, {
version: 2,
status: :fail,
message: nil,
tests: [
{
name: "No name given",
test_code: %(assert_equal "One for you, one for me.", TwoFer.two_fer),
status: :fail,
message: %(Expected: \"One for you, one for me.\"\n Actual: \"One for fred, one for me.\"),
output: "The name is fred.\nHere's another line.\n"
},
{
name: "A name given",
test_code: 'assert_equal "One for Alice, one for me.", TwoFer.two_fer("Alice")',
status: :pass,
output: "The name is Alice.\nHere's another line.\n"
},
{
name: "Another name given",
test_code: 'assert_equal "One for Bob, one for me.", TwoFer.two_fer("Bob")',
status: :pass,
output: "The name is Bob.\nHere's another line.\n"
}
]
}
)
end
def test_deep_exception
message = "
NoMethodError: undefined method `non_existant_method' for nil
Traceback (most recent call first):
Line 8:in `work_out_name'
Line 3:in `two_fer'
".strip
assert_fixture(
:deep_exception,
{
version: 2,
status: :fail,
message: nil,
tests: [
{
name: "No name given",
test_code: 'assert_equal "One for you, one for me.", TwoFer.two_fer',
status: :error,
message:
}
]
}
)
end
def test_name_error_exception
with_tmp_dir_for_fixture(:exception) do |_input_dir, output_dir|
actual = JSON.parse(File.read(output_dir / "results.json"))
assert_equal "error", actual["status"]
expected = "Line 3: undefined local variable or method `raise_an_error_because_i_am_a_random_method' for main (NameError)"
assert_equal expected, actual['message']
assert_test_run_exited_cleanly
end
end
def test_syntax_errors_in_tests
with_tmp_dir_for_fixture(:syntax_error_in_tests) do |_input_dir, output_dir|
actual = JSON.parse(File.read(output_dir / "results.json"))
assert_equal "error", actual["status"]
expected = <<~SYNTAX_ERRORS
Line 3: syntax error, unexpected ','
,'This is meant to be a syntax...
^
SYNTAX_ERRORS
assert_equal expected, actual['message']
assert_test_run_exited_cleanly
end
end
def test_syntax_errors_in_code
with_tmp_dir_for_fixture(:syntax_error_in_code) do |_input_dir, output_dir|
actual = JSON.parse(File.read(output_dir / "results.json"))
assert_equal "error", actual["status"]
expected = <<~SYNTAX_ERRORS
Line 2: syntax error, unexpected ',', expecting end-of-input
end,A stray comma
^
SYNTAX_ERRORS
assert_equal expected, actual['message']
assert_test_run_exited_cleanly
end
end
def test_really_bad_things_exit_uncleanly
skip
# I have no idea how to make this work, but
# it seems like a important test to have
# WriteReport.stubs(:new).raises("Something really bad!")
# refute_test_run_exited_cleanly
end
end