Permalink
Browse files

Merge branch 'master' of https://github.com/uk-ar/guard into uk-ar-ma…

…ster

Conflicts:
	CHANGELOG.md
	lib/guard.rb
	lib/guard/cli.rb
  • Loading branch information...
2 parents 14a859d + 8d02eec commit 9175b33da4f7a52faa60c8408bb5553734000999 @netzpirat netzpirat committed Aug 5, 2011
Showing with 51 additions and 0 deletions.
  1. +2 −0 CHANGELOG.md
  2. +16 −0 lib/guard.rb
  3. +33 −0 spec/guard_spec.rb
View
@@ -7,6 +7,7 @@
## Improvements
+- Pull request [#95](https://github.com/guard/guard/pull/95): Output system commands and options to be executed when in debug mode. ([@uk-ar][] and [@netzpirat][])
- `Guard::Dsl.revaluate_guardfile` has been renamed to `Guard::Dsl.reevaluate_guardfile`. ([@rymai][])
- New CLI options: ([@nestegg][])
- `watchdir`/`-w` to specify the directory in which Guard should watch for changes,
@@ -214,6 +215,7 @@
[@thierryhenrio]: https://github.com/thierryhenrio
[@tinogomes]: https://github.com/tinogomes
[@tpope]: https://github.com/tpope
+[@uk-ar]: https://github.com/uk-ar
[@veged]: https://github.com/veged
[@wereHamster]: https://github.com/wereHamster
[@yannlugrin]: https://github.com/yannlugrin
View
@@ -20,6 +20,8 @@ def setup(options = {})
@options[:notify] && ENV["GUARD_NOTIFY"] != 'false' ? Notifier.turn_on : Notifier.turn_off
UI.clear if @options[:clear]
+ debug_command_execution if @options[:debug]
+
self
end
@@ -117,5 +119,19 @@ def locate_guard(name)
UI.error "Could not find 'guard-#{name}' gem path."
end
+ def debug_command_execution
+ Kernel.send(:alias_method, :original_system, :system)
+ Kernel.send(:define_method, :system) do |command, *args|
+ ::Guard::UI.debug "Command execution: #{command} #{args.join(' ')}"
+ original_system command, *args
+ end
+
+ Kernel.send(:alias_method, :original_backtick, :"`")
+ Kernel.send(:define_method, :"`") do |command|
+ ::Guard::UI.debug "Command execution: #{command}"
+ original_backtick command
+ end
+ end
+
end
end
View
@@ -44,6 +44,11 @@
::Guard::Notifier.should_receive(:turn_off)
::Guard.setup(:notify => true)
end
+
+ it "logs command execution if the debug option is true" do
+ ::Guard.should_receive(:debug_command_execution)
+ ::Guard.setup(:debug => true)
+ end
end
describe ".start" do
@@ -179,4 +184,32 @@ class Inline < Guard
end
end
+ describe ".debug_command_execution" do
+ subject { ::Guard.setup }
+
+ before do
+ @original_system = Kernel.method(:system)
+ @original_command = Kernel.method(:"`")
+ end
+
+ after do
+ Kernel.send(:define_method, :system, @original_system.to_proc )
+ Kernel.send(:define_method, :"`", @original_command.to_proc )
+ end
+
+ it "outputs Kernel.#system method parameters" do
+ ::Guard.setup(:debug => true)
+ ::Guard::UI.should_receive(:debug).with("Command execution: echo test")
+ system("echo", "test").should be_true
+ end
+
+ it "outputs Kernel.#` method parameters" do
+ ::Guard.setup(:debug => true)
+ ::Guard::UI.should_receive(:debug).twice.with("Command execution: echo test")
+ `echo test`.should eql "test\n"
+ %x{echo test}.should eql "test\n"
+ end
+
+ end
+
end

0 comments on commit 9175b33

Please sign in to comment.