Skip to content
Browse files

log and readme should respect --quiet

  • Loading branch information...
1 parent 45d5663 commit eff41a2c05fbc6b0c86aae467fd9dc5bd515da67 @josevalim josevalim committed Mar 4, 2011
Showing with 29 additions and 3 deletions.
  1. +4 −3 railties/lib/rails/generators/actions.rb
  2. +25 −0 railties/test/generators/actions_test.rb
View
7 railties/lib/rails/generators/actions.rb
@@ -289,17 +289,18 @@ def route(routing_code)
# readme "README"
#
def readme(path)
- say File.read(find_in_source_paths(path))
+ log File.read(find_in_source_paths(path))
end
protected
# Define log for backwards compatibility. If just one argument is sent,
- # invoke say, otherwise invoke say_status.
+ # invoke say, otherwise invoke say_status. Differently from say and
+ # similarly to say_status, this method respects the quiet? option given.
#
def log(*args)
if args.size == 1
- say args.first.to_s
+ say args.first.to_s unless options.quiet?
else
args << (self.behavior == :invoke ? :green : :red)
say_status *args
View
25 railties/test/generators/actions_test.rb
@@ -223,6 +223,31 @@ def test_readme
assert_match(/Welcome to Rails/, action(:readme, "README"))
end
+ def test_readme_with_quiet
+ generator(default_arguments, :quiet => true)
+ run_generator
+ Rails::Generators::AppGenerator.expects(:source_root).times(2).returns(destination_root)
+ assert_no_match(/Welcome to Rails/, action(:readme, "README"))
+ end
+
+ def test_log
+ assert_equal("YES\n", action(:log, "YES"))
+ end
+
+ def test_log_with_status
+ assert_equal(" yes YES\n", action(:log, :yes, "YES"))
+ end
+
+ def test_log_with_quiet
+ generator(default_arguments, :quiet => true)
+ assert_equal("", action(:log, "YES"))
+ end
+
+ def test_log_with_status_with_quiet
+ generator(default_arguments, :quiet => true)
+ assert_equal("", action(:log, :yes, "YES"))
+ end
+
protected
def action(*args, &block)

0 comments on commit eff41a2

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