Skip to content

Commit 76f22e1

Browse files
authored
Merge pull request rails#33403 from bogdanvlviv/clarify-test_notes_finds_notes_in_custom_directories
Clarify `railties/test/application/rake/notes_test.rb`
2 parents 9ca579a + a6ebafc commit 76f22e1

File tree

1 file changed

+58
-59
lines changed

1 file changed

+58
-59
lines changed

railties/test/application/rake/notes_test.rb

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,22 @@ def teardown
3030
app_file "config/locales/en.yaml", "# TODO: note in yaml"
3131
app_file "app/views/home/index.ruby", "# TODO: note in ruby"
3232

33-
run_rake_notes do |output, lines|
34-
assert_match(/note in erb/, output)
35-
assert_match(/note in js/, output)
36-
assert_match(/note in css/, output)
37-
assert_match(/note in rake/, output)
38-
assert_match(/note in builder/, output)
39-
assert_match(/note in yml/, output)
40-
assert_match(/note in yaml/, output)
41-
assert_match(/note in ruby/, output)
42-
43-
assert_equal 9, lines.size
44-
assert_equal [4], lines.map(&:size).uniq
33+
stderr = capture(:stderr) do
34+
run_rake_notes do |output, lines|
35+
assert_match(/note in erb/, output)
36+
assert_match(/note in js/, output)
37+
assert_match(/note in css/, output)
38+
assert_match(/note in rake/, output)
39+
assert_match(/note in builder/, output)
40+
assert_match(/note in yml/, output)
41+
assert_match(/note in yaml/, output)
42+
assert_match(/note in ruby/, output)
43+
44+
assert_equal 9, lines.size
45+
assert_equal [4], lines.map(&:size).uniq
46+
end
4547
end
48+
assert_match(/DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/, stderr)
4649
end
4750

4851
test "notes finds notes in default directories" do
@@ -54,17 +57,20 @@ def teardown
5457

5558
app_file "some_other_dir/blah.rb", "# TODO: note in some_other directory"
5659

57-
run_rake_notes do |output, lines|
58-
assert_match(/note in app directory/, output)
59-
assert_match(/note in config directory/, output)
60-
assert_match(/note in db directory/, output)
61-
assert_match(/note in lib directory/, output)
62-
assert_match(/note in test directory/, output)
63-
assert_no_match(/note in some_other directory/, output)
64-
65-
assert_equal 5, lines.size
66-
assert_equal [4], lines.map(&:size).uniq
60+
stderr = capture(:stderr) do
61+
run_rake_notes do |output, lines|
62+
assert_match(/note in app directory/, output)
63+
assert_match(/note in config directory/, output)
64+
assert_match(/note in db directory/, output)
65+
assert_match(/note in lib directory/, output)
66+
assert_match(/note in test directory/, output)
67+
assert_no_match(/note in some_other directory/, output)
68+
69+
assert_equal 5, lines.size
70+
assert_equal [4], lines.map(&:size).uniq
71+
end
6772
end
73+
assert_match(/DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/, stderr)
6874
end
6975

7076
test "notes finds notes in custom directories" do
@@ -76,21 +82,22 @@ def teardown
7682

7783
app_file "some_other_dir/blah.rb", "# TODO: note in some_other directory"
7884

79-
run_rake_notes "SOURCE_ANNOTATION_DIRECTORIES='some_other_dir' bin/rails notes" do |output, lines|
80-
assert_match(/note in app directory/, output)
81-
assert_match(/note in config directory/, output)
82-
assert_match(/note in db directory/, output)
83-
assert_match(/note in lib directory/, output)
84-
assert_match(/note in test directory/, output)
85+
stderr = capture(:stderr) do
86+
run_rake_notes "SOURCE_ANNOTATION_DIRECTORIES='some_other_dir' bin/rake notes" do |output, lines|
87+
assert_match(/note in app directory/, output)
88+
assert_match(/note in config directory/, output)
89+
assert_match(/note in db directory/, output)
90+
assert_match(/note in lib directory/, output)
91+
assert_match(/note in test directory/, output)
8592

86-
assert_match(/note in some_other directory/, output)
93+
assert_match(/note in some_other directory/, output)
8794

88-
assert_equal 6, lines.size
89-
assert_equal [4], lines.map(&:size).uniq
90-
91-
log = File.read(Rails.application.config.paths["log"].first)
92-
assert_match(/`SOURCE_ANNOTATION_DIRECTORIES` is deprecated/, log)
95+
assert_equal 6, lines.size
96+
assert_equal [4], lines.map(&:size).uniq
97+
end
9398
end
99+
assert_match(/DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/, stderr)
100+
assert_match(/DEPRECATION WARNING: `SOURCE_ANNOTATION_DIRECTORIES` is deprecated and will be removed in Rails 6.1/, stderr)
94101
end
95102

96103
test "custom rake task finds specific notes in specific directories" do
@@ -125,50 +132,42 @@ def teardown
125132
app_file "app/assets/stylesheets/application.css.scss", "// TODO: note in scss"
126133
app_file "app/assets/stylesheets/application.css.sass", "// TODO: note in sass"
127134

128-
run_rake_notes do |output, lines|
129-
assert_match(/note in scss/, output)
130-
assert_match(/note in sass/, output)
131-
assert_equal 2, lines.size
135+
stderr = capture(:stderr) do
136+
run_rake_notes do |output, lines|
137+
assert_match(/note in scss/, output)
138+
assert_match(/note in sass/, output)
139+
assert_equal 2, lines.size
140+
end
132141
end
142+
assert_match(/DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/, stderr)
133143
end
134144

135145
test "register additional directories" do
136146
app_file "spec/spec_helper.rb", "# TODO: note in spec"
137147
app_file "spec/models/user_spec.rb", "# TODO: note in model spec"
138148
add_to_config ' config.annotations.register_directories("spec") '
139149

140-
run_rake_notes do |output, lines|
141-
assert_match(/note in spec/, output)
142-
assert_match(/note in model spec/, output)
143-
assert_equal 2, lines.size
150+
stderr = capture(:stderr) do
151+
run_rake_notes do |output, lines|
152+
assert_match(/note in spec/, output)
153+
assert_match(/note in model spec/, output)
154+
assert_equal 2, lines.size
155+
end
144156
end
157+
assert_match(/DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/, stderr)
145158
end
146159

147160
private
148161

149-
def run_rake_notes(command = "bin/rails notes")
150-
boot_rails
151-
load_tasks
152-
162+
def run_rake_notes(command = "bin/rake notes")
153163
Dir.chdir(app_path) do
154164
output = `#{command}`
155-
lines = output.scan(/\[([0-9\s]+)\]\s/).flatten
165+
166+
lines = output.scan(/\[([0-9\s]+)\]\s/).flatten
156167

157168
yield output, lines
158169
end
159170
end
160-
161-
def load_tasks
162-
require "rake"
163-
require "rdoc/task"
164-
require "rake/testtask"
165-
166-
Rails.application.load_tasks
167-
end
168-
169-
def boot_rails
170-
require "#{app_path}/config/environment"
171-
end
172171
end
173172
end
174173
end

0 commit comments

Comments
 (0)