Skip to content
This repository
Browse code

Merge pull request #5175 from jasonnoble/rake_notes_directories

Custom directories for rake notes
  • Loading branch information...
commit c435feb4044f6c62bb188c459c3be5d81cc77b07 2 parents 7d5146e + 324201d
Jeremy Kemper jeremy authored
13 guides/source/command_line.textile
Source Rendered
@@ -446,6 +446,19 @@ app/model/post.rb:
446 446
447 447 NOTE. When using specific annotations and custom annotations, the annotation name (FIXME, BUG etc) is not displayed in the output lines.
448 448
  449 +Be default, rake notes will look in the app, config, lib, script and test directories for notes. If you would like to search additional directories,
  450 +simply provide the directories as a comma seperated list in an environment variable +SOURCE_ANNOTATION_DIRECTORIES+.
  451 +
  452 +<shell>
  453 +$ export SOURCE_ANNOTATION_DIRECTORIES='rspec,vendor'
  454 +$ rake notes
  455 +(in /home/foobar/commandsapp)
  456 +app/model/user.rb:
  457 + * [ 35] [FIXME] User should have a subscription at this point
  458 +rspec/model/user_spec.rb:
  459 + * [122] [TODO] Verify the user that has a subscription works
  460 +</shell>
  461 +
449 462 h4. +routes+
450 463
451 464 +rake routes+ will list all of your defined routes, which is useful for tracking down routing problems in your app, or giving you a good overview of the URLs in an app you're trying to get familiar with.
5 railties/lib/rails/source_annotation_extractor.rb
@@ -14,6 +14,9 @@
14 14 # of the line (or closing ERB comment tag) is considered to be their text.
15 15 class SourceAnnotationExtractor
16 16 class Annotation < Struct.new(:line, :tag, :text)
  17 + def self.directories
  18 + @@directories ||= %w(app config lib script test) + (ENV['SOURCE_ANNOTATION_DIRECTORIES'] || '').split(',')
  19 + end
17 20
18 21 # Returns a representation of the annotation that looks like this:
19 22 #
@@ -48,7 +51,7 @@ def initialize(tag)
48 51
49 52 # Returns a hash that maps filenames under +dirs+ (recursively) to arrays
50 53 # with their annotations.
51   - def find(dirs=%w(app config lib script test))
  54 + def find(dirs = Annotation.directories)
52 55 dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
53 56 end
54 57
74 railties/test/application/rake/notes_test.rb
@@ -12,7 +12,7 @@ def teardown
12 12 teardown_app
13 13 end
14 14
15   - test 'notes' do
  15 + test 'notes finds notes for certain file_types' do
16 16 app_file "app/views/home/index.html.erb", "<% # TODO: note in erb %>"
17 17 app_file "app/views/home/index.html.haml", "-# TODO: note in haml"
18 18 app_file "app/views/home/index.html.slim", "/ TODO: note in slim"
@@ -49,7 +49,79 @@ def teardown
49 49 assert_equal ' ', line[1]
50 50 end
51 51 end
  52 + end
  53 +
  54 + test 'notes finds notes in default directories' do
  55 + app_file "app/controllers/some_controller.rb", "# TODO: note in app directory"
  56 + app_file "config/initializers/some_initializer.rb", "# TODO: note in config directory"
  57 + app_file "lib/some_file.rb", "# TODO: note in lib directory"
  58 + app_file "script/run_something.rb", "# TODO: note in script directory"
  59 + app_file "test/some_test.rb", 1000.times.map { "" }.join("\n") << "# TODO: note in test directory"
  60 +
  61 + app_file "some_other_dir/blah.rb", "# TODO: note in some_other directory"
  62 +
  63 + boot_rails
52 64
  65 + require 'rake'
  66 + require 'rdoc/task'
  67 + require 'rake/testtask'
  68 +
  69 + Rails.application.load_tasks
  70 +
  71 + Dir.chdir(app_path) do
  72 + output = `bundle exec rake notes`
  73 + lines = output.scan(/\[([0-9\s]+)\]/).flatten
  74 +
  75 + assert_match /note in app directory/, output
  76 + assert_match /note in config directory/, output
  77 + assert_match /note in lib directory/, output
  78 + assert_match /note in script directory/, output
  79 + assert_match /note in test directory/, output
  80 + assert_no_match /note in some_other directory/, output
  81 +
  82 + assert_equal 5, lines.size
  83 +
  84 + lines.each do |line_number|
  85 + assert_equal 4, line_number.size
  86 + end
  87 + end
  88 + end
  89 +
  90 + test 'notes finds notes in custom directories' do
  91 + app_file "app/controllers/some_controller.rb", "# TODO: note in app directory"
  92 + app_file "config/initializers/some_initializer.rb", "# TODO: note in config directory"
  93 + app_file "lib/some_file.rb", "# TODO: note in lib directory"
  94 + app_file "script/run_something.rb", "# TODO: note in script directory"
  95 + app_file "test/some_test.rb", 1000.times.map { "" }.join("\n") << "# TODO: note in test directory"
  96 +
  97 + app_file "some_other_dir/blah.rb", "# TODO: note in some_other directory"
  98 +
  99 + boot_rails
  100 +
  101 + require 'rake'
  102 + require 'rdoc/task'
  103 + require 'rake/testtask'
  104 +
  105 + Rails.application.load_tasks
  106 +
  107 + Dir.chdir(app_path) do
  108 + output = `SOURCE_ANNOTATION_DIRECTORIES='some_other_dir' bundle exec rake notes`
  109 + lines = output.scan(/\[([0-9\s]+)\]/).flatten
  110 +
  111 + assert_match /note in app directory/, output
  112 + assert_match /note in config directory/, output
  113 + assert_match /note in lib directory/, output
  114 + assert_match /note in script directory/, output
  115 + assert_match /note in test directory/, output
  116 +
  117 + assert_match /note in some_other directory/, output
  118 +
  119 + assert_equal 6, lines.size
  120 +
  121 + lines.each do |line_number|
  122 + assert_equal 4, line_number.size
  123 + end
  124 + end
53 125 end
54 126
55 127 private

0 comments on commit c435feb

Please sign in to comment.
Something went wrong with that request. Please try again.