Added some specs,and some lines in README/CHANGELOG for dry-run option.

And added support for Kernel.#` and %x literal.
This commit is contained in:
yuuki arisawa 2011-06-28 22:13:24 +09:00
parent 49d14b1360
commit 847b2b8740
5 changed files with 57 additions and 4 deletions

View File

@ -6,6 +6,7 @@
## Improvements ## Improvements
- Pull request [#95](https://github.com/guard/guard/pull/95): Do a dry run without executing actions when the `:clear` option is given. ([@uk-ar][])
- Pull request [#94](https://github.com/guard/guard/pull/94): Show backtrace in terminal when a problem with a watch action occurs. ([@capotej][]) - Pull request [#94](https://github.com/guard/guard/pull/94): Show backtrace in terminal when a problem with a watch action occurs. ([@capotej][])
- Pull request [#88](https://github.com/guard/guard/pull/88): Write exception trace in the terminal when a supervised task fail. ([@mcmire][]) - Pull request [#88](https://github.com/guard/guard/pull/88): Write exception trace in the terminal when a supervised task fail. ([@mcmire][])
- Color in red the "ERROR:" flag when using `UI.error`. ([@rymai][]) - Color in red the "ERROR:" flag when using `UI.error`. ([@rymai][])

View File

@ -163,6 +163,15 @@ $ guard --debug
$ guard -d # shortcut $ guard -d # shortcut
``` ```
### `--dry-run` option
Do a dry run without executing actions:
``` bash
$ guard --dry-run
$ guard -y # shortcut
```
An exhaustive list of options is available with: An exhaustive list of options is available with:
``` bash ``` bash

View File

@ -19,10 +19,15 @@ module Guard
@options[:notify] && ENV["GUARD_NOTIFY"] != 'false' ? Notifier.turn_on : Notifier.turn_off @options[:notify] && ENV["GUARD_NOTIFY"] != 'false' ? Notifier.turn_on : Notifier.turn_off
Kernel.send(:define_method, :system ) do if @options[:"dry-run"]
|program, *args| print program + ' ' + args.join(' ') + "\n" Kernel.send(:define_method, :system ) do
end if options.dry_run |program, *args| Kernel.print program + ' ' + args.join(' ') + "\n"
end
Kernel.send(:define_method, :"`" ) do
|command| Kernel.print command + "\n"
end
end
self self
end end

View File

@ -9,7 +9,7 @@ module Guard
method_option :notify, :type => :boolean, :default => true, :aliases => '-n', :banner => "Notifications feature (growl/libnotify)" method_option :notify, :type => :boolean, :default => true, :aliases => '-n', :banner => "Notifications feature (growl/libnotify)"
method_option :debug, :type => :boolean, :default => false, :aliases => '-d', :banner => "Print debug messages" method_option :debug, :type => :boolean, :default => false, :aliases => '-d', :banner => "Print debug messages"
method_option :group, :type => :array, :default => [], :aliases => '-g', :banner => "Run only the passed groups" method_option :group, :type => :array, :default => [], :aliases => '-g', :banner => "Run only the passed groups"
method_option :dry_run, :type => :boolean, :default => false, :aliases => '-y', :banner => "Do a dry run without executing actions" method_option :"dry-run", :type => :boolean, :default => false, :aliases => '-y', :banner => "Do a dry run without executing actions"
desc "start", "Starts Guard" desc "start", "Starts Guard"
def start def start

View File

@ -39,6 +39,44 @@ describe Guard do
::Guard::Notifier.should_receive(:turn_off) ::Guard::Notifier.should_receive(:turn_off)
::Guard.setup(:notify => true) ::Guard.setup(:notify => true)
end end
context do
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 "overwrites Kernel.#system method if the dry-run option is false" do
::Guard.setup(:"dry-run" => false)
::Kernel.should_not_receive(:print).with("command arg1 arg2\n")
system("command","arg1","arg2")
end
it "overwrites Kernel.#system method if the dry-run option is true" do
::Guard.setup(:"dry-run" => true)
::Kernel.should_receive(:print).with("command arg1 arg2\n")
system("command","arg1","arg2")
end
it "overwrites Kernel.#` method if the dry-run option is false" do
::Guard.setup(:"dry-run" => false)
::Kernel.should_not_receive(:print).with("command\n")
`command`
%x{command}
end
it "overwrites Kernel.#` method if the dry-run option is false" do
::Guard.setup(:"dry-run" => true)
::Kernel.should_receive(:print).twice.with("command\n")
`command`
%x{command}
end
end
end end
describe ".get_guard_class" do describe ".get_guard_class" do