log and readme should respect --quiet

This commit is contained in:
José Valim 2011-03-04 13:05:27 +01:00
parent 1db4969dc9
commit f00a398456
2 changed files with 29 additions and 3 deletions

View File

@ -264,17 +264,18 @@ module Rails
# readme "README" # readme "README"
# #
def readme(path) def readme(path)
say File.read(find_in_source_paths(path)) log File.read(find_in_source_paths(path))
end end
protected protected
# Define log for backwards compatibility. If just one argument is sent, # 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) def log(*args)
if args.size == 1 if args.size == 1
say args.first.to_s say args.first.to_s unless options.quiet?
else else
args << (self.behavior == :invoke ? :green : :red) args << (self.behavior == :invoke ? :green : :red)
say_status *args say_status *args

View File

@ -191,6 +191,31 @@ class ActionsTest < Rails::Generators::TestCase
assert_match(/Welcome to Rails/, action(:readme, "README")) assert_match(/Welcome to Rails/, action(:readme, "README"))
end 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 protected
def action(*args, &block) def action(*args, &block)