@@ -30,19 +30,22 @@ def teardown
30
30
app_file "config/locales/en.yaml" , "# TODO: note in yaml"
31
31
app_file "app/views/home/index.ruby" , "# TODO: note in ruby"
32
32
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
45
47
end
48
+ assert_match ( /DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/ , stderr )
46
49
end
47
50
48
51
test "notes finds notes in default directories" do
@@ -54,17 +57,20 @@ def teardown
54
57
55
58
app_file "some_other_dir/blah.rb" , "# TODO: note in some_other directory"
56
59
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
67
72
end
73
+ assert_match ( /DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/ , stderr )
68
74
end
69
75
70
76
test "notes finds notes in custom directories" do
@@ -76,21 +82,22 @@ def teardown
76
82
77
83
app_file "some_other_dir/blah.rb" , "# TODO: note in some_other directory"
78
84
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 )
85
92
86
- assert_match ( /note in some_other directory/ , output )
93
+ assert_match ( /note in some_other directory/ , output )
87
94
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
93
98
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 )
94
101
end
95
102
96
103
test "custom rake task finds specific notes in specific directories" do
@@ -125,50 +132,42 @@ def teardown
125
132
app_file "app/assets/stylesheets/application.css.scss" , "// TODO: note in scss"
126
133
app_file "app/assets/stylesheets/application.css.sass" , "// TODO: note in sass"
127
134
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
132
141
end
142
+ assert_match ( /DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/ , stderr )
133
143
end
134
144
135
145
test "register additional directories" do
136
146
app_file "spec/spec_helper.rb" , "# TODO: note in spec"
137
147
app_file "spec/models/user_spec.rb" , "# TODO: note in model spec"
138
148
add_to_config ' config.annotations.register_directories("spec") '
139
149
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
144
156
end
157
+ assert_match ( /DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/ , stderr )
145
158
end
146
159
147
160
private
148
161
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" )
153
163
Dir . chdir ( app_path ) do
154
164
output = `#{ command } `
155
- lines = output . scan ( /\[ ([0-9\s ]+)\] \s / ) . flatten
165
+
166
+ lines = output . scan ( /\[ ([0-9\s ]+)\] \s / ) . flatten
156
167
157
168
yield output , lines
158
169
end
159
170
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
172
171
end
173
172
end
174
173
end
0 commit comments