1
0
Fork 0
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:
Kasper Timm Hansen 2018-07-22 09:27:26 +02:00 committed by GitHub
commit 76f22e19d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,19 +30,22 @@ module ApplicationTests
app_file "config/locales/en.yaml", "# TODO: note in yaml" app_file "config/locales/en.yaml", "# TODO: note in yaml"
app_file "app/views/home/index.ruby", "# TODO: note in ruby" app_file "app/views/home/index.ruby", "# TODO: note in ruby"
run_rake_notes do |output, lines| stderr = capture(:stderr) do
assert_match(/note in erb/, output) run_rake_notes do |output, lines|
assert_match(/note in js/, output) assert_match(/note in erb/, output)
assert_match(/note in css/, output) assert_match(/note in js/, output)
assert_match(/note in rake/, output) assert_match(/note in css/, output)
assert_match(/note in builder/, output) assert_match(/note in rake/, output)
assert_match(/note in yml/, output) assert_match(/note in builder/, output)
assert_match(/note in yaml/, output) assert_match(/note in yml/, output)
assert_match(/note in ruby/, output) assert_match(/note in yaml/, output)
assert_match(/note in ruby/, output)
assert_equal 9, lines.size assert_equal 9, lines.size
assert_equal [4], lines.map(&:size).uniq assert_equal [4], lines.map(&:size).uniq
end
end end
assert_match(/DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/, stderr)
end end
test "notes finds notes in default directories" do test "notes finds notes in default directories" do
@ -54,17 +57,20 @@ module ApplicationTests
app_file "some_other_dir/blah.rb", "# TODO: note in some_other directory" app_file "some_other_dir/blah.rb", "# TODO: note in some_other directory"
run_rake_notes do |output, lines| stderr = capture(:stderr) do
assert_match(/note in app directory/, output) run_rake_notes do |output, lines|
assert_match(/note in config directory/, output) assert_match(/note in app directory/, output)
assert_match(/note in db directory/, output) assert_match(/note in config directory/, output)
assert_match(/note in lib directory/, output) assert_match(/note in db directory/, output)
assert_match(/note in test directory/, output) assert_match(/note in lib directory/, output)
assert_no_match(/note in some_other directory/, output) assert_match(/note in test directory/, output)
assert_no_match(/note in some_other directory/, output)
assert_equal 5, lines.size assert_equal 5, lines.size
assert_equal [4], lines.map(&:size).uniq assert_equal [4], lines.map(&:size).uniq
end
end end
assert_match(/DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/, stderr)
end end
test "notes finds notes in custom directories" do test "notes finds notes in custom directories" do
@ -76,21 +82,22 @@ module ApplicationTests
app_file "some_other_dir/blah.rb", "# TODO: note in some_other directory" 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
assert_match(/note in app directory/, output) run_rake_notes "SOURCE_ANNOTATION_DIRECTORIES='some_other_dir' bin/rake notes" do |output, lines|
assert_match(/note in config directory/, output) assert_match(/note in app directory/, output)
assert_match(/note in db directory/, output) assert_match(/note in config directory/, output)
assert_match(/note in lib directory/, output) assert_match(/note in db directory/, output)
assert_match(/note in test directory/, output) assert_match(/note in lib directory/, output)
assert_match(/note in test directory/, output)
assert_match(/note in some_other directory/, output) assert_match(/note in some_other directory/, output)
assert_equal 6, lines.size assert_equal 6, lines.size
assert_equal [4], lines.map(&:size).uniq assert_equal [4], lines.map(&:size).uniq
end
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 end
test "custom rake task finds specific notes in specific directories" do test "custom rake task finds specific notes in specific directories" do
@ -125,11 +132,14 @@ module ApplicationTests
app_file "app/assets/stylesheets/application.css.scss", "// TODO: note in scss" app_file "app/assets/stylesheets/application.css.scss", "// TODO: note in scss"
app_file "app/assets/stylesheets/application.css.sass", "// TODO: note in sass" app_file "app/assets/stylesheets/application.css.sass", "// TODO: note in sass"
run_rake_notes do |output, lines| stderr = capture(:stderr) do
assert_match(/note in scss/, output) run_rake_notes do |output, lines|
assert_match(/note in sass/, output) assert_match(/note in scss/, output)
assert_equal 2, lines.size assert_match(/note in sass/, output)
assert_equal 2, lines.size
end
end end
assert_match(/DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/, stderr)
end end
test "register additional directories" do test "register additional directories" do
@ -137,38 +147,27 @@ module ApplicationTests
app_file "spec/models/user_spec.rb", "# TODO: note in model spec" app_file "spec/models/user_spec.rb", "# TODO: note in model spec"
add_to_config ' config.annotations.register_directories("spec") ' add_to_config ' config.annotations.register_directories("spec") '
run_rake_notes do |output, lines| stderr = capture(:stderr) do
assert_match(/note in spec/, output) run_rake_notes do |output, lines|
assert_match(/note in model spec/, output) assert_match(/note in spec/, output)
assert_equal 2, lines.size assert_match(/note in model spec/, output)
assert_equal 2, lines.size
end
end end
assert_match(/DEPRECATION WARNING: This rake task is deprecated and will be removed in Rails 6.1/, stderr)
end end
private private
def run_rake_notes(command = "bin/rails notes") def run_rake_notes(command = "bin/rake notes")
boot_rails
load_tasks
Dir.chdir(app_path) do Dir.chdir(app_path) do
output = `#{command}` output = `#{command}`
lines = output.scan(/\[([0-9\s]+)\]\s/).flatten
lines = output.scan(/\[([0-9\s]+)\]\s/).flatten
yield output, lines yield output, lines
end end
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 end
end end