mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #33403 from bogdanvlviv/clarify-test_notes_finds_notes_in_custom_directories
Clarify `railties/test/application/rake/notes_test.rb`
This commit is contained in:
commit
76f22e19d6
1 changed files with 56 additions and 57 deletions
|
@ -30,6 +30,7 @@ module ApplicationTests
|
|||
app_file "config/locales/en.yaml", "# TODO: note in yaml"
|
||||
app_file "app/views/home/index.ruby", "# TODO: note in ruby"
|
||||
|
||||
stderr = capture(:stderr) do
|
||||
run_rake_notes do |output, lines|
|
||||
assert_match(/note in erb/, output)
|
||||
assert_match(/note in js/, output)
|
||||
|
@ -44,6 +45,8 @@ module ApplicationTests
|
|||
assert_equal [4], lines.map(&:size).uniq
|
||||
end
|
||||
end
|
||||
assert_match(/DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/, stderr)
|
||||
end
|
||||
|
||||
test "notes finds notes in default directories" do
|
||||
app_file "app/controllers/some_controller.rb", "# TODO: note in app directory"
|
||||
|
@ -54,6 +57,7 @@ module ApplicationTests
|
|||
|
||||
app_file "some_other_dir/blah.rb", "# TODO: note in some_other directory"
|
||||
|
||||
stderr = capture(:stderr) do
|
||||
run_rake_notes do |output, lines|
|
||||
assert_match(/note in app directory/, output)
|
||||
assert_match(/note in config directory/, output)
|
||||
|
@ -66,6 +70,8 @@ module ApplicationTests
|
|||
assert_equal [4], lines.map(&:size).uniq
|
||||
end
|
||||
end
|
||||
assert_match(/DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/, stderr)
|
||||
end
|
||||
|
||||
test "notes finds notes in custom directories" do
|
||||
app_file "app/controllers/some_controller.rb", "# TODO: note in app directory"
|
||||
|
@ -76,7 +82,8 @@ module ApplicationTests
|
|||
|
||||
app_file "some_other_dir/blah.rb", "# TODO: note in some_other directory"
|
||||
|
||||
run_rake_notes "SOURCE_ANNOTATION_DIRECTORIES='some_other_dir' bin/rails notes" do |output, lines|
|
||||
stderr = capture(:stderr) do
|
||||
run_rake_notes "SOURCE_ANNOTATION_DIRECTORIES='some_other_dir' bin/rake notes" do |output, lines|
|
||||
assert_match(/note in app directory/, output)
|
||||
assert_match(/note in config directory/, output)
|
||||
assert_match(/note in db directory/, output)
|
||||
|
@ -87,11 +94,11 @@ module ApplicationTests
|
|||
|
||||
assert_equal 6, lines.size
|
||||
assert_equal [4], lines.map(&:size).uniq
|
||||
|
||||
log = File.read(Rails.application.config.paths["log"].first)
|
||||
assert_match(/`SOURCE_ANNOTATION_DIRECTORIES` is deprecated/, log)
|
||||
end
|
||||
end
|
||||
assert_match(/DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/, stderr)
|
||||
assert_match(/DEPRECATION WARNING: `SOURCE_ANNOTATION_DIRECTORIES` is deprecated and will be removed in Rails 6.1/, stderr)
|
||||
end
|
||||
|
||||
test "custom rake task finds specific notes in specific directories" do
|
||||
app_file "app/controllers/some_controller.rb", "# TODO: note in app directory"
|
||||
|
@ -125,50 +132,42 @@ module ApplicationTests
|
|||
app_file "app/assets/stylesheets/application.css.scss", "// TODO: note in scss"
|
||||
app_file "app/assets/stylesheets/application.css.sass", "// TODO: note in sass"
|
||||
|
||||
stderr = capture(:stderr) do
|
||||
run_rake_notes do |output, lines|
|
||||
assert_match(/note in scss/, output)
|
||||
assert_match(/note in sass/, output)
|
||||
assert_equal 2, lines.size
|
||||
end
|
||||
end
|
||||
assert_match(/DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/, stderr)
|
||||
end
|
||||
|
||||
test "register additional directories" do
|
||||
app_file "spec/spec_helper.rb", "# TODO: note in spec"
|
||||
app_file "spec/models/user_spec.rb", "# TODO: note in model spec"
|
||||
add_to_config ' config.annotations.register_directories("spec") '
|
||||
|
||||
stderr = capture(:stderr) do
|
||||
run_rake_notes do |output, lines|
|
||||
assert_match(/note in spec/, output)
|
||||
assert_match(/note in model spec/, output)
|
||||
assert_equal 2, lines.size
|
||||
end
|
||||
end
|
||||
assert_match(/DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/, stderr)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def run_rake_notes(command = "bin/rails notes")
|
||||
boot_rails
|
||||
load_tasks
|
||||
|
||||
def run_rake_notes(command = "bin/rake notes")
|
||||
Dir.chdir(app_path) do
|
||||
output = `#{command}`
|
||||
|
||||
lines = output.scan(/\[([0-9\s]+)\]\s/).flatten
|
||||
|
||||
yield output, lines
|
||||
end
|
||||
end
|
||||
|
||||
def load_tasks
|
||||
require "rake"
|
||||
require "rdoc/task"
|
||||
require "rake/testtask"
|
||||
|
||||
Rails.application.load_tasks
|
||||
end
|
||||
|
||||
def boot_rails
|
||||
require "#{app_path}/config/environment"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue