Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure the logger is logging the whole command

  • Loading branch information...
commit bce41dc8fffe8471b616c04b126e01699dc04196 1 parent f5e8acd
@jyurek jyurek authored
View
11 lib/cocaine/command_line.rb
@@ -71,8 +71,9 @@ def command(interpolations = {})
def run(interpolations = {})
output = ''
begin
- @logger.info("\e[32mCommand\e[0m :: #{command}") if @logger
- output = execute(command(interpolations))
+ full_command = command(interpolations)
+ log("\e[32mCommand\e[0m :: #{full_command}")
+ output = execute(full_command)
rescue Errno::ENOENT
raise Cocaine::CommandNotFoundError
ensure
@@ -93,6 +94,12 @@ def unix?
private
+ def log(text)
+ if @logger
+ @logger.info(text)
+ end
+ end
+
def execute(command)
runner.call(command, environment)
end
View
1  lib/cocaine/command_line/runners/fake_runner.rb
@@ -10,6 +10,7 @@ def initialize
def call(command, env = {})
commands << [command, env]
+ ""
end
def ran?(predicate_command)
View
12 spec/cocaine/command_line_spec.rb
@@ -174,17 +174,15 @@
end
it "logs the command to a supplied logger" do
- logger = stub
- logger.stubs(:info).with(anything).returns(nil)
- Cocaine::CommandLine.new("echo", "'Logging!'", :logger => logger).run
- logger.should have_received(:info).with("\e[32mCommand\e[0m :: echo 'Logging!'")
+ logger = FakeLogger.new
+ Cocaine::CommandLine.new("echo", "'Logging!' :foo", :logger => logger).run(:foo => "bar")
+ logger.entries.should include("\e[32mCommand\e[0m :: echo 'Logging!' 'bar'")
end
it "logs the command to a default logger" do
- Cocaine::CommandLine.logger = stub
- Cocaine::CommandLine.logger.stubs(:info).with(anything).returns(nil)
+ Cocaine::CommandLine.logger = FakeLogger.new
Cocaine::CommandLine.new("echo", "'Logging!'").run
- Cocaine::CommandLine.logger.should have_received(:info).with("\e[32mCommand\e[0m :: echo 'Logging!'")
+ Cocaine::CommandLine.logger.entries.should include("\e[32mCommand\e[0m :: echo 'Logging!'")
end
it "is fine if no logger is supplied" do
View
13 spec/support/fake_logger.rb
@@ -0,0 +1,13 @@
+class FakeLogger
+ def initialize
+ @entries = []
+ end
+
+ def info(text)
+ @entries << text
+ end
+
+ def entries
+ @entries
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.