-
Notifications
You must be signed in to change notification settings - Fork 21.4k
/
help_integration_test.rb
86 lines (67 loc) · 2.16 KB
/
help_integration_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
# frozen_string_literal: true
require "isolation/abstract_unit"
require "rails/command"
class Rails::Command::HelpIntegrationTest < ActiveSupport::TestCase
setup :build_app
teardown :teardown_app
test "when passing --trace it invokes default" do
assert_match "Invoke default", rails("--trace")
end
test "prints helpful error on unrecognized command and allows command to be re-run" do
app_file("config/boot.rb", <<~RUBY, "a+")
require "rails/command"
module Rails
module Command
class UnrecognizedCommandCorrector
def yes?(statement, color = nil)
raise ArgumentError unless statement == "\nDid you mean? version [Yn]"
true
end
end
class << self
def tty?
true
end
end
end
end
RUBY
output = rails "vershen", allow_failure: true
assert_match %(Unrecognized command "vershen"), output
assert_match Rails::VERSION::STRING, output
end
test "loads Rake tasks only once on unrecognized command" do
app_file "lib/tasks/my_task.rake", <<~RUBY
puts "MY_TASK already defined? => \#{!!defined?(MY_TASK)}"
MY_TASK = true
RUBY
output = rails "vershen", allow_failure: true
assert_match "MY_TASK already defined? => false", output
assert_no_match "MY_TASK already defined? => true", output
end
test "prints help via `X:help` command when running `X` and `X:X` command is not defined" do
help = rails "dev:help"
output = rails "dev", allow_failure: true
assert_equal help, output
end
test "prints Rake tasks on --tasks / -T option" do
app_file "lib/tasks/my_task.rake", <<~RUBY
Rake.application.clear
desc "my_task"
task :my_task
RUBY
assert_match "my_task", rails("--tasks")
assert_match "my_task", rails("-T")
end
test "excludes application Rake tasks from command list via --help" do
app_file "Rakefile", <<~RUBY, "a"
desc "my_task"
task :my_task_1
RUBY
app_file "lib/tasks/my_task.rake", <<~RUBY
desc "my_task"
task :my_task_2
RUBY
assert_no_match "my_task", rails("--help")
end
end