Permalink
Browse files

Extract rake notes command and lines scan boilerplate

Refactor to a reusable method.
  • Loading branch information...
1 parent 3a3a386 commit 9c5c0bcfa6d81d45ef091dc8740623faa5e19784 @carlosantoniodasilva carlosantoniodasilva committed Mar 18, 2014
Showing with 14 additions and 19 deletions.
  1. +14 −19 railties/test/application/rake/notes_test.rb
@@ -31,10 +31,7 @@ def teardown
boot_rails
load_tasks
- Dir.chdir(app_path) do
- output = `bundle exec rake notes`
- lines = output.scan(/\[([0-9\s]+)\]\s/).flatten
-
+ run_rake_notes do |output, lines|
assert_match(/note in erb/, output)
assert_match(/note in js/, output)
assert_match(/note in css/, output)
@@ -64,10 +61,7 @@ def teardown
boot_rails
load_tasks
- Dir.chdir(app_path) do
- output = `bundle exec rake notes`
- lines = output.scan(/\[([0-9\s]+)\]/).flatten
-
+ run_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)
@@ -95,10 +89,7 @@ def teardown
boot_rails
load_tasks
- Dir.chdir(app_path) do
- output = `SOURCE_ANNOTATION_DIRECTORIES='some_other_dir' bundle exec rake notes`
- lines = output.scan(/\[([0-9\s]+)\]/).flatten
-
+ run_rake_notes "SOURCE_ANNOTATION_DIRECTORIES='some_other_dir' bundle exec 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)
@@ -132,10 +123,7 @@ def teardown
boot_rails
load_tasks
- Dir.chdir(app_path) do
- output = `bundle exec rake notes_custom`
- lines = output.scan(/\[([0-9\s]+)\]/).flatten
-
+ run_rake_notes "bundle exec rake notes_custom" do |output, lines|
assert_match(/\[FIXME\] note in lib directory/, output)
assert_match(/\[TODO\] note in test directory/, output)
assert_no_match(/OPTIMIZE/, output)
@@ -157,9 +145,7 @@ def teardown
boot_rails
load_tasks
- Dir.chdir(app_path) do
- output = `bundle exec rake notes`
- lines = output.scan(/\[([0-9\s]+)\]/).flatten
+ run_rake_notes do |output, lines|
assert_match(/note in scss/, output)
assert_match(/note in sass/, output)
assert_equal 2, lines.size
@@ -168,6 +154,15 @@ def teardown
private
+ def run_rake_notes(command = 'bundle exec 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'

0 comments on commit 9c5c0bc

Please sign in to comment.