-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathrake_task_test.rb
More file actions
82 lines (61 loc) · 2.47 KB
/
Copy pathrake_task_test.rb
File metadata and controls
82 lines (61 loc) · 2.47 KB
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
# frozen_string_literal: true
require "test_helper"
class RakeTaskTest < ActiveSupport::TestCase
test "is able to build valid rake commands" do
task = get_double_nested_task
plain_rake = "rake #{task.name}"
assert_equal plain_rake, task.build_rake_command
full_rake_command = "FOO=bar rake #{task.name}[1,2,3]"
assert_equal full_rake_command, task.build_rake_command(args: "1,2,3", environment: "FOO=bar")
no_arguments = "FOO=bar rake #{task.name}"
assert_equal no_arguments, task.build_rake_command(environment: "FOO=bar")
no_environment = "rake #{task.name}[1,2,3]"
assert_equal no_environment, task.build_rake_command(args: "1,2,3")
end
test "scrubs rake_definition_file to be html safe" do
task = get_double_nested_task
assert_includes task.rake_definition_file, "/test/dummy/lib/tasks/double_nested_tasks.rake:6"
end
test "returns the desc as full_comments" do
task = get_double_nested_task
assert_equal task.full_comment, "Doubley Nested Task"
end
test "to_safe_identifier escapes" do
id = RakeUi::RakeTask.to_safe_identifier("foo bar:baz")
assert_equal id, "foo+bar%3Abaz"
end
test "from_safe_identifier unescapes" do
id = RakeUi::RakeTask.from_safe_identifier("foo+bar%3Abaz")
assert_equal id, "foo bar:baz"
end
test "it encodes the task name as the id" do
task = get_double_nested_task
assert_equal task.id, RakeUi::RakeTask.to_safe_identifier(task.name)
end
def get_double_nested_task
id = RakeUi::RakeTask.to_safe_identifier("double_nested:inside_double_nested:double_nested_task")
RakeUi::RakeTask.find_by_id(id)
end
end
class RakeTaskDebugLoggingTest < ActiveSupport::TestCase
test "call emits public safe lifecycle debug events" do
task = RakeUi::RakeTask.find_by_id(RakeUi::RakeTask.to_safe_identifier("regular"))
events = []
debug = lambda do |event, task_name:, task_log_id: nil|
events << {event: event, task_name: task_name, task_log_id: task_log_id}
end
RakeUi::DebugLogger.stub(:debug, debug) do
task.stub(:fork_task_execution, 1234) do
task.call
end
end
assert_equal [
"rake_ui.task_execution.requested",
"rake_ui.task_log.created",
"rake_ui.task_execution.forked"
], events.map { |event| event[:event] }
assert events.all? { |event| event[:task_name] == "regular" }
assert_nil events.first[:task_log_id]
assert events[1..].all? { |event| event[:task_log_id].present? }
end
end