Merge branch 'master' of https://github.com/uk-ar/guard into uk-ar-master
Conflicts: CHANGELOG.md lib/guard.rb lib/guard/cli.rb
This commit is contained in:
commit
9175b33da4
@ -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
|
||||
|
16
lib/guard.rb
16
lib/guard.rb
@ -20,6 +20,8 @@ module Guard
|
||||
@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 @@ module Guard
|
||||
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
|
||||
|
@ -44,6 +44,11 @@ describe Guard do
|
||||
::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 @@ describe Guard do
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user