Compare commits

...

620 Commits

Author SHA1 Message Date
Michael Kessler
95f895e1ed GNTP needs Mac Growl >= 1.3. [ci skip] 2011-10-13 11:16:29 +02:00
Thibaud Guillaume-Gentil
3584dbbfbb Keep CHANGELOG up-to-date [ci skip] 2011-10-13 10:41:20 +02:00
Michael Kessler
10f1542ac3 Avoid Guard is not missing constant ... exceptions. (fixes #160) 2011-10-12 23:07:06 +02:00
Rémy Coutable
a5fb1aa601 Forcing some links for Rubydoc.info [ci skip] 2011-10-12 23:33:36 +03:00
Thibaud Guillaume-Gentil
50b35cc99c Fix README for rubydoc [ci skip] 2011-10-12 22:22:44 +02:00
Thibaud Guillaume-Gentil
5111e8594e Add new cli option
- The new cli option (-i / --no-interactions) allow to completely turn off any Guard terminal interactions
2011-10-12 22:14:25 +02:00
Thibaud Guillaume-Gentil
1a45a77969 Typo [ci skip] 2011-10-12 22:30:06 +03:00
Michael Kessler
67d73cf6a6 Avoid warnings on 1.8.7 2011-10-12 21:03:59 +02:00
Michael Kessler
6094451cfb Merge branch 'master' of github.com:guard/guard 2011-10-12 20:55:28 +02:00
Michael Kessler
3b0e2ad305 Add support for Growl Notification Transport Protocol. 2011-10-12 20:54:57 +02:00
Michael Kessler
83def5004f Disable bdd cycle.
Yes, it takes a way to long before you can get started.
We anyway have to run spec:portability to also locally
test on all supported Rubies.
2011-10-12 18:15:11 +02:00
Rémy Coutable
18e0f99a6d Added a sentence to tell people to check out the installation instructions specific to their operating systems. 2011-10-12 15:53:54 +03:00
Michael Kessler
4ed28a3cbe Add watcher changes to the changelog. 2011-10-11 11:18:24 +02:00
Michael Kessler
7383efaf31 Document any_return on the Guard class. 2011-10-11 11:16:11 +02:00
Michael Kessler
f6bea4da59 Document known guard options. 2011-10-11 11:09:41 +02:00
Michael Kessler
8527cf40e3 Make only one assumption per context. 2011-10-11 11:06:30 +02:00
Michael Kessler
8891776e34 Merge remote-tracking branch 'earlonrails/return_on_guard' 2011-10-11 10:55:12 +02:00
Kevin Krauss
5429d10eb5 Removed extra attr_accessor and used proper formatting. 2011-10-10 15:10:44 -07:00
Kevin Krauss
037b1e6feb Optional user defined return with guard options[:any_return] 2011-10-10 13:38:14 -07:00
Kevin Krauss
bdfdf45325 Switched the parameter to be added to the guard instead of the watcher. 2011-10-10 09:52:53 -07:00
Michael Kessler
0b837a20ec Keep changelog in sync. [ci skip] 2011-10-10 08:36:32 +02:00
Michael Kessler
5c0105b2c1 Describe why UI class uses STDERR. 2011-10-10 08:29:43 +02:00
Thibaud Guillaume-Gentil
6f1a0acb2e Merge pull request #156 from sunaku/patch-1
ui: print to STDERR (play nice with UNIX pipes)
2011-10-09 23:19:08 -07:00
Michael Kessler
1845efb11e Add missing specs for Guard implementation base class 2011-10-10 08:05:10 +02:00
Kevin Krauss
a274fb1ddf fixed spec for guard 2011-10-09 16:06:38 -07:00
Kevin Krauss
b2f282f1e8 watcher cleaned up. 2011-10-09 15:54:24 -07:00
Suraj N. Kurapati
31519887cd ui: print to STDERR (play nice with UNIX pipes) 2011-10-09 00:10:39 -07:00
Thibaud Guillaume-Gentil
1c6ce380ea Update README about Growl 1.3 2011-10-08 13:18:10 +03:00
Kevin Krauss
a7b6ebeef1 updated the watch spec to describe the tests better. 2011-10-07 10:45:26 -07:00
Kevin Krauss
33542acec9 watcher init now has an addition param that allows the user to return any obj type. The spec has been restored to its original and then more specs added for object support. 2011-10-07 10:36:47 -07:00
Kevin Krauss
d6b47f6448 Changed {:foo, 'bar'} to {:foo => 'bar'} 2011-10-05 18:09:28 -07:00
Kevin Krauss
a5dd0c7847 any return is ok. Pass the path and some other parameters if you would like and they don't become strings! 2011-10-05 18:01:55 -07:00
Thibaud Guillaume-Gentil
bebaef1592 Merge pull request #152 from scottdavis/master
Growl Notify Api Update
2011-10-04 23:34:29 -07:00
Kevin Krauss
47f3d878f6 When using a block allow none string return 2011-10-04 22:17:07 -07:00
Scott Davis
1181b8b234 updated the growl notify code to gracefuly fail if growl is not installed - this is new in growl_notify-0.0.3 2011-10-05 01:10:48 -04:00
Michael Kessler
8b6a035dfe Make spec example simpler to avoid Ruby hash ordering issue. 2011-10-04 11:37:12 +02:00
Michael Kessler
a1e5723efe Sort the Guard options when describe the DSL. 2011-10-04 10:26:06 +02:00
Michael Kessler
4451d73583 Move the template initialization to the Guard module and add specs. 2011-10-04 09:46:14 +02:00
Michael Kessler
cdf0906614 Move the DSL describing logic from the CLI to the DSLDescriber. 2011-10-04 09:04:50 +02:00
Michael Kessler
cba4e4c163 Add --fail-fast to RSpec configuration. 2011-10-04 08:51:55 +02:00
Michael Kessler
eb7081e3d2 Describe the relation of a task return value and the hook functions. 2011-10-03 11:32:40 +02:00
Thibaud Guillaume-Gentil
da866d3380 Version 0.8.4 2011-10-03 08:25:07 +02:00
Rémy Coutable
ac42712335 Fixed link.
[ci skip]
2011-10-03 01:10:37 +03:00
Rémy Coutable
6ae9a83dbd Complete & simplify the CHANGELOG 2011-10-03 01:09:04 +03:00
Rémy Coutable
910856362e Merge pull request #150 from f1sherman/use_mutex_instead_of_lock
fix issue where interator thread was continuing to capture input from std
2011-10-02 14:56:43 -07:00
Brian John
cd545d5207 fix issue where interator thread was continuing to capture input from stdin while a guard is being executed 2011-10-02 16:46:20 -05:00
Michael Kessler
1090e0f797 Merge pull request #148 from simi/patch-1
Correct string interpolation at guard init
2011-10-02 06:20:17 -07:00
Josef Šimánek
b15638f13c Correct string interpolation at guard init 2011-10-02 16:15:48 +03:00
Thibaud Guillaume-Gentil
64ac60a1fe Version 0.8.3 2011-10-01 20:53:21 +02:00
Michael Kessler
e26c1d2179 Update CHANGELOG. 2011-10-01 13:38:04 +02:00
Michael Kessler
7dcd7ca168 Update wrong spec description. 2011-10-01 13:37:49 +02:00
Brian John
b3535b4a4e use a mutex instead of a lock for more efficient/simple locking 2011-09-30 20:45:41 -05:00
Michael Kessler
3c75205dd0 Merge branch 'master' of github.com:guard/guard 2011-09-30 18:35:31 +02:00
Michael Kessler
e33f5df518 Make Guard implementation of :task_has_failed simple.
This change makes sure that Guard implementation can just
`throw :task_has_failed` without knowing whether the enclosing
group has enabled :halt_on_fail.

The problem with throw/catch is, that when you throw a :symbol,
you'll have to catch it, otherwise you get a 'uncatched throw' error.

When the Guard group has not enabled :halt_on_fail, we catch the throw
when execute the supervised task.
2011-09-30 18:35:04 +02:00
Thibaud Guillaume-Gentil
b36bea28f3 Merge pull request #145 from johnbintz/master
Fix over-utilization of CPU in Interactor
2011-09-30 09:17:44 -07:00
John Bintz
776361d038 add a sleep to the interactor thread, because it's healthy to take a break every once in a while 2011-09-30 11:22:35 -04:00
Thibaud Guillaume-Gentil
6ecc541bda Version 0.8.2 2011-09-30 16:47:43 +02:00
Michael Kessler
e9ddb1c110 Update wrong doc example. [ci skip] 2011-09-30 12:13:50 +02:00
Michael Kessler
5bdb56caa0 Update docs regarding :task_has_failed.
- Add :task_has_failed documentation to Guard and Group classes
- Consolidated Guard documentation from the README and its YARDOC.
- Remove all return `true` values from Guard task methods.
2011-09-30 11:30:05 +02:00
Thibaud Guillaume-Gentil
56ebe9f9f4 Improve guard stop
- prevent run_guard_task(:stop) to be skipped
2011-09-29 22:39:24 +02:00
Thibaud Guillaume-Gentil
aaa08d3a89 Version 0.8.1 2011-09-29 09:22:02 +02:00
Rémy Coutable
1607901e43 Fixes #144, due to a too-hardore refactoring! ;)
We will need specs for Guard::CLI!
2011-09-29 00:27:37 +02:00
Thibaud Guillaume-Gentil
243ea157a9 Version 0.8.0 2011-09-28 22:18:29 +02:00
Rémy Coutable
b2488e7b9e Edited CHANGELOG.md via GitHub 2011-09-28 17:20:02 +03:00
Rémy Coutable
309ecc7b4b Edited README.md via GitHub 2011-09-28 17:15:47 +03:00
Michael Kessler
db949bf9e4 Refactor the watch_all_modifications specs.
- Just test a single expectation per it block
- Better separation of fixture setup/teardown
2011-09-28 15:57:30 +02:00
Michael Kessler
40e033ce0f Document passed options. 2011-09-28 15:47:53 +02:00
Michael Kessler
5d122466fa Use new fixture helper. 2011-09-28 15:16:55 +02:00
Michael Kessler
ca7b059c66 Fix wrong wording. 2011-09-28 15:16:19 +02:00
Michael Kessler
5325cbdea1 Refactor listener specs.
- Introduce `listen_to`, `fixture` and `watch` spec helpers.
- Added docs to spec helper.
- Better separation of fixture setup/teardown and the actual expectation.
- Make line match within 120 characters.
2011-09-28 15:06:33 +02:00
Michael Kessler
14150889c5 Align variable assignment, make return variable clear. 2011-09-28 13:46:05 +02:00
Michael Kessler
ec71eea227 Minor doc changes. 2011-09-28 13:41:29 +02:00
Michael Kessler
81f713a9ae Ignore .rvmrc. 2011-09-28 13:36:13 +02:00
Michael Kessler
83b1c9f787 Trigger all listener specs when listener_helper.rb is changed. 2011-09-28 13:34:53 +02:00
Michael Kessler
b00c850ef8 Put guards into groups.
Now I can just run the :specs group and run all specs
without generating the man pages.

In addition I enabled the full BDD cycle for development,
not sure why it wasn't enabled. Feel free to revert if there
is a specific reason for that.
2011-09-28 13:24:01 +02:00
Michael Kessler
a91874a4df Ignore .rbx folder 2011-09-28 13:20:30 +02:00
Michael Kessler
b64b7882f7 Refactor massive execute_supervised_task_for_all_guards method.
- Renamed some Guard methods to be shorter and more consistent.
- Extract methods from execute_supervised_task_for_all_guards for less complexity.
- Added more specs for extracted methods.
- Added more docs on how marking of deleted/moved files works.
- Refactor Guard to be unaware of the :watch_all_modifications options for simplicity.
2011-09-28 12:42:09 +02:00
Michael Kessler
805fd174d9 Merge branch 'master' of github.com:guard/guard 2011-09-28 10:22:02 +02:00
Thibaud Guillaume-Gentil
479c6b1918 Typo 2011-09-28 08:47:01 +02:00
Michael Kessler
d857134446 Fix code indention. 2011-09-27 20:44:17 +02:00
Michael Kessler
7e6e52a2c9 Docs for #run_on_deletion Guard method. 2011-09-27 20:29:52 +02:00
Darren Pearce
87656c2065 Merge branch 'master' of git://github.com/guard/guard 2011-09-26 13:47:20 -06:00
Rémy Coutable
4572cbed0c Remove strange man pages 2011-09-26 21:43:52 +02:00
Darren Pearce
67882bcceb Merge branch 'master' of git://github.com/guard/guard
Conflicts:
	lib/guard.rb
2011-09-26 12:22:02 -06:00
Darren Pearce
d9fc071492 fixed typo and updated relativize_paths regex 2011-09-26 11:37:54 -06:00
Michael Kessler
a1f37f60d6 Re-evaluate the Guardfile before reload all Guards (Fixes #141). 2011-09-24 12:58:27 +02:00
Michael Kessler
0936771a9e Decrease Travis sleep time. 2011-09-24 12:20:35 +02:00
Michael Kessler
e9eaa39e4d Remove Travis debug output. 2011-09-24 12:14:59 +02:00
Michael Kessler
1571292ba7 Make spec sleep time a float. 2011-09-24 11:35:53 +02:00
Michael Kessler
8365d7c429 Set a generous spec sleep time on Travis. 2011-09-24 11:10:01 +02:00
Michael Kessler
5de287ba95 Make the sleep time for listener specs configurable. 2011-09-24 11:09:32 +02:00
Rémy Coutable
5c9ee2afdf Yardoc improvements [ci skip] 2011-09-23 11:01:52 +02:00
Rémy Coutable
a7a6c5c69e Improves yardoc (hopefully) [ci skip] 2011-09-23 10:52:58 +02:00
Rémy Coutable
a326c35875 Fix specs for Ruby != 1.9 2011-09-23 00:53:13 +02:00
Rémy Coutable
2f59a10558 Update CHANGELOG 2011-09-23 00:41:39 +02:00
Rémy Coutable
41ada16595 Allow more complex conditions when searching for guards 2011-09-23 00:39:27 +02:00
Rémy Coutable
0a60575dde Update CHANGELOG 2011-09-23 00:32:30 +02:00
Rémy Coutable
dc526f2898 Man 2011-09-23 00:23:46 +02:00
Rémy Coutable
1cd669bf60 Refactor & fix specs 2011-09-23 00:22:44 +02:00
Rémy Coutable
916613c027 Ensure group name is a Symbol in Guard::Guard#initialize 2011-09-23 00:22:25 +02:00
Rémy Coutable
12fcf15a95 New smart accessors for guards and groups 2011-09-23 00:21:30 +02:00
Rémy Coutable
ed97336c7d New Group class 2011-09-23 00:20:35 +02:00
Rémy Coutable
4c1cf825e5 Merge branch 'master' into guard_dependencies
Conflicts:
	lib/guard.rb
	lib/guard/dsl.rb
	man/guard
	man/guard.html
2011-09-22 22:44:15 +02:00
Darren Pearce
ec463a271b Merge branch 'master' of git://github.com/guard/guard
Conflicts:
	lib/guard/listener.rb
2011-09-21 17:14:09 -06:00
Darren Pearce
0c9634a1c2 updated README 2011-09-21 17:04:10 -06:00
Darren Pearce
432d4a0991 changed watch deletions option to watch_all_modifiactions, Merge branch 'master' of git://github.com/guard/guard
Conflicts:
	lib/guard.rb
	lib/guard/cli.rb
	lib/guard/listener.rb
2011-09-21 17:00:53 -06:00
Rémy Coutable
bda57d1d8f Little doc improvements 2011-09-21 18:54:33 +02:00
Michael Kessler
507abce5b6 Fix some typos, better wording and formatting. 2011-09-21 01:30:35 +02:00
Michael Kessler
78448631ab Remove GitHub flavoured Markdown until rubydoc.info shows the README correct. 2011-09-21 00:55:07 +02:00
Michael Kessler
072d5404ee Merge pull request #137 from hron/guard
---

It seems like the new interactor eats input from $stdin even while it is locked. This disallow using tools like ruby-debug or pry in specs or cucumber.

The fix just kills the interactor when it is locked and runs it again when ulocked.

Conflicts:
	lib/guard/interactor.rb
2011-09-21 00:34:11 +02:00
Rémy Coutable
9ebc59f533 Merge pull request #138 from rmm5t/patch-1
Fixed comments in example scaffold to reference interactions
2011-09-20 13:18:16 -07:00
Rémy Coutable
d493e3c5d9 Tiny doc improvements 2011-09-20 21:52:59 +02:00
Ryan McGeary
dd1a5cbb49 Fixed comments in example scaffold to reference interactions instead of signal handlers 2011-09-20 16:24:00 -03:00
Aleksei Gusev
8c6a30795a Change Guard::Interactor#lock and #unlock methods so they will lock interactor
in the right thread and free $stdin [closes #137].
2011-09-20 21:54:21 +03:00
Michael Kessler
c0dcef9dbc 100% yardoc
Files:          16
Modules:         5 (    0 undocumented)
Classes:        11 (    0 undocumented)
Constants:      20 (    0 undocumented)
Methods:       136 (    0 undocumented)
 100.00% documented
2011-09-20 15:07:29 +02:00
Michael Kessler
b944932f53 Document the hook module. 2011-09-20 14:42:32 +02:00
Michael Kessler
33b52d2955 Fix guard groups. 2011-09-20 14:26:27 +02:00
Michael Kessler
53802ed355 Add yardoc to listeners. 2011-09-20 13:58:25 +02:00
Michael Kessler
ad6fe6f69b Yardoc for the interactor. 2011-09-20 13:10:16 +02:00
Michael Kessler
98ee450037 Initial notifier yardoc. 2011-09-20 13:06:35 +02:00
Michael Kessler
ab91117ed7 Add yardoc to the UI class. 2011-09-20 12:54:36 +02:00
Michael Kessler
dddc2ad369 Add yardoc to the watcher class. 2011-09-20 12:54:28 +02:00
Michael Kessler
044100b7c3 Fix command debug. 2011-09-20 12:10:53 +02:00
Michael Kessler
2fa0f7255a Fix wrong params tag. 2011-09-20 12:08:51 +02:00
Michael Kessler
0f5b2b764a Initial yardoc for the main Guard class for specific implementations. 2011-09-20 12:07:34 +02:00
Michael Kessler
dc009d445a Add yardoc for the DslDescriber. 2011-09-20 11:49:05 +02:00
Michael Kessler
d66a872f4a Initial yardoc for Guard. 2011-09-20 11:40:47 +02:00
Michael Kessler
9df4b3c291 Add options to evaluate_guardfile. 2011-09-20 11:23:37 +02:00
Michael Kessler
7099774e7c Fix wrong yard param tags. 2011-09-20 11:13:12 +02:00
Michael Kessler
aa55d48b96 Initial yardoc for the DSL class. 2011-09-20 11:11:40 +02:00
Michael Kessler
e126c7f609 Add yardoc for CLI class. 2011-09-20 10:05:11 +02:00
Michael Kessler
48863fee0d Ignore generated documentation. 2011-09-20 10:03:09 +02:00
Michael Kessler
42d4d94611 Add yard options. 2011-09-20 10:02:54 +02:00
Michael Kessler
fc3e179a0c Add yard and kramdown to development dependencies. 2011-09-20 10:02:43 +02:00
Aleksei Gusev
443f57efce Fix interacting with tools like ruby-debug.
It seems like the new interactor eats input from $stdin even while it locked.
  This disallow using tools like 'ruby-debug' or 'pry' in specs or cucumber.

  The fix just kills the interactor when it is locked and runs it again when
  ulocked.
2011-09-19 23:27:05 +03:00
Rémy Coutable
f9521fe0fe nil is not accepted for catch's arg in other implementation than 1.9.2 2011-09-16 01:26:27 +02:00
Rémy Coutable
1608b17501 Build only master and guard_dependencies branches on Travis 2011-09-16 01:20:42 +02:00
Rémy Coutable
078d55f13c Actually halt guards' execution in a group only when the guard's task throw :task_has_failed (not when it returns false). 2011-09-16 01:20:22 +02:00
Rémy Coutable
b1b69924a7 First implementation of #97 "Guard dependencies". 2011-09-16 01:01:58 +02:00
Rémy Coutable
22001c5ecd Optimize multiple if statements in Gemfile. 2011-09-15 22:02:23 +03:00
Darren Pearce
6993712c38 Merge branch 'master' of git://github.com/guard/guard 2011-09-14 11:44:36 -06:00
Darren Pearce
5a70faf974 updated deletion option name to be more explict 2011-09-14 11:44:01 -06:00
Thibaud Guillaume-Gentil
fb2c320a2a Version 0.7.0 2011-09-14 09:52:36 +02:00
Darren Pearce
879732fb43 updated README with deletions option 2011-09-13 22:56:23 -06:00
Darren Pearce
34aaed9741 fixed specs to cleanup afterwards 2011-09-13 22:46:56 -06:00
Darren Pearce
b74d09b9d6 Merge remote branch 'upstream/master'
Conflicts:
	lib/guard.rb
	lib/guard/listener.rb
	spec/guard/listener_spec.rb
2011-09-13 16:50:24 -06:00
Darren Pearce
423610f22d moved timestamp hash creation into it's own method add initial specs for watching deleted files and fixed some minor formatting 2011-09-13 16:22:39 -06:00
Rémy Coutable
9ad866079f https://secure.travis-ci.org is working again! Houra! 2011-09-06 13:01:06 +03:00
Thibaud Guillaume-Gentil
c704fe5d0b Version 0.7.0.rc1 2011-09-05 11:25:49 +02:00
Thibaud Guillaume-Gentil
da46791204 Added @netzpirat to the JRuby & Rubinius support in the CHANGELOG [ci skip] 2011-09-05 12:24:26 +03:00
Michael Kessler
84d6641925 Merge branch 'master' of github.com:guard/guard 2011-09-05 10:57:41 +02:00
Michael Kessler
2edf8bead6 Add JRuby and Rubinius to the list of tested Rubies. 2011-09-05 10:57:21 +02:00
Michael Kessler
b37928a540 Remove jruby_spec branch from Travis. 2011-09-05 10:54:45 +02:00
Michael Kessler
b1bef902b1 Correct typo. 2011-09-05 10:44:50 +02:00
Thibaud Guillaume-Gentil
16fe7441d4 Use [mtime, ctime].max for == comparaison
Conflicts:

	lib/guard/listener.rb
2011-09-05 10:43:18 +02:00
Rémy Coutable
58af2b2c1d Merge branch 'master' of github.com:guard/guard 2011-09-05 10:40:13 +02:00
Rémy Coutable
330493a572 Don't put a newline in debug output 2011-09-05 10:39:56 +02:00
Michael Kessler
59103ffe09 Use the listener_helpers start/stop. 2011-09-05 10:36:45 +02:00
Michael Kessler
d88ffec9a0 Merge branch 'master' of github.com:guard/guard 2011-09-05 10:17:18 +02:00
Michael Kessler
54689318cc Configure Travis to build new branches. 2011-09-05 10:16:40 +02:00
Rémy Coutable
dc9bddf02e Merge branch 'master' of github.com:guard/guard 2011-09-05 10:16:17 +02:00
Rémy Coutable
771c9d08c0 Tell Travis-CI to notify only the core team.
Currently it notifies some people but I don't get how they are chosen, it even notifies me on 2 email addresses (my current and my former registered on GitHub)…
2011-09-05 10:16:11 +02:00
Michael Kessler
d1c452bc1e Revert "More Travis tests."
This reverts commit bd67a69a8b.
2011-09-05 10:07:19 +02:00
Michael Kessler
bd67a69a8b More Travis tests. 2011-09-05 09:42:05 +02:00
Rémy Coutable
3de4f505d6 Merge branch 'master' into hook 2011-09-04 18:50:59 +02:00
Rémy Coutable
596f92f7eb Update README 2011-09-04 18:47:51 +02:00
Rémy Coutable
fe103ca9a4 Update CHANGELOG 2011-09-04 18:45:26 +02:00
Rémy Coutable
b8beb3fb9e Update man 2011-09-04 18:45:14 +02:00
Rémy Coutable
96604060ed Clean Hook code 2011-09-04 18:44:42 +02:00
Rémy Coutable
3d9d1ad649 Make it (even) more clear that stdin.gets is only available in the HEAD/0.7! [ci skip] 2011-09-04 19:29:18 +03:00
Rémy Coutable
11495687f4 Merge branch 'master' into hook
Conflicts:
	Guardfile
	lib/guard.rb
	lib/guard/dsl.rb
	spec/guard/interactor_spec.rb
	spec/guard/listeners/darwin_spec.rb
2011-09-04 18:00:29 +02:00
Michael Kessler
8255ae0be9 Working on a fork with Travis won't work. Re-add feature branch. 2011-09-04 16:18:31 +02:00
Michael Kessler
20305a59ba Remove testing branch. 2011-09-04 15:26:58 +02:00
Michael Kessler
b8e43e7a7c Add JRuby/Travis test branch to CI. 2011-09-04 14:41:28 +02:00
Michael Kessler
69d308b505 Fix Travis CI build status image.
The image is not displayed properly because Travis SSL uses the
Heroku wildcard SSL certificate and is thus not trusted because
of the URL mismatch.
2011-09-04 01:13:23 +02:00
Michael Kessler
8bb295f105 Link to the wiki for more information on growl_notify vs. growl. 2011-09-03 23:38:07 +02:00
Rémy Coutable
0a2a34e55f Edited CHANGELOG.md via GitHub 2011-09-04 00:33:53 +03:00
Thibaud Guillaume-Gentil
50d80d962b Update CHANGELOG 2011-09-03 23:17:00 +02:00
Thibaud Guillaume-Gentil
85f67f26ab Update man 2011-09-03 23:15:03 +02:00
Thibaud Guillaume-Gentil
60874a6991 Clean 2011-09-03 22:46:09 +02:00
Thibaud Guillaume-Gentil
1c5d1fd268 Merge branch 'master' into stdin 2011-09-03 22:45:04 +02:00
Thibaud Guillaume-Gentil
a288f51ec8 Update man files 2011-09-03 22:40:18 +02:00
Thibaud Guillaume-Gentil
215af072a2 Replace Signal handlers README section by Interactions 2011-09-03 22:40:06 +02:00
Thibaud Guillaume-Gentil
9fcd8621ad Ignore *.rbc 2011-09-03 22:38:03 +02:00
Thibaud Guillaume-Gentil
f91622adc5 Clean 2011-09-03 22:37:50 +02:00
Thibaud Guillaume-Gentil
e1472cb0c4 Make specs pass on jruby & rubinius (Mac OS X) 2011-09-03 22:37:36 +02:00
Rémy Coutable
5fee2f919e Updated man 2011-09-03 22:18:57 +02:00
Thibaud Guillaume-Gentil
ee5468eeeb Don't kill listener thread on spec 2011-09-03 21:44:09 +02:00
Thibaud Guillaume-Gentil
b0295c1437 Merge branch 'master' into stdin 2011-09-03 21:33:32 +02:00
Thibaud Guillaume-Gentil
8b66b71716 Travis test 2011-09-03 21:33:06 +02:00
Rémy Coutable
94a7c99b0c growl_notify gem is recommended over growl gem 2011-09-03 22:15:41 +03:00
Rémy Coutable
7ffa358b3a Edited README.md via GitHub 2011-09-03 21:30:44 +03:00
Rémy Coutable
62ef515824 Oops! [ci skip] 2011-09-03 20:07:08 +03:00
Rémy Coutable
2769541e8e Improve the README 2011-09-03 20:05:50 +03:00
Thibaud Guillaume-Gentil
41127e2cbf Only use crime on == timestamp comparison 2011-09-03 14:52:33 +02:00
Thibaud Guillaume-Gentil
5978e875df Put mtime (maybe ctime is updated on linux when moving a file) 2011-09-03 14:43:25 +02:00
Thibaud Guillaume-Gentil
68efb0d52f Focus on failed spec 2011-09-03 14:30:15 +02:00
Thibaud Guillaume-Gentil
667b248ad0 Add attrib on linux listener 2011-09-03 14:25:12 +02:00
Thibaud Guillaume-Gentil
18cb3471af Try to debug linux spec on travis 2011-09-03 14:16:32 +02:00
Thibaud Guillaume-Gentil
905c32dcc9 Add listener spec for chmod modification 2011-09-03 14:15:54 +02:00
Thibaud Guillaume-Gentil
45ba095093 Merge branch 'master' into stdin 2011-09-02 16:22:49 +02:00
Thibaud Guillaume-Gentil
0c7b496296 Add stdin branch to travis 2011-09-02 16:22:24 +02:00
Thibaud Guillaume-Gentil
f8b4f45737 Fix spec 2011-09-02 16:22:09 +02:00
Thibaud Guillaume-Gentil
47be15125b Skip reactor on test env
Update last_event sooner
Use ctime instead of mtime (Rails 3.1 assets pipeline issue)
2011-09-02 16:22:01 +02:00
Thibaud Guillaume-Gentil
c4ddb29fc6 Work on specs 2011-09-01 23:24:45 +02:00
Thibaud Guillaume-Gentil
3b73ea77b7 Merge branch 'master' into stdin 2011-09-01 21:59:00 +02:00
Michael Kessler
2ad9c5d51c Remove claim that Spork doesn't work with growl_notify. 2011-09-01 21:33:51 +02:00
Thibaud Guillaume-Gentil
9e578ce85a Version 0.6.3 2011-09-01 21:31:21 +02:00
Thibaud Guillaume-Gentil
5c1fb285e8 Merge branch 'master' into stdin
Conflicts:
	lib/guard/listener.rb
2011-09-01 21:28:03 +02:00
Thibaud Guillaume-Gentil
8040fe65a7 Fix travis png link 2011-09-01 21:25:45 +02:00
Thibaud Guillaume-Gentil
74b3445549 Fix travis png link 2011-09-01 21:24:53 +02:00
Rémy Coutable
d258db6282 2 new features added to changelog 2011-09-01 15:45:11 +03:00
Rémy Coutable
0d3acdf947 Merge pull request #130 from ianwhite/master
Adds ignore_paths option to DSL [#104] [#129]
2011-09-01 05:42:17 -07:00
Ian White
d5b4c4ede7 Words for ignore_paths method 2011-09-01 12:43:02 +01:00
Ian White
54773af2b0 Adds ignore_paths to DSL 2011-09-01 12:30:34 +01:00
Ian White
c74c9c9bf9 Add ignore_paths option to listener 2011-09-01 10:19:20 +01:00
Thibaud Guillaume-Gentil
c92290526b Merge pull request #128 from tpope/user_config
Add a user guard config
2011-08-31 01:41:21 -07:00
Tim Pope
b59d6ac07b Add a user guard config
Users can add additional settings to ~/.guard.rb that augment the
existing Guardfile.
2011-08-31 04:07:42 -04:00
Thibaud Guillaume-Gentil
4ac556bfe3 Back to '--format doc' for guard-rspec 2011-08-30 21:21:09 +02:00
Thibaud Guillaume-Gentil
5de94ccbcb Merge branch 'master' into stdin
Conflicts:
	Guardfile
	lib/guard.rb
2011-08-30 21:16:30 +02:00
Thibaud Guillaume-Gentil
63c3015532 Merge branch 'stdin' of github.com:guard/guard into stdin
Conflicts:
	lib/guard.rb
2011-08-30 21:14:22 +02:00
Thibaud Guillaume-Gentil
3717179591 Refactor new interactor/listener mechanic now it's
look pretty.
Specs still need some love :)
2011-08-30 21:13:51 +02:00
Thibaud Guillaume-Gentil
742b9fe3ff Add sleep to not eat 100% cpu :) 2011-08-30 10:48:29 +02:00
Thibaud Guillaume-Gentil
e752dbe1c1 Maybe first working version (but still a work in progress) 2011-08-29 21:25:58 +02:00
Darren Pearce
02c4465940 added fetch to fix failing tests 2011-08-26 23:42:31 -06:00
Darren Pearce
f8960ec783 converted sha1 check in favour of checking cached file modified timestamps 2011-08-26 11:05:16 -06:00
Darren Pearce
8da8f6a33d added optional support for watching deletions and with that comes file moves 2011-08-23 10:07:23 -06:00
Darren Pearce
e795ab29f5 inital idea for deleted files 2011-08-19 14:53:48 -06:00
Rémy Coutable
b144514b06 Formatting [ci skip] 2011-08-17 17:10:14 +03:00
Thibaud Guillaume-Gentil
8ff259b249 Version 0.6.2 2011-08-17 16:07:23 +02:00
Rémy Coutable
537f5cb00a Update CHANGELOG for 0.6.2! [ci skip] 2011-08-17 17:05:11 +03:00
Michael Kessler
1fd6f2d7be Explain the growl/growl_notify differences. 2011-08-17 14:57:20 +02:00
Michael Kessler
0e1564ef3b Revert "remove growl support completely"
This reverts commit 7f87411189.
2011-08-17 14:27:40 +02:00
Rémy Coutable
9710229f7c Use doc formatter again (instead of Fuubar) 2011-08-17 10:46:13 +02:00
Rémy Coutable
4fd1db3fb7 Use doc formatter again (instead of Fuubar) 2011-08-17 10:45:54 +02:00
Rémy Coutable
652c3d8661 Merge branch 'master' into hook
Conflicts:
	lib/guard.rb
	lib/guard/dsl.rb
	spec/guard/dsl_spec.rb
	spec/guard_spec.rb
2011-08-17 10:45:20 +02:00
Thibaud Guillaume-Gentil
af408ceb65 Add thread in guard interactor 2011-08-17 10:07:30 +02:00
Rémy Coutable
dc2ab97d23 Pass the group in the options hash instead of a new parameter in the Guard::Guard.initialize method! 2011-08-17 10:04:42 +02:00
Rémy Coutable
32904356cb Merge branch 'master' into hook 2011-08-17 01:47:25 +02:00
Rémy Coutable
563b020d4f Oops (worked on 1.9.2 only) :) 2011-08-17 01:36:44 +02:00
Rémy Coutable
eb347ee266 Merge branch 'master' into hook
Conflicts:
	Gemfile
	Guardfile
	README.markdown
	Rakefile
	lib/guard.rb
	lib/guard/dsl.rb
	lib/guard/interactor.rb
	lib/guard/listener.rb
	lib/guard/ui.rb
	lib/guard/watcher.rb
	spec/guard/dsl_spec.rb
	spec/guard/notifier_spec.rb
2011-08-17 01:34:27 +02:00
Rémy Coutable
1c59a7825d Merge branch 'master' of github.com:guard/guard 2011-08-17 00:40:05 +02:00
Rémy Coutable
dd86402109 Add @groups attributes to keep track of the groups, ordered as in the Guardfile 2011-08-17 00:39:45 +02:00
Rémy Coutable
6f7ce6feb7 On a guard's initialization, pass the group in which it's been declared in the Guardfile, pass group's name on Guard.add_guard and thus in the Dsl 2011-08-17 00:36:02 +02:00
Rémy Coutable
e6dc507de7 Rename manual source file 2011-08-17 00:27:22 +02:00
Rémy Coutable
24f0d21f71 Try to reduce specs execution time by providing an option for the "rest delay" before & after starting / stopping the listener. 2011-08-17 00:27:02 +02:00
Rémy Coutable
0b945f10ec Ensure that scoped groups and group name are symbolized before checking for inclusion.
This is useful since Dsl.evaluate_guardfile can be called directly (hence, options are note passed by Thor, which stringify options).
2011-08-17 00:26:03 +02:00
Thibaud Guillaume-Gentil
d6e27fe334 Merge branch 'master' into stdin
Conflicts:
	Guardfile
2011-08-16 09:08:05 +02:00
Thibaud Guillaume-Gentil
8144a43726 Merge branch 'master' of github.com:guard/guard 2011-08-16 09:06:23 +02:00
Thibaud Guillaume-Gentil
d268f236bf Version 0.6.1 2011-08-15 09:53:10 +02:00
Rémy Coutable
1ee70fbe2e Updates manual 2011-08-15 09:49:21 +02:00
Rémy Coutable
59bb373fa7 Update CHANGELOG 2011-08-15 09:19:32 +02:00
Rémy Coutable
b44a91bfef Merge branch 'master' of github.com:guard/guard 2011-08-15 09:15:34 +02:00
Rémy Coutable
ec7ba3cda1 Use fuubar formatter 2011-08-15 09:15:29 +02:00
Rémy Coutable
52cf570245 Merge pull request #120 from mordaroso/ego
Fix re-evaluating Guardfile
2011-08-14 11:29:02 -07:00
Rémy Coutable
e9cef8809b [ci skip] Added a link to the screencast on Guard by Ryan Bates (idea taken from the guard-process's README!). :) 2011-08-14 21:25:57 +03:00
mordaroso
820501bf15 remove guardfile_contents when re-evaluating so that the Guardfile gets reloaded correctly 2011-08-14 18:41:05 +02:00
Michael Kessler
e375d2f327 Explain what happens with guards without a group. 2011-08-14 14:17:48 +02:00
Michael Kessler
fd405b3131 Merge pull request #119 from ches/guard
---

After all my talking in #118, I thought I should fix it :-)
2011-08-14 13:22:26 +02:00
Ches Martin
ca2a4fa1be Don't fail specs because of blasted vim swapfiles 2011-08-14 15:22:07 +07:00
Ches Martin
87375c7a1f evaluate_guardfile uses all groups if none specified. Fixes #118 2011-08-14 15:16:16 +07:00
Thibaud Guillaume-Gentil
e7c23ff78d Add gem 'win32console' note in the README 2011-08-13 16:50:27 +02:00
Thibaud Guillaume-Gentil
2c81e5b9bd Version 0.6.0 2011-08-13 16:47:23 +02:00
Thibaud Guillaume-Gentil
573ddf9d9d First trial to remove Posix Signals interaction 2011-08-13 16:43:32 +02:00
Thibaud Guillaume-Gentil
3c326611e9 Merge pull request #99 from johnbintz/also-use-growl_notify
Option to also use growl_notify gem
2011-08-13 07:42:08 -07:00
Thibaud Guillaume-Gentil
f45f598029 Merge pull request #116 from capitalthought/master
Polling#watch_change should use listener directory, not Dir.pwd
2011-08-12 12:35:28 -07:00
Rob Eanes
e846068e89 Polling#watch_change should use listener directory, not Dir.pwd 2011-08-12 10:03:06 -05:00
Rémy Coutable
63ca5f0b70 [ci skip] Added missing documentation for options and for win32console! 2011-08-11 13:27:41 +03:00
Rémy Coutable
118e8ff167 Added guard-ronn (to build manual automatically). 2011-08-11 12:10:44 +02:00
Rémy Coutable
bcbcf61390 Update CHANGELOG 2011-08-11 12:09:30 +02:00
Rémy Coutable
95b86a38c7 Fix specs (hopefully) 2011-08-11 12:09:24 +02:00
Rémy Coutable
a58e5d8fa5 Merge pull request #115 from zonque/master
[Linux] Add ':transient => true' to default libnotify options (make the notices vanish after a few seconds).
2011-08-11 03:02:33 -07:00
Daniel Mack
3663687ad6 Add ':transient => true' to default libnotify options
This is a new feature in libnotify causing transitions to vanish after
they've been displayed.
2011-08-11 11:24:14 +02:00
Rémy Coutable
134a476f03 Build against master and hook branch, and ping IRC room when build finishes. 2011-08-10 01:17:11 +02:00
Rémy Coutable
7da0cd2b0d Update manual with latest changes. [ci skip] 2011-08-10 01:16:31 +02:00
Thibaud Guillaume-Gentil
ca4b808b86 Update CHANGELOG 2011-08-09 15:18:45 +02:00
Thibaud Guillaume-Gentil
db730eece5 Merge pull request #112 from docwhat/guard-list
Add list command to CLI
2011-08-09 06:15:24 -07:00
Christian Höltje
0054af64ed Mention 'guard list' in README 2011-08-09 09:08:53 -04:00
Christian Höltje
091ecf3322 Add list command to CLI
This adds a list command, that shows all available
guard gems.

https://github.com/guard/guard/issues/111
2011-08-08 20:11:22 -04:00
Michael Kessler
9175b33da4 Merge branch 'master' of https://github.com/uk-ar/guard into uk-ar-master
Conflicts:
	CHANGELOG.md
	lib/guard.rb
	lib/guard/cli.rb
2011-08-05 14:37:08 +02:00
Michael Kessler
14a859d728 Fix spec for Guard.get_guard_class 2011-08-05 10:23:54 +02:00
Rémy Coutable
f0bcf8509c Merge pull request #108 from dnagir/patch-2
Show error when loading guard fails (solves problem when you have no clue
2011-08-04 13:17:06 -07:00
Michael Kessler
0dca1405aa Merge pull request #109 from NickClark/master
Fix an unmatched quote in readme
2011-08-04 00:13:03 -07:00
Nicholas A Clark
0c9cf69980 Fix unmatched quotes in readme 2011-08-03 22:15:27 -03:00
Dmytrii Nagirniak
0c15b442f8 show error when loading guard fails (solves problem when you have no clue what's wrong) 2011-08-02 20:49:15 +10:00
Rémy Coutable
a1d798e141 Edited CHANGELOG.md via GitHub 2011-08-02 13:20:10 +03:00
Rémy Coutable
de97793e86 Edited CHANGELOG.md via GitHub 2011-08-02 13:19:16 +03:00
Rémy Coutable
57da06f2ec Merge pull request #107 from dnagir/patch-1
Small spelling fix
2011-08-02 03:18:01 -07:00
Dmytrii Nagirniak
ed6a93ac74 small spelling fix 2011-08-02 20:03:15 +10:00
Rémy Coutable
b34cd1acfb Based on @ttilley explanation in https://github.com/thibaudgg/rb-fsevent/issues/17, signal handlers registration should happen before any subprocess creation (fsevent_watch for instance) to be properly catches by the subprocess.
Note that in the case when guard is run via bundler, this –quoting @ttilley– "would make this an unsolvable problem" (isn't it dramatic?! ;)).
2011-07-30 23:58:53 +02:00
Rémy Coutable
6b30238735 Use #[] instead of #has_key? since it is more flexible (accept symbol as key for actual string keys in the hash). 2011-07-29 09:05:40 +02:00
Rémy Coutable
a6d0dab45c Use the SSL version of the Travis build image 2011-07-29 00:30:07 +02:00
Rémy Coutable
38067f447f Add some specs for Guard.start (just to ensure core methods are well called…) 2011-07-29 00:23:20 +02:00
Rémy Coutable
1481604411 Rename Guard::Dsl.revaluate_guardfile to Guard::Dsl.reevaludate_guardfile 2011-07-29 00:22:53 +02:00
Rémy Coutable
48057cb6c8 New CLI options: watchdir and guardfile thanks to @nestegg! 2011-07-28 23:59:31 +02:00
Rémy Coutable
a366e0f8dd Merge branch 'nestegg' of git://github.com/nestegg/guard into nestegg-watchdir_and_guardfile_cli_options 2011-07-28 22:44:03 +02:00
Rémy Coutable
0176a0c5cc Merge branch 'master' of github.com:guard/guard 2011-07-25 23:31:24 +02:00
Rémy Coutable
9b74ddbfdb Update CHANGELOG 2011-07-25 23:30:54 +02:00
Rémy Coutable
9b711ea7fb Merge branch 'master' of https://github.com/stereobooster/guard into stereobooster-master
Conflicts:
	lib/guard/ui.rb
2011-07-25 23:28:54 +02:00
Michael Kessler
e376acc05a Add GitHub home of @bronson to the CHANGELOG. 2011-07-23 17:49:19 +02:00
Doug Renn
8e129c585a Add a command line option for directory to watch 2011-07-22 16:10:36 -06:00
Doug Renn
e3bbdbfa42 Add a command line option to specify the guardfile 2011-07-22 15:27:03 -06:00
Doug Renn
ee8489fb83 Don't assume watched directory, use value from listener 2011-07-22 11:57:49 -06:00
Rémy Coutable
baa1817b3a Update Changelog 2011-07-21 02:24:15 +02:00
Rémy Coutable
7bfe5a3259 Fix Linux spec 2011-07-21 02:24:03 +02:00
Rémy Coutable
508aad1787 I don't like the failed specs to always come back!
Use the RSpec documentation formatter & tuned the spec:portability task to tests against the same Ruby version tested on Travis CI
2011-07-21 01:42:32 +02:00
Rémy Coutable
06be2107af Dir.glob now ignores files that don't need to be watched
By default, we don't watch ., .., .bundle, .git (this is HUGE), log, tmp and vendor (this is also HUGE). Also don't append '/' to the dir given to Guard::Listener#potentially_modified_files, the method now handles it internally.

In my case, Guard::Listener#potentially_modified_files was taking ~56 seconds (in a big Rails project), it takes now... less than 1 second.

Enjoy.
2011-07-21 01:40:40 +02:00
Rémy Coutable
9cc1cf64d1 Use Guard::Listener#worker as much as possible 2011-07-21 01:30:22 +02:00
Rémy Coutable
802d134165 Don't add attr_reader and attr_writer when unecessary
Rename Guard::Listener#relativate_paths to Guard::Listener#relativize_paths
2011-07-21 01:29:05 +02:00
Rémy Coutable
8a1ca41626 Moved Guard::Listener#update_last_event inside Guard::Listener#modified_files
Since the pattern was to always call Guard::Listener#update_last_event after Guard::Listener#modified_files.
2011-07-21 01:25:06 +02:00
Rémy Coutable
a318e03ad1 Added a debug message when running run_on_change
So the debug mode is a little more useful...

Also added timestamp in debug print
2011-07-21 01:21:04 +02:00
Thibaud Guillaume-Gentil
76c2977b67 Version 0.5.1 2011-07-15 08:35:12 +02:00
Thibaud Guillaume-Gentil
be8cd87be9 Prevents notification on revaluate_guardfile spec 2011-07-15 08:33:13 +02:00
Thibaud Guillaume-Gentil
694664ced8 Closes #100 2011-07-15 08:32:34 +02:00
Rémy Coutable
8622ba5f94 Merge pull request #102 from bronson/patch-1
Fix undefined method `empty?' for nil:NilClass error
2011-07-14 13:33:39 -07:00
Scott Bronson
8d27fff74d Fix undefined method `empty?' for nil:NilClass error 2011-07-14 11:42:26 -07:00
Rémy Coutable
18b741ed4e Merge pull request #101 from bquorning/patch-1
Grammar fix
2011-07-12 04:55:29 -07:00
Benjamin Quorning
13e325ca52 Grammar fix 2011-07-12 04:06:55 -07:00
John Bintz
7f87411189 remove growl support completely 2011-07-06 15:45:20 -04:00
yuuki arisawa
8d02eec38c Add support not to change files when dry run. 2011-07-02 19:16:06 +09:00
Thibaud Guillaume-Gentil
649920b7f0 Version 0.5.0 2011-07-02 10:23:18 +02:00
Thibaud Guillaume-Gentil
e7cc14152d Merge branch 'master' of github.com:guard/guard 2011-07-02 10:01:54 +02:00
Thibaud Guillaume-Gentil
ba0b84838d Integrated Guard::Ego inside Guard, oh yeah! 2011-07-02 10:01:45 +02:00
John Bintz
facd4f2a0b force use of Guard application name when using growl_notify 2011-07-01 11:52:24 -04:00
Michael Kessler
d78ecb45fb Change inotify event flags (Closes #12).
There have been some issues with Guard in Linux, which all lead back
to the selection of the proper inotify flags. It seems that almost each
editors behaves different when it comes to save a file. @jeffutter
started to collect information about these events, which are now listed
in the Guard wiki:

https://github.com/guard/guard/wiki/Analysis-of-inotify-events-for-different-editors

If you miss your favorite editor, please add your analysis to the list.
2011-06-30 09:23:12 +02:00
John Bintz
8917682cdf update README 2011-06-28 16:58:23 -04:00
John Bintz
b13255a9f8 more test and support for growl_notify 2011-06-28 16:53:23 -04:00
John Bintz
e53036ad05 add support for growl_notify 2011-06-28 16:15:14 -04:00
yuuki arisawa
847b2b8740 Added some specs,and some lines in README/CHANGELOG for dry-run option.
And added support for Kernel.#` and %x literal.
2011-06-28 22:13:24 +09:00
yuuki arisawa
49d14b1360 Added dry_run option for Guardfile debug 2011-06-26 00:13:26 +09:00
Rémy Coutable
59b1ea2c96 Added @capotej to the CHANGELOG 2011-06-23 18:02:49 +02:00
Rémy Coutable
f394fef7eb Merge branch 'master' of https://github.com/capotej/guard into capotej-master 2011-06-23 18:01:32 +02:00
Julio Capote
268d55a145 changelog 2011-06-23 08:54:27 -07:00
Julio Capote
05e55545b7 passing specs for watcher exception handling 2011-06-23 08:52:02 -07:00
Thibaud Guillaume-Gentil
5923cef530 Merge pull request #93 from capotej/master
Better exception handling
2011-06-23 00:07:09 -07:00
Julio Capote
8e91b5f737 Forgot to join the backtrace array with newlines for better output 2011-06-22 17:00:15 -07:00
Julio Capote
673fa0eebc Better exception handling
This shows the backtrace when there is a problem with a watch action, makes for easier watch debugging
2011-06-22 16:47:12 -07:00
Thibaud Guillaume-Gentil
8c5be4536b Merge pull request #92 from tpope/hidden_home_config_file
Make home Guardfile hidden
2011-06-22 12:22:18 -07:00
Tim Pope
524af462d9 Make home Guardfile hidden 2011-06-22 10:54:50 -04:00
Rémy Coutable
c2b2c15a80 Updated CHANGELOG with latest changes 2011-06-22 10:44:45 +02:00
Rémy Coutable
d3f7d8d6a4 Merge pull request #91 from johnbintz/show-guards-in-guardfile
Show Guards in Guardfile
2011-06-22 01:40:44 -07:00
John Bintz
7ba4819d3b documentation and man page updates 2011-06-21 11:00:00 -04:00
John Bintz
72f31c9eba inspect values rather than simply print them, so that strings appear quoted 2011-06-21 10:34:11 -04:00
John Bintz
c3ddeac36f remove empty spec 2011-06-21 10:33:21 -04:00
John Bintz
ae320fe003 remove useless method 2011-06-21 09:58:02 -04:00
John Bintz
ef79b5e720 use Guard::UI instead of straight puts 2011-06-21 09:55:04 -04:00
John Bintz
aa3010af91 show the guards defined in the Guardfile with 'guard show' or 'guard -T' 2011-06-21 09:54:52 -04:00
Yann Lugrin
a6f3ebebfa Linux listener work more like others listeners
Now use modified_file method from listener api to ensure similar
behavior to the other platform. This change avoid unwanted behavior
when multiple events are raised for a file (like running tests more
one times).
2011-06-20 16:09:47 +02:00
stereobooster
2b6d524cfb add const ANSI_ESCAPE_BRIGHT = "1" 2011-06-20 05:33:08 -07:00
stereobooster
3464d59cb7 more color support for UI 2011-06-20 05:26:44 -07:00
stereobooster
e4514ab298 Fix issue #12. Test it without win32console. 2011-06-20 03:13:28 -07:00
Yann Lugrin
043d285894 don't return directories when requesting files 2011-06-20 10:08:32 +02:00
Rémy Coutable
f56db548e7 Don't gzip the man page for now. 2011-06-19 22:04:20 +02:00
Rémy Coutable
5f8880f270 Guard has now a (basic) man page! :) 2011-06-19 21:55:28 +02:00
Rémy Coutable
63c61e2470 Improved the consistency of the CHANGELOG. 2011-06-19 20:56:11 +02:00
Rémy Coutable
dd7eb7d505 Added last changes to CHANGELOG 2011-06-19 20:45:31 +02:00
Rémy Coutable
02f404e85f Added a fake guard that simply breaks (for tests purpose) 2011-06-19 20:25:52 +02:00
Rémy Coutable
20dd08e977 Write exception details using UI.error, and UI.error will now output "ERROR:" in red! 2011-06-19 20:24:47 +02:00
Rémy Coutable
5573e0d221 Merge branch 'dont_swallow_error_on_running_task' of https://github.com/mcmire/guard into mcmire-dont_swallow_error_on_running_task 2011-06-19 19:49:19 +02:00
Rémy Coutable
c8002ac2de Making the README more awesome 2011-06-19 12:36:44 +02:00
Rémy Coutable
d7557659dd Improved README 2011-06-19 12:23:34 +02:00
Rémy Coutable
709f63754e Cleaned/improved description of CLI options 2011-06-19 12:22:32 +02:00
Rémy Coutable
5996951685 Really? "return"? 2011-06-19 12:22:09 +02:00
Rémy Coutable
bbe42f9d23 Added informations on the --debug option! 2011-06-19 02:54:17 -07:00
Elliot Winkler
b41f31e420 If running a task for a guard and it borks, don't swallow the error but print the backtrace 2011-06-18 16:30:00 -06:00
Ricardo Markiewicz
d51b457b71 Improve INotify support on linux (fixes #79 #82)
Improve usage with several text editors that writes to temporal
files and then move over the original filename instead of write
files directly. Tested with GEdit, Nano, vim (with 'set backup'
and 'set nobackup') and emacs.
2011-06-17 18:48:35 +02:00
Thibaud Guillaume-Gentil
975444bda3 Merge pull request #86 from stereobooster/master
Fix issue 12
2011-06-17 00:01:01 -07:00
slavic
61b0a7aa05 Fix issue #12. Specs don't work. Fails beacause of ".git/index" 2011-06-17 00:36:16 +03:00
slavic
a0245de6cd Merge commit '2ff6a2229aabaa63444511cc5f0b0c5e31acd8ef' 2011-06-17 00:29:02 +03:00
Thibaud Guillaume-Gentil
2ff6a2229a Merge pull request #84 from etehtsea/rbconfig-migration
Use RbConfig instead of obsolete and deprecated Config.
2011-06-16 06:30:24 -07:00
Konstantin Shabanov
668e0f4d85 Use RbConfig instead of obsolete and deprecated Config. 2011-06-16 18:14:51 +07:00
Yann Lugrin
ca7b98099c Watching dotfile (hidden files under unix) fix #80 2011-06-15 18:02:32 +02:00
Michael Kessler
8f7034b8a0 Make sure questions go to the Google group/IRC and issues to GitHub. 2011-06-10 23:14:34 +02:00
Rémy Coutable
a01a6b6fd2 Updated CHANGELOG (added 0.4.2 changes). 2011-06-08 12:26:16 +02:00
Rémy Coutable
21f5a41f88 Actually clear the terminal before the setup (don't clear setup messages). 2011-06-08 12:25:44 +02:00
Rémy Coutable
c14460f86e Updated CHANGELOG 2011-06-08 12:18:00 +02:00
Rémy Coutable
ddc6f26b91 Clear the terminal on start when the :clear option is given 2011-06-08 12:16:36 +02:00
Thibaud Guillaume-Gentil
952d4b4b81 Version 0.4.2 2011-06-08 09:12:06 +02:00
Thibaud Guillaume-Gentil
a2b3927a2e Fixed Guard::Version in ruby 1.8.7 2011-06-08 09:10:26 +02:00
Rémy Coutable
71e51706b7 Merge pull request #78 from fnichol/patch-1
Fix CHANGELOG @mislav link.
2011-06-07 14:09:29 -07:00
Fletcher Nichol
511a9218b1 Fix CHANGELOG @mislav link. 2011-06-07 13:45:23 -07:00
Thibaud Guillaume-Gentil
1681bc8b45 Version 0.4.1 2011-06-07 21:27:19 +02:00
Thibaud Guillaume-Gentil
a058a8b5f3 Updated CHANGELOG 2011-06-07 21:27:09 +02:00
Thibaud Guillaume-Gentil
7360e4a8cd Merge branch 'enhancements' of https://github.com/mislav/guard into mislav-enhancements 2011-06-07 21:16:28 +02:00
Thibaud Guillaume-Gentil
3fc02dc344 Updated CHANGELOG 2011-06-07 21:15:33 +02:00
Thibaud Guillaume-Gentil
a3c8bbd860 Updated installation doc 2011-06-07 21:10:49 +02:00
Yann Lugrin
da1800f18a .turn_on can't work for other platform, stub .enabled? instead 2011-06-07 19:13:48 +02:00
Yann Lugrin
abae416bb0 add Notifu to windows documentation part 2011-06-07 18:05:11 +02:00
Yann Lugrin
d41e9fe7fe don't use system notification library if could not be required 2011-06-07 17:58:02 +02:00
Yann Lugrin
e2b13d2dc5 bad use of around rspec hook (tests passes every times even if should fail) 2011-06-07 17:35:49 +02:00
Mislav Marohnić
2997ed6962 skip version comparison if Gem::Version is not available
This decouples Guard from RubyGems
2011-06-07 15:46:30 +02:00
Mislav Marohnić
17a654b171 refactor get_guard_class to first try the constant and fallback to require
This enables defining inline guard handlers to override ones present in gems,
e.g. you could define an inline Guard::RSpec handler and have guard use that
instead of first trying to load 'guard/rspec' from the 'guard-rspec' gem.

Also gets rid of the ill-named method `try_to_load_gem`. Handlers are simply
found in the $LOAD_PATH and don't have to necessarily come from gems.
2011-06-07 15:42:45 +02:00
Mislav Marohnić
9d63f1a77f include CHANGELOG in the gem 2011-06-07 15:42:44 +02:00
Mislav Marohnić
29f671b64a change gem "homepage" property to the GitHub project 2011-06-07 15:42:44 +02:00
Mislav Marohnić
03aa0b0df8 gemspec: avoid adding the "lib/" directory to load path
Simply reading the gemspec shouldn't activate the gem by adding its
files to the load path.
2011-06-07 15:42:44 +02:00
Mislav Marohnić
d5a5fa139a fix grammar in gem summary & description 2011-06-07 15:41:52 +02:00
Thibaud Guillaume-Gentil
ff6629f6f1 Version 0.4.0 2011-06-05 20:53:36 +02:00
Thibaud Guillaume-Gentil
ffcff59176 Added 'rake' in Gemfile for travis-ci 2011-06-04 21:38:25 +02:00
Thibaud Guillaume-Gentil
deec4135a9 Updated version deps for rb-fsevent & rb-inotify 2011-06-04 21:38:09 +02:00
Thibaud Guillaume-Gentil
5808a3cf23 Removed merged code commented 2011-06-02 23:58:07 +02:00
Rémy Coutable
fb5caf43f6 Awesome CHANGELOG.md thanks to @pcreux. 2011-06-01 17:08:03 -07:00
Rémy Coutable
e7c5def15d Merge pull request #74 from pcreux/master
CHANGELOG with link definitions.
2011-06-01 16:59:40 -07:00
Philippe Creux
7e375b43a6 CHANGELOG is now cleaner than ever. 2011-06-01 16:36:59 -07:00
Rémy Coutable
cb5843aa47 In Ruby < 1.9, Symbol#downcase doesn't exist! 2011-06-02 00:40:37 +02:00
Rémy Coutable
3d52d51d36 Added last pull-request #73 to the Changelog, thanks to @johnbintz! 2011-06-01 13:30:38 -07:00
Rémy Coutable
53adfc9e94 Merge pull request #73 from johnbintz/symbols-for-group-names
Allow symbols for group names
2011-06-01 12:07:12 -07:00
John Bintz
b0d30900fb add additional spec to test string-only guard group names 2011-06-01 15:00:01 -04:00
John Bintz
087f51085f allow symbols for group names 2011-06-01 14:17:31 -04:00
Thibaud Guillaume-Gentil
048ed9c94c Updated Google group & irc text 2011-06-01 17:13:20 +02:00
Thibaud Guillaume-Gentil
d2af0503ca Added Google group & irc links in Readme 2011-06-01 17:10:54 +02:00
Michael Kessler
217069bbc6 Add wiki link on how to configure signal keyboard shortcuts. 2011-05-31 14:28:59 +02:00
Michael Kessler
1bcfdfd3ad Make the notifier spec more robust on notification library loading.
I really love travis-ci, it makes my life easier AND harder.
2011-05-30 17:20:39 +02:00
Michael Kessler
320706e2f5 Merge pull request #51 from indirect/guard
---

This change allows guard plugins (like guard-rspec) to pass options (like :priority) up to the Growl notifier. With this change, things like indirect/rspec-guard@d2f01d69a7 are possible, and the growl notification colors can be customized depending on the outcome of the spec run.

Conflicts:
	lib/guard/notifier.rb
2011-05-30 16:45:15 +02:00
Michael Kessler
2bebca2fcf Make the notifier spec test all platforms on any platform. 2011-05-30 16:04:02 +02:00
Thibaud Guillaume-Gentil
ac93449be4 Fixed files in gemspec 2011-05-29 10:59:56 +02:00
Thibaud Guillaume-Gentil
527e42c8e1 Version 0.4.0.rc 2011-05-28 20:24:57 +02:00
Rémy Coutable
097e4dda68 Almost forgot the "Refactor listeners to work as a library" pull-request! :) Ready for release... 2011-05-28 20:18:48 +02:00
Rémy Coutable
0e31d3fece Tiny presentation change in Changelog 2011-05-28 19:46:52 +02:00
Rémy Coutable
502d1e6197 Removing a superfluous parenthesis in Changelog 2011-05-28 19:41:54 +02:00
Rémy Coutable
96e7c43d25 Merge branch 'master' of github.com:guard/guard
Conflicts:
	README.md
2011-05-28 19:39:48 +02:00
Rémy Coutable
11c3e0b782 Keeping the Changelog up to date and improved the Readme 2011-05-28 19:39:18 +02:00
Rémy Coutable
f7acec3141 Keeping the Changelog up to date and improved the Readme 2011-05-28 19:33:51 +02:00
Thibaud Guillaume-Gentil
42e4413cf2 Fixed guard init 2011-05-28 18:18:45 +02:00
Thibaud Guillaume-Gentil
85ed0f8217 Merge branch 'master' of github.com:guard/guard 2011-05-28 17:53:27 +02:00
Thibaud Guillaume-Gentil
1747f66128 Merge branch 'user_guardfile' of https://github.com/hashrocket/guard into hashrocket-user_guardfile
Conflicts:
	lib/guard/dsl.rb
	spec/guard/dsl_spec.rb
2011-05-28 17:52:50 +02:00
Thibaud Guillaume-Gentil
973aba4375 Merge pull request #64 from stereobooster/master
Windows notifications
2011-05-28 08:32:45 -07:00
Thibaud Guillaume-Gentil
6a77f01645 Merge branch 'master' of https://github.com/niklas/guard into niklas-master
Conflicts:
	lib/guard/listener.rb
	spec/guard/listeners/linux_spec.rb
2011-05-28 17:15:09 +02:00
Thibaud Guillaume-Gentil
1628a1f01d fix for resolving the digest module (again) 2011-05-28 16:50:16 +02:00
Thibaud Guillaume-Gentil
1a883dcf2c Merge branch 'master' of github.com:guard/guard 2011-05-28 16:47:43 +02:00
Thibaud Guillaume-Gentil
8f68778927 Only check sha1_checksum when file mtime.to_i == last_event.to_i (so touching file to fire guard is working again) 2011-05-28 16:47:35 +02:00
Rémy Coutable
36d55d60ec Added new features to Changelog 2011-05-27 18:02:25 +02:00
Rémy Coutable
72734e1587 Fixed a bug preventing from using "guard :test" in Guardfile! 2011-05-27 17:56:46 +02:00
Rémy Coutable
b471405f4d Merge branch 'master' of https://github.com/anithri/guard into anithri-master-55
Conflicts:
	lib/guard/notifier.rb
	spec/guard/dsl_spec.rb
	spec/guard/listeners/polling_spec.rb
	spec/guard/notifier_spec.rb
2011-05-27 17:56:18 +02:00
Thibaud Guillaume-Gentil
06c3cda93c Merge pull request #69 from tinogomes/patch-1
Edited README.markdown via GitHub
2011-05-27 05:18:54 -07:00
Celestino Gomes
af7dbb9302 Edited README.markdown via GitHub 2011-05-27 05:13:39 -07:00
Thibaud Guillaume-Gentil
b1231753a1 Merge pull request #68 from johnbintz/digest-fix
Fix for resolving the Digest module
2011-05-26 23:23:28 -07:00
Aaron Kalin and Veezus Kreist
a51afdf0e3 Outdent private statement 2011-05-25 14:08:11 -05:00
Aaron Kalin and Veezus Kreist
9928f80c76 Fix guardfile_path spec for Windows support 2011-05-25 13:32:56 -05:00
Aaron Kalin and Veezus Kreist
b69aa7677c Update README regarding Guardfile location 2011-05-25 13:23:08 -05:00
Aaron Kalin and Veezus Kreist
add80d2831 Conform to project standards 2011-05-25 13:23:02 -05:00
Joshua Davey and Veezus Kreist
debdecbbd7 Allow user-based Guardfiles 2011-05-24 16:44:24 -05:00
Thibaud Guillaume-Gentil
ce2a5c5980 Merge pull request #66 from johnbintz/better-class-name-generation
Support for dashes in guard names
2011-05-24 01:08:29 -07:00
John Bintz
307d13a517 fix for resolving the digest module 2011-05-23 21:36:51 -04:00
John Bintz
310bc5b644 support for dashes in guard names 2011-05-23 19:07:12 -04:00
Yann Lugrin
492b5a4114 require guard/ui because notifier can be required without full guard 2011-05-23 22:35:37 +02:00
slavic
ad3def39e2 Changes connected with new version of rb-notifu 2011-05-22 11:38:54 +03:00
slavic
18d2db9ff1 windows notifiaction works (tested with guard-bundler) 2011-05-22 00:47:02 +03:00
slavic
02448b8575 windows notifiaction 2011-05-21 02:19:42 +03:00
slavic
51750c6d1a Merge commit '284747befbc4695577d8cdc9f9f912064335ced4' 2011-05-21 02:17:16 +03:00
Thibaud Guillaume-Gentil
284747befb Updated travis-ci png 2011-05-17 06:00:45 -07:00
Niklas Hofer
b12769d2bf can give path and options to Listener.select_and_init 2011-05-15 21:45:30 +02:00
Niklas Hofer
a3cf121111 can disable relativation of paths 2011-05-15 21:45:30 +02:00
Niklas Hofer
2f0870abfc refactor Polling Listener to catch deleted and moved files 2011-05-15 21:45:30 +02:00
Niklas Hofer
7b95eeb275 must not use touch on Linux 2011-05-15 21:45:30 +02:00
Niklas Hofer
bc740d725f create shared examples all listeners should behave like 2011-05-15 21:45:30 +02:00
Niklas Hofer
9c44f89a61 can specify directory to listen to, still defaulting to pwd 2011-05-15 21:45:30 +02:00
Thibaud Guillaume-Gentil
6a0121bcb9 Merge pull request #62 from stereobooster/master
rake specs:portability task for windows
2011-05-15 11:33:15 -07:00
slavic
84bcf671b4 rake specs:portability task for windows 2011-05-15 13:30:30 +03:00
slavic
9a4039d9e1 Merge commit '55946927c2ea0051e18c59fcccb67223c3964100' 2011-05-15 12:45:42 +03:00
Thibaud Guillaume-Gentil
55946927c2 Required growl/libnotify each time in Guard::Notifier.notify for guard-rspec formatter that is called out of guard scope 2011-05-13 22:24:49 +02:00
Thibaud Guillaume-Gentil
e0ca761a25 Removed useless \n when saying 'Bye bye...' 2011-05-13 22:05:58 +02:00
Thibaud Guillaume-Gentil
71d8c7009b Back to ENV['GUARD_NOTIFY"] for listener on/off feature because of guard-rspec formatter. 2011-05-13 21:48:30 +02:00
Thibaud Guillaume-Gentil
66c5a05349 Updated RSpec dev dep (~> 2.6.0) 2011-05-13 21:47:02 +02:00
Michael Kessler
30e4611342 Update the last event time after the rest period. 2011-05-13 12:33:56 +02:00
Michael Kessler
5f0c815256 Cleaning up all specs.
I basically went through all specs and applied the following rules:

* Use `describe` for methods and `context` for contexts.
* All class methods starts with `.` and instance methods with `#`.
* Removed all `it should`, because the specs _have to_.
* Applied a consistant naming on all listener specs.
* Make fixture usage more fail save by giving generous sleep times.
* Make all behaviour description non-technical and easy to understand.

The goal of this excercise was to have a documentation that is easy
readable and describes the behaviour and not the implementation.

Try it out by using the RSpec documentation format!
2011-05-13 11:26:05 +02:00
Michael Kessler
34a77dea1a Use the latest guard-rspec for development. 2011-05-13 11:22:12 +02:00
Michael Kessler
1db2456a45 Avoid result sorting by using =~ for array matching. 2011-05-13 09:01:12 +02:00
Michael Kessler
4e47e3e652 Wait 1 second before continue, so the fixture modifications won't influence the subsequent specs.
This is merely a guess, because all specs pass fine on the local machine but on Travis CI the next
spec that uses the fixtures fails. This might be a problem related to the rounding of the timestamps
in #file_modified?.
2011-05-12 20:27:07 +02:00
Michael Kessler
beb9f92409 Don't rely on the (almost random) order of an Array. 2011-05-12 18:16:32 +02:00
Michael Kessler
d3dab8b962 Remove unnecessary File creation. Specs are now passing on 1.8.7. 2011-05-12 17:01:48 +02:00
Michael Kessler
3a87a4305c Merge pull request #61 from netzpirat/modified_files_spec
Add missing specs for file modification detection (See SHA: 0dcf13d77c
2011-05-12 07:39:59 -07:00
Michael Kessler
a1606b511f Fix sleep typo 2011-05-12 15:03:55 +02:00
Michael Kessler
d36f4c332f Add missing specs for file modification detection (See SHA: 0dcf13d77c) 2011-05-12 15:01:21 +02:00
Scott Parrish
3f15bbc1f0 Merge remote-tracking branch 'upstream/master'
Conflicts:
	lib/guard/notifier.rb
	spec/guard/notifier_spec.rb
2011-05-11 13:19:15 -06:00
Thibaud Guillaume-Gentil
f424854e61 Refactorized notifier enabling/disabling 2011-05-10 21:22:25 +02:00
Thibaud Guillaume-Gentil
0dcf13d77c - Handled quick file (<1s) modification
- Avoid to catch modified files without content modification (sha1 checksum)
(Specs needed)
2011-05-09 09:39:11 +02:00
Thibaud Guillaume-Gentil
f7140f2b1c Removed commented stuff 2011-05-09 09:36:09 +02:00
Thibaud Guillaume-Gentil
ec2de278ad Removed bundler dev dep version (Travis is now using 1.1.pre.4) 2011-05-08 22:08:28 +02:00
Thibaud Guillaume-Gentil
aabf0583b3 Merge branch 'master' of github.com:guard/guard
Conflicts:
	lib/guard.rb
	spec/guard_spec.rb
2011-05-08 22:01:35 +02:00
Thibaud Guillaume-Gentil
29ad7cd8b1 Updated gem dev deps 2011-05-08 21:56:59 +02:00
Thibaud Guillaume-Gentil
1e5ab84b3a Fixed Guard::Notifier (when growl/libnotify not present) 2011-05-08 21:56:46 +02:00
Rémy Coutable
6d5cb96eef Removed unexpected "`" in README 2011-05-07 15:58:19 -07:00
Scott Parrish
6b35e96e8d previous changes were made to Dsl that built on the options hash that was passed to it.
Except the options hash is actually a
    Thor::CoreExt::HashWithIndifferentAccess

so, i reorganized the internal access and storage to read original data from the passed hash, but stores it into a local hash.

No tests changed since no external behavior changed.  All tests passed.

This fixes the issue when the binary is run and results in a
     can't modify frozen hash (RuntimeError)

small change to fix specs to run and always have @@orig_options be locked.
2011-05-07 12:43:24 -06:00
Scott Parrish
2a834e1228 previous changes were made to Dsl that built on the options hash that was passed to it.
Except the options hash is actually a
    Thor::CoreExt::HashWithIndifferentAccess

so, i reorganized the internal access and storage to read original data from the passed hash, but stores it into a local hash.

No tests changed since no external behavior changed.  All tests passed.

This fixes the issue when the binary is run and results in a
     can't modify frozen hash (RuntimeError)
2011-05-07 12:04:59 -06:00
Rémy Coutable
b7137bbf0c Made the README even more gorgeous! 2011-05-07 19:09:43 +02:00
Rémy Coutable
057549a84d Readme cleanup 2011-05-07 19:00:21 +02:00
Rémy Coutable
df98c4ff4c Merge branch 'master' of github.com:guard/guard 2011-05-07 18:48:13 +02:00
Rémy Coutable
d7b0876178 Merge pull request #60 from stereobooster/master
Windows support!
2011-05-07 09:47:18 -07:00
Rémy Coutable
9cfe8d3635 Don't modify a frozen hash. 2011-05-07 18:40:13 +02:00
slavic
29069cdeb7 Update documentation for windows support 2011-05-07 15:18:32 +03:00
slavic
92f81d383a Merge with current guard (commit '5352528530f29d3db523261560ee6920063c85b5') 2011-05-07 15:17:41 +03:00
slavic
5c93116d6f Update documentation for windows support 2011-05-07 13:40:45 +03:00
slavic
fc9c5f4284 Merge windows branch. Tested 1.8.7-p334-i386-mingw32 & 1.9.2-p180-i386-mingw32 2011-05-07 13:18:24 +03:00
Scott Parrish
562c367383 Made slight alteration to Guard::Notifier. pulled out logic into #should_send? to allow for stubbing in tests and added #turn_on to allow more flexibility for when things are or are not sent.
Notifier Specs changed to make pass, expanded and to use new notify strategies.  NOTE mac tests not tested.

i like the @enable as opposed to @disable, should be easy to reverse if necessary though
2011-05-07 00:43:21 -06:00
Scott Parrish
c749a311c3 slight changes to specs 2011-05-06 21:38:53 -06:00
Scott Parrish
526d769e22 update to current upstream 2011-05-06 21:18:42 -06:00
Scott Parrish
8ea296bf8f Guard::Dsl changed massively. overall strategy was to decouple to evaluate_guardfile into "getting the data" and "using the data" parts. this provides the ability to pass a string that contains the contents of a guardfile, or to pass a filename for a guardfile as well as reading the default loc for a guardfile.
Dsl specs changed massivly to support new style of Dsl
2011-05-06 20:53:34 -06:00
Thibaud Guillaume-Gentil
5352528530 Merge branch 'master' of https://github.com/stereobooster/guard into stereobooster-master
Conflicts:
	lib/guard/interactor.rb
2011-05-06 23:35:09 +02:00
Thibaud Guillaume-Gentil
2f94f9e22f Fixed notification option
Only print notification "Install message" once
Added GUARD_NOTIFY=false env variable support
Fixes #28
2011-05-06 23:19:31 +02:00
Thibaud Guillaume-Gentil
fa44ef31bc Moved stop "\n" 2011-05-06 22:58:18 +02:00
Thibaud Guillaume-Gentil
75c1758b22 Updated Guardfile 2011-05-06 22:57:44 +02:00
Thibaud Guillaume-Gentil
d7394e4262 Bye bye 1.8.6 support. 2011-05-06 22:10:38 +02:00
Thibaud Guillaume-Gentil
5740548a51 Kept support of Rubygems < 1.8.0 (for now!) 2011-05-06 21:51:50 +02:00
Thibaud Guillaume-Gentil
a84e46ab48 Oups! 2011-05-06 21:29:22 +02:00
Thibaud Guillaume-Gentil
296837895a Skipped Guard::Notifier spec if growl/libnotify not installed 2011-05-06 21:27:28 +02:00
Thibaud Guillaume-Gentil
660baf7adc Tried to not require rb-inotify (travis-ci issue) 2011-05-06 21:24:00 +02:00
Thibaud Guillaume-Gentil
2da724f5e9 Fixed Rubygems deprecation messages 2011-05-06 21:23:30 +02:00
Thibaud Guillaume-Gentil
f7e9e42dce Skipped Darwin/Linux listener specs if rb-fsevent/rb-inotify not available 2011-05-06 21:15:33 +02:00
Thibaud Guillaume-Gentil
869ed2fa28 Fixed Interactor spec 2011-05-06 21:14:39 +02:00
Thibaud Guillaume-Gentil
d6d9dd9e75 Merge pull request #58 from nicksieger/interactor-module-methods
Extract code from signal handlers into methods
2011-05-06 12:08:45 -07:00
Thibaud Guillaume-Gentil
466f4273f4 Merge pull request #57 from nicksieger/specs-green-on-jruby
Fix spec on JRuby that was failing due to different execution order
2011-05-06 12:04:19 -07:00
Nick Sieger
70c15a7c94 Extract code from signal handlers into methods
This will allow building other mechanisms to interact with Guard, for
example on JRuby, where signal handling tends to be unreliable.
2011-05-06 12:45:47 -05:00
Nick Sieger
5c1e264c39 Fix spec on JRuby that was failing due to different execution order 2011-05-06 12:09:00 -05:00
Rémy Coutable
815a81dd54 Merge pull request #56 from bltavares/master
Changed some loops to positive statements
2011-05-05 23:40:41 -07:00
Bruno Tavares
ed0b086cc5 Removed the unless with multiple conditions. Changed it back to if 2011-05-05 20:52:11 -03:00
Bruno Tavares
cefb872360 Changed some conditions to positive statement 2011-05-05 20:14:58 -03:00
Scott Parrish
f3d49ee81e Made slight alteration to Guard::Notifier. pulled out logic into #should_send? to allow for stubbing in tests and added #turn_on to allow more flexibility for when things are or are not sent.
Notifier Specs changed to make pass, expanded and to use new notify strategies.  NOTE mac tests not tested.
Guard::Dsl changed massively.  overall strategy was to decouple to evaluate_guardfile into "getting the data" and "using the data" parts.  this provides the ability to pass a string that contains the contents of a guardfile, or to pass a filename for a guardfile as well as reading the default loc for a guardfile.
Dsl specs changed massivly to support new style of Dsl
listener/linux_spec changed to add a few :long_running tags and to alter some paths to correct values
listener/polling_spec changed to add a few :long_running tags and to alter some paths to correct values
2011-05-05 03:05:58 -06:00
Rémy Coutable
32cb5d7bf8 Added a "require" in spec that was making specs failing on Travis CI 2011-05-02 15:34:33 +02:00
Rémy Coutable
aeb2c67c17 Typo 2011-05-02 00:07:39 +02:00
slavic
0f7bca7bbd now all specs work 2011-05-01 21:49:16 +03:00
monocle
efdacce491 Added hooks to README 2011-04-30 20:46:41 -07:00
monocle
d798bf05e2 Merge branch hook of github.com:guard/guard into hook 2011-04-30 18:41:27 -07:00
slavic
94e04ec7e0 add support for Windows using rb-fchange. Specs fail because of k32WaitForMultipleObjects blocks all threads 2011-04-30 13:38:57 +03:00
Rémy Coutable
d12a2368b2 Added links to issues in CHANGELOG 2011-04-30 01:47:11 +02:00
Rémy Coutable
8d3ad21cb1 Added .travis.yml file 2011-04-30 01:40:54 +02:00
Rémy Coutable
de42d0d08a Convert CHANGELOG from RDOC to Markdown and cleaned it!
Signed-off-by: Rémy Coutable <rymai@rymai.me>
2011-04-30 01:39:40 +02:00
Rémy Coutable
20b8a9af69 Merge branch 'hook' of github.com:guard/guard into hook
Conflicts:
	lib/guard.rb
	lib/guard/dsl.rb
	lib/guard/hook.rb
	spec/guard/dsl_spec.rb
	spec/guard/hook_spec.rb
	spec/guard_spec.rb
2011-04-30 00:49:46 +02:00
Rémy Coutable
e853009528 Refactored Guard::Dsl#callback and updated specs, improved inline docs for Guard::Hook#hook, added ENV["GUARD_ENV"] = 'development' in Guardfile so we see hooks firing! Run specs on REE too.
Signed-off-by: Rémy Coutable <rymai@rymai.me>
2011-04-30 00:45:38 +02:00
monocle
134cbdb007 Hook - 1) Send args to hooks from Guard.supervised_task
2) Pass args from hooks to callbacks
3) Suppress UI message from hooks unless in 'development'
2011-04-30 00:45:38 +02:00
Rémy Coutable
b83653db2e Added #callback DSL, modified Guard and Guard::Hook a bit in consequence.
Signed-off-by: Rémy Coutable <remy@jilion.com>
2011-04-30 00:45:38 +02:00
monocle
b646ae53f6 Fix preexisting tests after adding default hooks 2011-04-30 00:45:13 +02:00
monocle
386b0be53d Hooks - Add :begin and :end hook to all guard actions via Guard.supervised_task 2011-04-30 00:41:25 +02:00
monocle
7916139726 Added hook/callback feature. 2011-04-30 00:41:25 +02:00
Thibaud Guillaume-Gentil
bb28799240 Removed useless Bundler requirement. Fixes #41 2011-04-29 08:25:57 +02:00
Andre Arko
ae1ae1cfbd Allow options (like :priority) to be passed through to Growl 2011-04-28 20:22:41 -07:00
Thibaud Guillaume-Gentil
ead039b2f2 Fixed README 2011-04-25 20:45:48 +02:00
Thibaud Guillaume-Gentil
76df310cad README rdoc => markdown 2011-04-25 20:44:18 +02:00
Thibaud Guillaume-Gentil
42288ece11 Merged pull request #50 from jrsacks/master.
Updating docs to describe inline guards
2011-04-25 11:19:18 -07:00
Jeff Sacks
38c371272d fixing require bug; updating documentation and version 2011-04-25 09:18:59 -05:00
slavic
6ecb72c9cb support color on windows 2011-04-24 22:30:54 +03:00
slavic
cbe2cb353c fix issue #27 2011-04-24 20:21:39 +03:00
Jeff Sacks
a0b6ecacdb adding support for inline classes 2011-04-21 16:39:46 -05:00
Thibaud Guillaume-Gentil
d329e4e3b0 Version 0.3.3 2011-04-19 09:40:56 +02:00
Thibaud Guillaume-Gentil
98c112c074 Fixed new_modified_files rerun conditions on Guard.run_on_change_for_all_guards 2011-04-19 09:40:34 +02:00
monocle
c82e1582f8 Hook - 1) Send args to hooks from Guard.supervised_task
2) Pass args from hooks to callbacks
3) Suppress UI message from hooks unless in 'development'
2011-04-17 17:06:45 -07:00
Thibaud Guillaume-Gentil
c5df9949fe Version 0.3.2 2011-04-17 21:49:07 +02:00
Rémy Coutable
5b8ae609da Merge branch 'master' into hook
Conflicts:
	lib/guard/guard.rb
	spec/guard_spec.rb
2011-04-16 23:23:08 +02:00
Rémy Coutable
c0f1ea6459 Merge branch 'master' of https://github.com/brainopia/guard into brainopia-master 2011-04-16 23:17:21 +02:00
Rémy Coutable
9b981f5459 Run guards for new modified files only if any guard match any file (preventing from clearing the screen when no guard will run!).
Signed-off-by: Rémy Coutable <remy@jilion.com>
2011-04-16 23:13:29 +02:00
Rémy Coutable
44aed3264c Added #callback DSL, modified Guard and Guard::Hook a bit in consequence.
Signed-off-by: Rémy Coutable <remy@jilion.com>
2011-04-16 23:02:13 +02:00
brainopia
097ce1f17e Fix Guard.locate_guard to return path to gem folder 2011-04-16 23:43:50 +04:00
Rémy Coutable
d47aebd424 Merge branch 'hook' of git://github.com/monocle/guard 2011-04-16 19:23:08 +02:00
monocle
1d38c59200 Fix preexisting tests after adding default hooks 2011-04-14 13:56:12 -07:00
Thibaud Guillaume-Gentil
bbc63abd5e Updated CHANGELOG (0.3.1 tag) 2011-04-14 13:54:18 -07:00
Thibaud Guillaume-Gentil
1027e4b6b3 Version 0.3.1 2011-04-14 13:54:18 -07:00
Thibaud Guillaume-Gentil
da0d059a43 Updated CHANGELOG 2011-04-14 13:54:18 -07:00
Nico Rieck
154ef207ed Use the correct ANSI escape code to reset SGR parameters. 2011-04-14 13:54:18 -07:00
monocle
7b559ce255 Hooks - Add :begin and :end hook to all guard actions via Guard.supervised_task 2011-04-14 13:31:34 -07:00
Thibaud Guillaume-Gentil
e13bde0411 Updated CHANGELOG (0.3.1 tag) 2011-04-14 21:40:46 +02:00
Thibaud Guillaume-Gentil
0c37dcd35a Version 0.3.1 2011-04-14 21:39:29 +02:00
Thibaud Guillaume-Gentil
d1ae2863c9 Updated CHANGELOG 2011-04-14 21:38:30 +02:00
Thibaud Guillaume-Gentil
2359723763 Merge branch 'fix/ui-reset-line' of https://github.com/gix/guard into gix-fix/ui-reset-line 2011-04-14 21:29:18 +02:00
monocle
c4ce612bde Added hook/callback feature. 2011-04-10 16:08:43 -07:00
Thibaud Guillaume-Gentil
4f13ab2785 Added some doc for the new --notify false option 2011-04-10 22:38:14 +02:00
Thibaud Guillaume-Gentil
42c27242e1 Added a command line option (-n false) to disable notifications (growl/libnotify). closed #28 2011-04-10 22:32:29 +02:00
Thibaud Guillaume-Gentil
31c43f7c13 Cleared screen when new files modified during the guards run 2011-04-10 21:56:48 +02:00
Thibaud Guillaume-Gentil
2a06c13356 Updated gems 2011-04-10 21:50:18 +02:00
Thibaud Guillaume-Gentil
bdc6dd06f3 Moved available guard to the wiki 2011-04-10 12:27:41 -07:00
Thibaud Guillaume-Gentil
0d396b690f Added guard-pow by @thibaudgg (good guy!) 2011-04-08 01:02:17 -07:00
Thibaud Guillaume-Gentil
b569cf47a5 Added guard-phantomjs by @carhartl 2011-04-04 01:49:06 -07:00
Rémy Coutable
ba508981a8 Merge branch 'typos' of https://github.com/nathany/guard into nathany-typos 2011-03-31 10:02:22 +02:00
Rémy Coutable
3d0a3f135f Merge branch 'master' of github.com:guard/guard 2011-03-31 10:02:11 +02:00
Rémy Coutable
6854a4c853 In Readme: method => methods 2011-03-31 10:02:08 +02:00
Nathan Youngman
ac5c605304 fix a few typos 2011-03-25 19:27:21 -06:00
Nico Rieck
74ddb05d2d Use the correct ANSI escape code to reset SGR parameters. 2011-03-24 21:36:24 +01:00
Thibaud Guillaume-Gentil
67f481f89b Added guard-prove to README 2011-03-22 00:17:36 -07:00
Thibaud Guillaume-Gentil
2188881093 Added guard-webrick to README 2011-03-22 00:14:14 -07:00
Rémy Coutable
ccb7c3a8c1 Edited README.rdoc via GitHub 2011-03-03 12:51:49 -08:00
Rémy Coutable
072e639128 Edited README.rdoc via GitHub 2011-03-03 12:51:16 -08:00
Rémy Coutable
b3d61c251c Edited README.rdoc via GitHub 2011-03-03 12:49:31 -08:00
Rémy Coutable
c76e753949 Improved README (via GitHub)! 2011-03-03 12:44:02 -08:00
Thibaud Guillaume-Gentil
26e42db3ae Added guard-pusher to the list! 2011-02-25 12:08:04 -08:00
Thibaud Guillaume-Gentil
59f555e086 Switched to gem which command to locate gem path rather than open-gem 2011-02-22 15:15:09 +01:00
Thibaud Guillaume-Gentil
17f048d883 Added koshigoe bug fixes 2011-02-21 12:07:09 +01:00
koshigoe
36e11c3820 fixed problem: Guard.get_guard_class return wrong class when loaded nested class.
The problem cause when using guard-ego with guard-spork.
2011-02-19 03:53:05 +09:00
Thibaud Guillaume-Gentil
523e10e118 Added guard-krl 2011-01-26 14:03:56 +01:00
Thibaud Guillaume-Gentil
07ad987dfc Updated Changelog 2011-01-26 14:03:48 +01:00
Marian Schubert
9ff627cfaa Return unique filenames from Linux listener
so that we don't get duplicate entries for same file. This solves problem with
commonly used Linux editors (e.g. Vim, Emacs) that generate multiple inotify
events on file save.

http://schettino72.wordpress.com/2010/03/07/inotify-text-editors-emacs-vim/
2011-01-26 12:17:09 +00:00
Thibaud Guillaume-Gentil
260c09a79f Updated Changelog 2011-01-19 23:08:41 +01:00
Thibaud Guillaume-Gentil
95da678d6a Bump to 0.3.0 2011-01-19 23:07:14 +01:00
Thibaud Guillaume-Gentil
c2fdcd76a6 Updated license date 2011-01-19 23:06:18 +01:00
Thibaud Guillaume-Gentil
d37502d5cc Updated dev gems 2011-01-19 23:06:02 +01:00
Thibaud Guillaume-Gentil
9772e9d9c8 Replaced Thread (incompatible with inotify) by a whole dir scan after each run_on_changes 2011-01-19 23:05:45 +01:00
Thibaud Guillaume-Gentil
48b9c2b824 Added guard-less in README 2011-01-05 00:04:54 -08:00
Rémy Coutable
a21bb8e306 Making the Readme clear about the required "guard" and "watch" and the optional "group" in Guardfile. 2010-12-17 20:57:54 +01:00
Rémy Coutable
73b2d0ba53 Removed not-used-anymore accessor 2010-12-17 20:57:11 +01:00
Rémy Coutable
1c86b1e632 Fix "uninitialized class variable @@guardfile in Guard::Dsl" 2010-12-17 18:44:12 +01:00
Rémy Coutable
a0f1ac4053 Renamed Guard::Dsl.guardfile_included? to Guard::Dsl.guardfile_include? (private API) and fix a bug where Guard::Dsl.guardfile_include? was not detecting guard specified with a symbol, double quotes or parenthesis in Guardfile.
e.g.:
guard :rspec
guard ('rspec')
guard("rspec")
...
2010-12-17 18:37:44 +01:00
Rémy Coutable
5db6149651 Updated Changelog and Readme 2010-12-17 18:14:33 +01:00
Rémy Coutable
f90823ae90 Shortened implementation of the new group DSL method and made it (+ specs) clearer 2010-12-17 18:13:31 +01:00
Michael Kessler
63af219490 Enhance the DSL to allow grouping of guard definitions and run them selectively 2010-12-17 16:31:39 +01:00
Rémy Coutable
c788c00099 Fix bug that occurred when pattern was a string and no action was associated. 2010-12-16 15:09:36 +01:00
Rémy Coutable
d0891efdc0 Remove useless variable assignment 2010-12-16 15:08:26 +01:00
Rémy Coutable
8fa0f1d4bc Match a Regex 2010-12-16 15:08:05 +01:00
Rémy Coutable
ebe94d213b Improved deprecation warning message 2010-12-16 09:15:14 +01:00
Rémy Coutable
1831bf752f Guard no more automatically convert String into Regexp in "watch" method patterns.
It allows to define:

watch("foo_bar.rb") without meaning /foo_bar.rb/ (where "foo_bar_rb.rb" would have been matched)

However, during the deprecation phase, strings that look like a regexes (e.g. "^foo_bar.rb", "foo_bar.rb$", "foo_.*bar.rb" or "foo_(bar|baz).rb" are converted automatically to Regexp and a *very annoying* deprecation message is displayed.
2010-12-16 01:22:42 +01:00
Thibaud Guillaume-Gentil
62f9cd5311 Fixed yesterday merge 2010-12-01 08:37:31 +01:00
Thibaud Guillaume-Gentil
b16239cdc5 Added guard-stendhal & guard-soca 2010-11-30 22:46:52 +01:00
Thibaud Guillaume-Gentil
2fc6745837 Merge branch 'master' of github.com:guard/guard
Conflicts:
	lib/guard.rb
	lib/guard/interactor.rb
	spec/guard_spec.rb
2010-11-30 21:23:53 +01:00
Thibaud Guillaume-Gentil
53a79691a5 Kept listener running in thread even when guards plugin are also running. 2010-11-30 21:15:03 +01:00
Thibaud Guillaume-Gentil
ae55268e88 Updated Changelog 2010-11-25 23:37:56 -08:00
Thibaud Guillaume-Gentil
bb56c41a49 Using %|...| regex in Guardfile example 2010-11-25 23:35:46 -08:00
Rémy Coutable
7f39a55fdf Use 'guard' instead of 'g', use parenthesis and don't explicitly return when not necessary 2010-11-26 00:58:36 +01:00
Rémy Coutable
3116b13f1b Optimized spec_helper, remove useless code and add the "bypass when test env" for UI.error 2010-11-26 00:57:08 +01:00
Rémy Coutable
cda514cf2a Updated Changelog and Readme 2010-11-26 00:56:18 +01:00
Rémy Coutable
47d1e11743 Added specs for Guard::Watcher, allow enumerables in 'watch' blocks. 2010-11-26 00:55:21 +01:00
Thibaud Guillaume-Gentil
85beb5e97a Don't call run_on_change guard method when there is no matched files. 2010-11-25 08:52:53 +01:00
Thibaud Guillaume-Gentil
eebd74b253 Added options to error/debug UI method 2010-11-11 11:02:29 +01:00
Thibaud Guillaume-Gentil
0e88105faa Added guard-ego/jammit/spork to README, awesome! 2010-11-11 08:22:35 +01:00
Rémy Coutable
e2247ea732 Improving, cleaning & making clear Guard class' specs 2010-11-03 23:31:00 +01:00
55 changed files with 6310 additions and 1044 deletions

9
.gitignore vendored
View File

@ -1,6 +1,13 @@
pkg/*
doc/*
*.gem
*.rbc
.*.swp
*.bak
.bundle
.yardoc
.rbx
.rvmrc
Gemfile.lock
## MAC OS
@ -9,4 +16,4 @@ Gemfile.lock
.com.apple.timemachine.supported
.fseventsd
Desktop DB
Desktop DF
Desktop DF

19
.travis.yml Normal file
View File

@ -0,0 +1,19 @@
rvm:
- 1.8.7
- 1.9.2
- ree
- jruby
- rbx
branches:
only:
- master
- guard_dependencies
env:
- GUARD_SLEEP=1
notifications:
recipients:
- thibaud@thibaud.me
- rymai@rymai.me
- michi@netzpiraten.ch
- yann.lugrin@sans-savoir.net
irc: "irc.freenode.org#guard"

11
.yardopts Normal file
View File

@ -0,0 +1,11 @@
--title 'Guard Documentation'
--readme README.md
--markup markdown
--markup-provider kramdown
--private
--protected
--output-dir ./doc
lib/**/*.rb
-
CHANGELOG.md
LICENSE

347
CHANGELOG.md Normal file
View File

@ -0,0 +1,347 @@
## Master
### Improvements
- Add cli option (-i / --no-interactions) to turn off Guard terminal interactions. ([@thibaudgg][])
- Add support for Growl Notification Transport Protocol. ([@netzpirat][])
- [#157](https://github.com/guard/guard/pull/157): Allow any return from the Guard watchers. ([@earlonrails][])
- [#156](https://github.com/guard/guard/pull/156): Log error and diagnostic messages to STDERR. ([@sunaku][])
- [#152](https://github.com/guard/guard/pull/152): Growl Notify API update for a graceful fail. ([@scottdavis][])
### Bug fix
- [#149](https://github.com/guard/guard/issues/160): Avoid `Guard is not missing constant ...` exceptions. (reported by [@earlonrails][], fixed by [@netzpirat][])
## 0.8.4 - October 3, 2011
### Bug fix
- [#149](https://github.com/guard/guard/issues/149) & [#150](https://github.com/guard/guard/pull/150): Fix issue where interator thread was continuing to capture input from stdin while a guard is being executed. (reported by [@hardipe][], fixed by [@f1sherman][])
## 0.8.3 - October 1, 2011
### Bug fix
- [#145](https://github.com/guard/guard/pull/145): Fix over-utilization of CPU in Interactor. ([@johnbintz][])
### Improvements
- [#146](https://github.com/guard/guard/pull/146): Use a mutex instead of a lock for more efficient/simple locking. ([@f1sherman][])
- Make Guard implementation of `:task_has_failed` simple. ([@netzpirat][])
## 0.8.2 - September 30, 2011
### Bug fix
- Fixed guard stop to prevent run_guard_task(:stop) to be skipped [guard-spork issue #28](https://github.com/guard/guard-spork/issues/28). ([@thibaudgg][])
### Improvement
- Update docs regarding :task_has_failed. ([@netzpirat][])
## 0.8.1 - September 29, 2011
### Bug fix
- [#144](https://github.com/guard/guard/pull/144): Fix `guard init`. (reported by [@fabioyamate][], fixed by [@rymai][])
## 0.8.0 - September 28, 2011
### Bug fixes
- [#137](https://github.com/guard/guard/pull/137): Fix interacting with tools like ruby-debug. ([@hron][] & [@netzpirat][])
- [#138](https://github.com/guard/guard/pull/138): Fixed comments in example scaffold to reference interactions. ([@rmm5t][] & [@netzpirat][])
### New feature
- [#136](https://github.com/guard/guard/pull/136): New CLI `:watch_all_modifications`/`-A` option to watch for deleted and moved files too. ([@limeyd][] & [@netzpirat][])
- [#97](https://github.com/guard/guard/issues/97): Guard dependencies. Task execution can now be halted if a Guard throws `:task_has_failed` and `Guard::Dsl#group` options include `:halt_on_fail => true`. ([@rymai][])
- [#121](https://github.com/guard/guard/issues/121): `Guard.guards` and `Guard.groups` are now smart accessors. Filters can be passed to find a specific Guard/group or several Guards/groups that match (see YARDoc). ([@rymai][] & [@ches][])
- New `Guard::Group` class to store groups defined in Guardfile (with `Guard::Dsl#group`). ([@rymai][])
### Improvements
- Specs refactoring. ([@netzpirat][])
- Full YARD documentation. ([@netzpirat][] & a little of [@rymai][])
## 0.7.0 - September 14, 2011
## 0.7.0.rc1 - September 5, 2011
### Major Changes
- Posix Signals handlers (`Ctrl-C`, `Ctrl-\` and `Ctrl-Z`) are no more supported and replaced by `$stdin.gets`. Please refer to the "Interactions" section in the README for more information. ([@thibaudgg][])
- JRuby & Rubinius support (beta). ([@thibaudgg][] & [@netzpirat][])
### New features
- [#42](https://github.com/guard/guard/pull/42): New DSL method: `callback` allows you to execute arbitrary code before or after any of the `start`, `stop`, `reload`, `run_all` and `run_on_change` guards' method. New [Wiki page](https://github.com/guard/guard/wiki/Hooks-and-callbacks) for documenting it. ([@monocle][] & [@rymai][])
- Ability to 'pause' files modification listening. Please refer to the "Interactions" section in the README for more information. ([@thibaudgg][])
### Improvement
- Remove the need to scan the whole directory after guard's `run_on_change` method. ([@thibaudgg][])
## 0.6.3 - September 1, 2011
### New features
- [#130](https://github.com/guard/guard/pull/130): Adds `ignore_paths` method to DSL. ([@ianwhite][])
- [#128](https://github.com/guard/guard/pull/128): Users can add additional settings to `~/.guard.rb` that augment the existing Guardfile. ([@tpope][])
## 0.6.2 - August 17, 2011
### Bug fixes
- Re-add the possibility to use the `growl` gem since the `growl_notify` gem this is currently known to not work in conjunction with Spork. ([@netzpirat][])
- Ensure that scoped groups and group name are symbolized before checking for inclusion. ([@rymai][])
### New features
- Groups are now stored in a `@groups` variable (will be used for future features). ([@rymai][])
- Guards will now receive their group in the options hash at initialization (will be used for future features). ([@rymai][])
### Improvement
- Explain the growl/growl_notify differences in the README. ([@netzpirat][])
## 0.6.1 - August 15, 2011
### Bug fixes
- [#120](https://github.com/guard/guard/pull/120): remove `guardfile_contents` when re-evaluating so that the Guardfile gets reloaded correctly. ([@mordaroso][])
- [#119](https://github.com/guard/guard/pull/119): `Dsl.evaluate_guardfile` uses all groups if none specified. ([@ches][])
## 0.6.0 - August 13, 2011
### Bug fixes
- Pull request [#107](https://github.com/guard/guard/pull/107): Small spelling fix. ([@dnagir][])
- `Dir.glob` now ignores files that don't need to be watched. ([@rymai][])
### New feature
- Pull request [#112](https://github.com/guard/guard/pull/112): Add `list` command to CLI. ([@docwhat][])
### Improvements
- [#99](https://github.com/guard/guard/pull/99): [OS X] Switch from growl gem to growl_notify gem. ([@johnbintz][])
- [#115](https://github.com/guard/guard/pull/115): [Linux] Add `:transient => true` to default libnotify options. ([@zonque][])
- [#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,
- `guardfile`/`-G` to specify an alternate location for the Guardfile to use.
- [#90](https://github.com/guard/guard/pull/90): Refactoring of color handling in the `Guard::UI`. ([@stereobooster][])
## 0.5.1 - July 2, 2011
### Bug fix
- Fixed `guard show` command. ([@bronson][] & [@thibaudgg][])
## 0.5.0 - July 2, 2011
### New features
- Guard::Ego is now part of Guard, so Guardfile is automagically re-evaluated when modified. ([@thibaudgg][])
- [#91](https://github.com/guard/guard/pull/91): Show Guards in Guardfile with the `guard -T`. ([@johnbintz][])
### Improvements
- [#98](https://github.com/guard/guard/issues/98): Multiple calls per watch event on linux with rb-inotify. ([@jeffutter][] & [@netzpirat][])
- [#94](https://github.com/guard/guard/pull/94): Show backtrace in terminal when a problem with a watch action occurs. ([@capotej][])
- [#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][])
- [#79](https://github.com/guard/guard/issues/79) and Pull request [#82](https://github.com/guard/guard/pull/82): Improve INotify support on Linux. ([@Gazer][] & [@yannlugrin][])
- [#12](https://github.com/guard/guard/issues/12) and Pull request [#86](https://github.com/guard/guard/pull/86): Eventually exits with SystemStackError. ([@stereobooster][])
- [#84](https://github.com/guard/guard/pull/84): Use RbConfig instead of obsolete and deprecated Config. ([@etehtsea][])
- [#80](https://github.com/guard/guard/pull/80): Watching dotfile (hidden files under unix). (reported by [@chrisberkhout][], fixed by [@yannlugrin][])
- Clear the terminal on start when the `:clear` option is given. ([@rymai][])
- Rename home directory Guardfile to `.Guardfile`. ([@tpope][])
## 0.4.2 - June 7, 2011
### Bug fixes
- Fixed Guard::Version in ruby 1.8.7 ([@thibaudgg][])
- Fix ([@mislav][]) link in CHANGELOG (Note: this is a recursive CHANGELOG item). ([@fnichol][])
## 0.4.1 - June 7, 2011
### Improvements
- [#77](https://github.com/guard/guard/pull/77): Refactor `get_guard_class` to first try the constant and fallback to require + various tweaks. ([@mislav][])
- Notifier improvement, don't use system notification library if could not be required. ([@yannlugrin][])
## 0.4.0 - June 5, 2011
### Bug fix
- In Ruby < 1.9, `Symbol#downcase` doesn't exist! ([@rymai][])
### New features
- [#73](https://github.com/guard/guard/pull/73): Allow DSL's `group` method to accept a Symbol as group name. ([@johnbintz][])
- [#51](https://github.com/guard/guard/pull/51): Allow options (like `:priority`) to be passed through to the Notifier. ([@indirect][] & [@netzpirat][])
### Improvement
- [#74](https://github.com/guard/guard/pull/74): Added link definitions to make the CHANGELOG more DRY! That's for sure now, we have the cleanest CHANGELOG ever! (even the link definitions are sorted alphabetically!) ([@pcreux][])
## 0.4.0.rc - May 28, 2011
### Bug fixes
- [#69](https://github.com/guard/guard/pull/69): Fixed typo in README: `Ctr-/` => `Ctr-\`. ([@tinogomes][])
- [#66](https://github.com/guard/guard/pull/66): Support for dashes in guard names. ([@johnbintz][])
- Require `guard/ui` because `Guard::Notifier` can be required without full Guard. ([@yannlugrin][])
- Handled quick file (<1s) modification. Avoid to catch modified files without content modification (sha1 checksum). ([@thibaudgg][] & [@netzpirat][])
- Fixed `Guard::Notifier` (when growl/libnotify not present). ([@thibaudgg][])
- Fixed Rubygems deprecation messages. ([@thibaudgg][])
### New features
- [#67](https://github.com/guard/guard/pull/67): Allow Guardfile in `$HOME` folder. ([@hashrocketeer][])
- [#64](https://github.com/guard/guard/pull/64): Windows notifications support. ([@stereobooster][])
- [#63](https://github.com/guard/guard/pull/63): Refactor listeners to work as a library. ([@niklas][])
- Use `ENV["GUARD_NOTIFY"]` to disable notifications. ([@thibaudgg][])
- Cleaning up all specs. ([@netzpirat][])
- [#60](https://github.com/guard/guard/pull/60): Added Windows support. ([@stereobooster][])
- [#58](https://github.com/guard/guard/pull/58): Extract code from signal handlers into methods. ([@nicksieger][])
- [#55](https://github.com/guard/guard/pull/55): It is now possible to pass `:guardfile` (a Guardfile path) or `:guardfile_contents` (the content of a Guardfile) to `Guard::Dsl.evaluate_guardfile`. Hence this allows the use of `Guard::Dsl.evaluate_guardfile` in a programmatic manner. ([@anithri][], improved by [@rymai][])
## 0.3.4 - April 24, 2011
### Bug fix
- [#41](https://github.com/guard/guard/issues/41): Removed useless Bundler requirement. ([@thibaudgg][])
### New features
- Changed CHANGELOG from RDOC to Markdown and cleaned it! Let's celebrate! ([@rymai][])
- Changed README from RDOC to Markdown! Let's celebrate! ([@thibaudgg][])
- [#48](https://github.com/guard/guard/issues/48): Adding support for inline Guard classes rather than requiring a gem. ([@jrsacks][])
## 0.3.3 - April 18, 2011
### Bug fix
- Fixed `new_modified_files` rerun conditions on `Guard.run_on_change_for_all_guards`. ([@thibaudgg][])
## 0.3.2 - April 17, 2011
### Bug fixe
- [#43](https://github.com/guard/guard/pull/43): Fixed `guard init` command. ([@brainopia][])
## 0.3.1 - April 14, 2011
### Bug fixes
- Return unique filenames from Linux listener. (Marian Schubert)
- `Guard.get_guard_class` return wrong class when loaded nested class. ([@koshigoe][])
- [#35](https://github.com/guard/guard/issues/35): Fixed open-gem/gem_open dependency problem by using `gem which` to locate guards gem path. (reported by [@thierryhenrio][], fixed by [@thibaudgg][])
- [#38](https://github.com/guard/guard/issues/38) & Pull request [#39](https://github.com/guard/guard/issues/39): Fixed an invalid ANSI escape code in `Guard::UI.reset_line`. ([@gix][])
### New feature
- [#28](https://github.com/guard/guard/issues/28): New `-n` command line option to disable notifications (Growl / Libnotify). ([@thibaudgg][])
## 0.3.0 - January 19, 2011
### Bug fix
- Avoid launching `run_on_change` guards method when no files matched. `--clear` guard argument is now usable. ([@thibaudgg][])
### New features
- The whole directory is now watched during `run_on_change` to detect new files modifications. ([@thibaudgg][])
- [#26](https://github.com/guard/guard/pull/26): New DSL method: `group` allows you to group several guards. New CLI option: `--group group_name` to specify certain groups of guards to start. ([@netzpirat][])
- `watch` patterns are now more strict: strings are matched with `String#==`, `Regexp` are matched with `Regexp#match`. ([@rymai][])
- A deprecation warning is displayed if your `Guardfile` contains `String` that look like `Regexp` (bad!). ([@rymai][])
- It's now possible to return an `Enumerable` in the `watch` optional blocks in the `Guardfile`. ([@rymai][])
### New specs
- `Guard::Watcher`. ([@rymai][])
- [#13](https://github.com/guard/guard/pull/13): `Guard::Dsl`. ([@oliamb][])
## 0.2.2 - October 25, 2010
### Bug fix
- [#5](https://github.com/guard/guard/issues/5): avoid creating new copy of `fsevent_watch` every time a file is changed. (reported by [@stouset][], fixed by [@thibaudgg][])
## 0.2.1 - October 24, 2010
### Bug fixes
- [#7](https://github.com/guard/guard/pull/7): Fixes for Linux support. ([@yannlugrin][])
- [#6](https://github.com/guard/guard/pull/6): Locate guard now chomp newline in result path. ([@yannlugrin][])
## 0.2.0 - October 21, 2010
### Bug fixes
- [#3](https://github.com/guard/guard/issues/3): `guard init <guard-name>` no more need `Gemfile` but `open_gem` is required now. (reported by [@wereHamster][], fixed by [@thibaudgg][])
- [#2](https://github.com/guard/guard/issues/2): 1.8.6 compatibility. (reported by [@veged][], fixed by [@thibaudgg][])
- Removes Growl & Libnotify dependencies. ([@thibaudgg][])
## 0.2.0.beta.1 - October 17, 2010
### New features
- Improved listeners support (`rb-fsevent` & `rb-inotify`). ([@thibaudgg][])
- Added polling listening fallback. ([@thibaudgg][])
[@anithri]: https://github.com/anithri
[@brainopia]: https://github.com/brainopia
[@bronson]: https://github.com/bronson
[@capotej]: https://github.com/capotej
[@ches]: https://github.com/ches
[@chrisberkhout]: https://github.com/chrisberkhout
[@dnagir]: https://github.com/dnagir
[@docwhat]: https://github.com/docwhat
[@earlonrails]: https://github.com/earlonrails
[@etehtsea]: https://github.com/etehtsea
[@f1sherman]: https://github.com/f1sherman
[@fabioyamate]: https://github.com/fabioyamate
[@fnichol]: https://github.com/fnichol
[@Gazer]: https://github.com/Gazer
[@gix]: https://github.com/gix
[@hron]: https://github.com/hron
[@hardipe]: https://github.com/hardipe
[@hashrocketeer]: https://github.com/hashrocketeer
[@ianwhite]: https://github.com/ianwhite
[@indirect]: https://github.com/indirect
[@jeffutter]: https://github.com/jeffutter
[@johnbintz]: https://github.com/johnbintz
[@jrsacks]: https://github.com/jrsacks
[@koshigoe]: https://github.com/koshigoe
[@limeyd]: https://github.com/limeyd
[@mcmire]: https://github.com/mcmire
[@mislav]: https://github.com/mislav
[@monocle]: https://github.com/monocle
[@mordaroso]: https://github.com/mordaroso
[@nestegg]: https://github.com/nestegg
[@netzpirat]: https://github.com/netzpirat
[@nicksieger]: https://github.com/nicksieger
[@niklas]: https://github.com/niklas
[@oliamb]: https://github.com/oliamb
[@pcreux]: https://github.com/pcreux
[@rmm5t]: https://github.com/rmm5t
[@rymai]: https://github.com/rymai
[@scottdavis]: https://github.com/scottdavis
[@stereobooster]: https://github.com/stereobooster
[@stouset]: https://github.com/stouset
[@sunaku]: https://github.com/sunaku
[@thibaudgg]: https://github.com/thibaudgg
[@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
[@zonque]: https://github.com/zonque

View File

@ -1,26 +0,0 @@
== 0.2.2 (Oct 25, 2010)
Bugs fixes:
- Avoid creating new copy of fsevent_watch every time a file is changed. (issue #5)
== 0.2.1 (Oct 24, 2010)
Bugs fixes:
- Fixes for Linux support
== 0.2.0 (Oct 21, 2010)
Bugs fixes:
- Fixes for 1.8.6 compatibility (issue #2)
- guard init <guard-name> no more need Gemfile presence but open_gem is required now (issue #3)
- Removes growl & libnotify dependencies
== 0.2.0.beta.1 (Oct 17, 2010)
Features:
- Improved listeners support (rb-fsevent & rb-inotify)
- Added polling listening fallback

25
Gemfile
View File

@ -1,14 +1,23 @@
source "http://rubygems.org"
source :rubygems
gemspec
gem 'rake'
group :guard do
gem 'guard-ronn'
end
require 'rbconfig'
if Config::CONFIG['target_os'] =~ /darwin/i
gem 'rb-fsevent', '>= 0.3.5'
gem 'growl', '~> 1.0.3'
end
if Config::CONFIG['target_os'] =~ /linux/i
gem 'rb-inotify', '>= 0.5.1'
gem 'libnotify', '~> 0.1.3'
if RbConfig::CONFIG['target_os'] =~ /darwin/i
gem 'rb-fsevent', '>= 0.4.0', :require => false
gem 'growl', '~> 1.0.3', :require => false
elsif RbConfig::CONFIG['target_os'] =~ /linux/i
gem 'rb-inotify', '>= 0.8.5', :require => false
gem 'libnotify', '~> 0.1.3', :require => false
elsif RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
gem 'win32console', :require => false
gem 'rb-fchange', '>= 0.0.2', :require => false
gem 'rb-notifu', '>= 0.0.4', :require => false
end

View File

@ -1,5 +1,28 @@
guard 'rspec', :version => 2 do
watch('^spec/(.*)_spec.rb')
watch('^lib/(.*).rb') { |m| "spec/#{m[1]}_spec.rb" }
watch('^spec/spec_helper.rb') { "spec" }
end
group :specs do
guard :rspec, :all_on_start => false, :all_after_pass => false, :cli => '--fail-fast --format doc' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/support/listener_helper.rb') { Dir.glob("spec/guard/listeners/*") }
watch('spec/spec_helper.rb') { "spec" }
end
end
group :docs do
guard :ronn do
watch(%r{^man/.+\.ronn?$})
end
end
# require 'guard/guard'
#
# module ::Guard
# class Breaking < ::Guard::Guard
# def run_all
# raise "Fool !"
# end
# end
# end
#
# group "exceptional" do
# guard :breaking
# end

View File

@ -1,4 +1,4 @@
Copyright (c) 2010 Thibaud Guillaume-Gentil
Copyright (c) 2011 Thibaud Guillaume-Gentil
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

459
README.md Normal file
View File

@ -0,0 +1,459 @@
Guard [![Build Status](https://secure.travis-ci.org/guard/guard.png)](http://travis-ci.org/guard/guard)
=====
Guard is a command line tool that easily handle events on files modifications.
If you have any questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard` (irc.freenode.net).
Features
--------
* [FSEvent](http://en.wikipedia.org/wiki/FSEvents) support on Mac OS X 10.5+ (without RubyCocoa!, [rb-fsevent gem, >= 0.3.5](https://rubygems.org/gems/rb-fsevent) required).
* [Inotify](http://en.wikipedia.org/wiki/Inotify) support on Linux ([rb-inotify gem, >= 0.5.1](https://rubygems.org/gems/rb-inotify) required).
* [Directory Change Notification](http://msdn.microsoft.com/en-us/library/aa365261\(VS.85\).aspx) support on Windows ([rb-fchange, >= 0.0.2](https://rubygems.org/gems/rb-fchange) required).
* Polling on the other operating systems (help us to support more OS).
* Automatic & Super fast (when polling is not used) files modifications detection (even new files are detected).
* Visual notifications on Mac OSX ([Growl](http://growl.info)), Linux ([Libnotify](http://developer.gnome.org/libnotify)) and Windows ([Notifu](http://www.paralint.com/projects/notifu)).
* Tested against Ruby 1.8.7, 1.9.2, REE and the latest versions of JRuby & Rubinius.
Screencast
----------
Ryan Bates made a Railscast on Guard, you can view it here: [http://railscasts.com/episodes/264-guard](http://railscasts.com/episodes/264-guard)
Install
-------
Install the gem:
$ gem install guard
Or add it to your Gemfile (inside the `development` group):
gem 'guard'
and install it via Bundler:
$ bundle install
Generate an empty Guardfile with:
$ guard init
You may optionally place a .Guardfile in your home directory to use it across multiple projects.
Also note that if a `.guard.rb` is found in your home directory, it will be appended to the Guardfile.
Add the guards you need to your Guardfile (see the existing guards below).
Now, be sure to read the particular instructions for your operating system: [Mac OS X](#mac) | [Linux](#linux) | [Windows](#win)
<a name="mac" />
### On Mac OS X
Install the rb-fsevent gem for [FSEvent](http://en.wikipedia.org/wiki/FSEvents) support:
$ gem install rb-fsevent
You have three possibilities for getting Growl support:
Use the [growl_notify gem](https://rubygems.org/gems/growl_notify):
$ gem install growl_notify
The `growl_notify` gem is compatible with Growl >= 1.3 and uses AppleScript to send Growl notifications.
The gem needs a native C extension to make use of AppleScript and does not run on JRuby and MacRuby.
Use the [ruby_gntp gem](https://github.com/snaka/ruby_gntp):
$ gem install ruby_gntp
The `ruby_gntp` gem is compatible with Growl >= 1.3 and uses the Growl Notification Transport Protocol to send Growl
notifications. Guard supports multiple notification channels for customizing each notification type, but it's limited
to the local host currently.
Use the [growl gem](https://rubygems.org/gems/growl):
$ gem install growl
The `growl` gem is compatible with all versions of Growl and uses a command line tool [growlnotify](http://growl.info/extras.php#growlnotify)
that must be separately downloaded and installed. You can also install it with HomeBrew:
$ brew install growlnotify
Finally you have to add your Growl library of choice to your Gemfile:
gem 'rb-fsevent'
gem 'growl_notify' # or gem 'ruby_gntp' or gem 'growl'
Have a look at the [Guard Wiki](https://github.com/guard/guard/wiki/Which-Growl-library-should-I-use) for more information.
<a name="linux" />
### On Linux
Install the [rb-inotify gem](https://rubygems.org/gems/rb-inotify) for [inotify](http://en.wikipedia.org/wiki/Inotify) support:
$ gem install rb-inotify
Install the [libnotify gem](https://rubygems.org/gems/libnotify) if you want visual notification support:
$ gem install libnotify
And add them to your Gemfile:
gem 'rb-inotify'
gem 'libnotify'
<a name="win" />
### On Windows
Install the [rb-fchange gem](https://rubygems.org/gems/rb-fchange) for [Directory Change Notification](http://msdn.microsoft.com/en-us/library/aa365261\(VS.85\).aspx) support:
$ gem install rb-fchange
Install the [win32console gem](https://rubygems.org/gems/win32console) if you want colors in your terminal:
$ gem install win32console
Install the [rb-notifu gem](https://rubygems.org/gems/rb-notifu) if you want visual notification support:
$ gem install rb-notifu
And add them to your Gemfile:
gem 'rb-fchange'
gem 'rb-notifu'
gem 'win32console'
Usage
-----
Just launch Guard inside your Ruby / Rails project with:
$ guard [start]
or if you use Bundler, to run the Guard executable specific to your bundle:
$ bundle exec guard [start]
Guard will look for a Guardfile in your current directory. If it does not find one, it will look in your `$HOME` directory for a .Guardfile.
Command line options
--------------------
### `-c`/`--clear` option
Shell can be cleared after each change:
$ guard --clear
$ guard -c # shortcut
### `-n`/`--notify` option
Notifications (growl/libnotify) can be disabled:
$ guard --notify false
$ guard -n f # shortcut
Notifications can also be disabled globally by setting a `GUARD_NOTIFY` environment variable to `false`
### `-g`/`--group` option
Only certain guards groups can be run (see the Guardfile DSL below for creating groups):
$ guard --group group_name another_group_name
$ guard -g group_name another_group_name # shortcut
### `-d`/`--debug` option
Guard can be run in debug mode:
$ guard --debug
$ guard -d # shortcut
### `-w`/`--watchdir` option
Guard can watch in any directory (instead of the current directory):
$ guard --watchdir ~/your/fancy/project
$ guard -w ~/your/fancy/project # shortcut
### `-G`/`--guardfile` option
Guard can use a Guardfile not located in the current directory:
$ guard --guardfile ~/.your_global_guardfile
$ guard -G ~/.your_global_guardfile # shortcut
### `-A`/`--watch-all-modifications` option
Guard can optionally watch all file modifications like moves or deletions with:
$ guard start -A
$ guard start --watch-all-modifications
### `-i`/`--no-interactions` option
Turn off completely any Guard terminal [interactions](#interactions) with:
$ guard start -A
$ guard start --watch-all-modifications
An exhaustive list of options is available with:
$ guard help [TASK]
<a name="interactions" />
Interactions
------------
**From version >= 0.7.0 Posix Signal handlers are no more used to interact with Guard. If you're using a version < 0.7, please refer to the [README in the v0.6 branch](https://github.com/guard/guard/blob/v0.6/README.md).**
When Guard do nothing you can interact with by entering a command + hitting enter:
* `stop|quit|exit|s|q|e + enter` - Calls each guard's `#stop` method, in the same order they are declared in the Guardfile, and then quits Guard itself.
* `reload|r|z + enter` - Calls each guard's `#reload` method, in the same order they are declared in the Guardfile.
* `pause|p + enter` - Toggle files modification listening. Useful when switching git branches.
* `just enter (no commands)` - Calls each guard's `#run_all` method, in the same order they are declared in the Guardfile.
Available Guards
----------------
A list of the available guards is present [in the wiki](https://github.com/guard/guard/wiki/List-of-available-Guards).
### Add a guard to your Guardfile
Add it to your Gemfile (inside the `development` group):
gem '<guard-name>'
You can list all guards installed on your system with:
$ guard list
Insert default guard's definition to your Guardfile by running this command:
$ guard init <guard-name>
You are good to go, or you can modify your guards' definition to suit your needs.
Guardfile DSL
-------------
The Guardfile DSL consists of the following methods:
* `#guard` - Allows you to add a guard with an optional hash of options.
* `#watch` - Allows you to define which files are supervised by a guard. An optional block can be added to overwrite the paths sent to the guard's `#run_on_change` method or to launch any arbitrary command.
* `#group` - Allows you to group several guards together. Groups to be run can be specified with the Guard DSL option `--group` (or `-g`). This comes in handy especially when you have a huge Guardfile and want to focus your development on a certain part. Guards that don't belong to a group are considered global and are always run.
* `#callback` - Allows you to execute arbitrary code before or after any of the `start`, `stop`, `reload`, `run_all` and `run_on_change` guards' method. You can even insert more hooks inside these methods. Please [checkout the Wiki page](https://github.com/guard/guard/wiki/Hooks-and-callbacks) for more details.
* `#ignore_paths` - Allows you to ignore top level directories altogether. This comes is handy when you have large amounts of non-source data in you project. By default .bundle, .git, log, tmp, and vendor are ignored. Currently it is only possible to ignore the immediate descendants of the watched directory.
Example:
ignore_paths 'foo', 'bar'
group 'backend' do
guard 'bundler' do
watch('Gemfile')
end
guard 'rspec', :cli => '--color --format doc' do
# Regexp watch patterns are matched with Regexp#match
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^spec/models/.+\.rb$}) { ["spec/models", "spec/acceptance"] }
watch(%r{^spec/.+\.rb$}) { `say hello` }
# String watch patterns are matched with simple '=='
watch('spec/spec_helper.rb') { "spec" }
end
end
group 'frontend' do
guard 'coffeescript', :output => 'public/javascripts/compiled' do
watch(%r{^app/coffeescripts/.+\.coffee$})
end
guard 'livereload' do
watch(%r{^app/.+\.(erb|haml)$})
end
end
Using a Guardfile without the `guard` binary
--------------------------------------------
The Guardfile DSL can also be used in a programmatic fashion by calling directly `Guard::Dsl.evaluate_guardfile`.
Available options are as follow:
* `:guardfile` - The path to a valid Guardfile.
* `:guardfile_contents` - A string representing the content of a valid Guardfile
Remember, without any options given, Guard will look for a Guardfile in your current directory and if it does not find one, it will look for it in your `$HOME` directory.
For instance, you could use it as follow:
gem 'guard'
require 'guard'
Guard.setup
Guard::Dsl.evaluate_guardfile(:guardfile => '/your/custom/path/to/a/valid/Guardfile')
# or
Guard::Dsl.evaluate_guardfile(:guardfile_contents => "
guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
end
")
### Listing defined guards/groups for the current project
You can list the defined groups and guards for the current Guardfile from the command line using `guard show` or `guard -T`:
$ guard -T
(global):
shell
Group backend:
bundler
rspec: cli => "--color --format doc"
Group frontend:
coffeescript: output => "public/javascripts/compiled"
livereload
User config file
----------------
If a `.guard.rb` is found in your home directory, it will be appended to
the Guardfile. This can be used for tasks you want guard to handle but
other users probably don't. For example, indexing your source tree with
[Ctags](http://ctags.sourceforge.net):
guard 'shell' do
watch(%r{^(?:app|lib)/.+\.rb$}) { `ctags -R` }
end
Create a new guard
------------------
Creating a new guard is very easy, just create a new gem (`bundle gem` if you use Bundler) with this basic structure:
.travis.yml # bonus point!
CHANGELOG.md # bonus point!
Gemfile
guard-name.gemspec
Guardfile
lib/
guard/
guard-name/
templates/
Guardfile # needed for `guard init <guard-name>`
version.rb
guard-name.rb
test/ # or spec/
README.md
`Guard::GuardName` (in `lib/guard/guard-name.rb`) must inherit from
[Guard::Guard](http://rubydoc.info/github/guard/guard/master/Guard/Guard) and should overwrite at least one of
the basic `Guard::Guard` task methods.
Here is an example scaffold for `lib/guard/guard-name.rb`:
require 'guard'
require 'guard/guard'
module Guard
class GuardName < Guard
# Initialize a Guard.
# @param [Array<Guard::Watcher>] watchers the Guard file watchers
# @param [Hash] options the custom Guard options
def initialize(watchers = [], options = {})
super
end
# Call once when Guard starts. Please override initialize method to init stuff.
# @raise [:task_has_failed] when start has failed
def start
end
# Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
# @raise [:task_has_failed] when stop has failed
def stop
end
# Called when `reload|r|z + enter` is pressed.
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
# @raise [:task_has_failed] when reload has failed
def reload
end
# Called when just `enter` is pressed
# This method should be principally used for long action like running all specs/tests/...
# @raise [:task_has_failed] when run_all has failed
def run_all
end
# Called on file(s) modifications that the Guard watches.
# @param [Array<String>] paths the changes files or paths
# @raise [:task_has_failed] when run_on_change has failed
def run_on_change(paths)
end
# Called on file(s) deletions that the Guard watches.
# @param [Array<String>] paths the deleted files or paths
# @raise [:task_has_failed] when run_on_change has failed
def run_on_deletion(paths)
end
end
end
Please take a look at the [existing guards' source code](https://github.com/guard/guard/wiki/List-of-available-Guards)
for more concrete example and inspiration.
Alternatively, a new guard can be added inline to a Guardfile with this basic structure:
require 'guard/guard'
module ::Guard
class InlineGuard < ::Guard::Guard
def run_all
end
def run_on_change(paths)
end
end
end
Here is a very cool example by [@avdi](https://github.com/avdi) : [http://avdi.org/devblog/2011/06/15/a-guardfile-for-redis](http://avdi.org/devblog/2011/06/15/a-guardfile-for-redis)
Development
-----------
* Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/guard/master/frames).
* Source hosted at [GitHub](https://github.com/guard/guard).
* Report issues and feature requests to [GitHub Issues](https://github.com/guard/guard/issues).
Pull requests are very welcome! Please try to follow these simple "rules", though:
- Please create a topic branch for every separate change you make;
- Make sure your patches are well tested;
- Update the README (if applicable);
- Update the CHANGELOG (maybe not for a typo but don't hesitate!);
- Please **do not change** the version number.
For questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard` (irc.freenode.net).
Author
------
[Thibaud Guillaume-Gentil](https://github.com/thibaudgg)
Contributors
------------
[https://github.com/guard/guard/contributors](https://github.com/guard/guard/contributors)

View File

@ -1,204 +0,0 @@
= Guard
Guard is a command line tool to easly handle events on files modifications.
== Features
- {FSEvent}[http://en.wikipedia.org/wiki/FSEvents] support on Mac OS X 10.5+ (without RubyCocoa!, {rb-fsevent gem, >= 0.3.5}[https://rubygems.org/gems/rb-fsevent] required)
- {Inotify}[http://en.wikipedia.org/wiki/Inotify] support on Linux ({rb-inotify gem, >= 0.5.1}[https://rubygems.org/gems/rb-inotify] required)
- Polling for others (help us to support more systems)
- Super fast change detection (when polling not used)
- Automatic files modifications detection (even new files are detected)
- Growl notification ({growlnotify}[http://growl.info/documentation/growlnotify.php] & {growl gem}[https://rubygems.org/gems/growl] required)
- Libnotify notification ({libnotify gem}[https://rubygems.org/gems/libnotify] required)
- Tested on Ruby 1.8.6, 1.8.7 & 1.9.2
== Install
Install the gem:
gem install guard
Add it to your Gemfile (inside test group):
gem 'guard'
Generate an empty Guardfile with:
guard init
Add guard(s) you need (see available guards below)
=== On Mac OS X
Install rb-fsevent for {FSEvent}[http://en.wikipedia.org/wiki/FSEvents] support
gem install rb-fsevent
Install growl for Growl notification support
gem install growl
And add it to you Gemfile
gem 'growl'
=== On Linux
Install rb-inotify for {inotify}[http://en.wikipedia.org/wiki/Inotify] support
gem install rb-inotify
Install libnotify for libonity notification support
gem install libnotify
And add it to you Gemfile
gem 'libnotify'
== Usage
Just launch Guard inside your ruby/rails project with:
guard
Shell can be cleared after each change with:
guard -c
Options list is available with:
guard help [TASK]
Signal handlers are used to interact with Guard:
- Ctrl-C - Quit Guard (call stop guard(s) method before)
- Ctrl-\ - Call run_all guard(s) method
- Ctrl-Z - Call reload guard(s) method
== Available Guards
- {guard-bundler}[http://github.com/guard/guard-bundler] by {Yann Lugrin}[http://github.com/yannlugrin]
- {guard-coffeescript}[http://github.com/guard/guard-coffeescript] by {Michael Kessler}[http://github.com/netzpirat]
- {guard-compass}[http://github.com/guard/guard-compass] by {Olivier Amblet}[http://github.com/oliamb]
- {guard-cucumber}[http://github.com/guard/guard-cucumber] by {Michael Kessler}[http://github.com/netzpirat]
- {guard-livereload}[http://github.com/guard/guard-livereload] by {Thibaud Guillaume-Gentil}[http://github.com/thibaudgg]
- {guard-minitest}[http://github.com/guard/guard-minitest] by {Yann Lugrin}[http://github.com/yannlugrin]
- {guard-nanoc}[http://github.com/guard/guard-nanoc] by {Yann Lugrin}[http://github.com/yannlugrin]
- {guard-passenger}[http://github.com/guard/guard-passenger] by {Fabio Kuhn}[http://github.com/mordaroso]
- {guard-rspec}[http://github.com/guard/guard-rspec] by {Thibaud Guillaume-Gentil}[http://github.com/thibaudgg]
- {guard-sass}[http://github.com/guard/guard-sass] by {Joshua Hawxwell}[http://github.com/hawx]
- {guard-shell}[http://github.com/guard/guard-shell] by {Joshua Hawxwell}[http://github.com/hawx]
- {guard-test}[http://github.com/guard/guard-test] by {Rémy Coutable}[http://github.com/rymai]
guard ideas:
- guard-spork
- others ideas?
=== Add a guard to your Guardfile
Add it to your Gemfile (inside test group):
gem '<guard-name>'
Add guard definition to your Guardfile by running this command:
guard init <guard-name>
You are good to go!
== Create a guard
Create a new guard is very easy, just create a new gem with this basic structure:
lib/
guard/
guard-name/
templates/
Guardfile (needed for guard init <guard-name>)
guard-name.rb
lib/guard/guard-name.rb inherit from guard/guard and should overwrite at least one of the five guard methods. Example:
require 'guard'
require 'guard/guard'
module Guard
class GuardName < Guard
def initialize(watchers = [], options = {})
super
# init stuff here, thx!
end
# ================
# = Guard method =
# ================
# If one of those methods raise an exception, the Guard instance
# will be removed from the active guard.
# Call once when guard starts
# Please override initialize method to init stuff
def start
true
end
# Call with Ctrl-C signal (when Guard quit)
def stop
true
end
# Call with Ctrl-Z signal
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
def reload
true
end
# Call with Ctrl-/ signal
# This method should be principally used for long action like running all specs/tests/...
def run_all
true
end
# Call on file(s) modifications
def run_on_change(paths)
true
end
end
end
Looks at available guards code for more concrete example.
== Guardfile DSL
Guardfile DSL consists of just two simple methods: guard & watch. Example:
guard 'rspec', :version => 2 do
watch('^spec/(.*)_spec.rb')
watch('^lib/(.*)\.rb') { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('^spec/spec_helper.rb') { "spec" }
watch('^spec/spec_helper.rb') { `say hello` }
end
- "guard" method allow to add a guard with an optional options hash
- "watch" method allow to define which files are supervised per this guard. A optional block can be added to overwrite path sending to run_on_change guard method or launch simple command.
== TODO
- Add more specs! Shame on me :)
== Development
- Source hosted at {GitHub}[http://github.com/guard/guard]
- Report issues/Questions/Feature requests on {GitHub Issues}[http://github.com/guard/guard/issues]
Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change
you make.
== Authors
{Thibaud Guillaume-Gentil}[http://github.com/thibaudgg]

View File

@ -5,17 +5,44 @@ require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
require 'rbconfig'
namespace(:spec) do
desc "Run all specs on multiple ruby versions (requires rvm)"
task(:portability) do
%w[1.8.6 1.8.7 1.9.2].each do |version|
system <<-BASH
bash -c 'source ~/.rvm/scripts/rvm;
rvm #{version};
echo "--------- version #{version} ----------\n";
bundle install;
rake spec'
BASH
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/i
desc "Run all specs on multiple ruby versions (requires pik)"
task(:portability) do
%w[187 192 161].each do |version|
system "cmd /c echo -----------#{version}------------ & " +
"pik use #{version} & " +
"bundle install & " +
"bundle exec rspec spec"
end
end
else
desc "Run all specs on multiple ruby versions (requires rvm)"
task(:portability) do
travis_config_file = File.expand_path("../.travis.yml", __FILE__)
begin
travis_options ||= YAML::load_file(travis_config_file)
rescue => ex
puts "Travis config file '#{travis_config_file}' could not be found: #{ex.message}"
return
end
travis_options['rvm'].each do |version|
system <<-BASH
bash -c 'source ~/.rvm/scripts/rvm;
rvm #{version};
ruby_version_string_size=`ruby -v | wc -m`
echo;
for ((c=1; c<$ruby_version_string_size; c++)); do echo -n "="; done
echo;
echo "`ruby -v`";
for ((c=1; c<$ruby_version_string_size; c++)); do echo -n "="; done
echo;
RBXOPT="-Xrbc.db" bundle install;
RBXOPT="-Xrbc.db" bundle exec rspec spec -f doc 2>&1;'
BASH
end
end
end
end
end

View File

@ -3,4 +3,4 @@
require 'guard'
require 'guard/cli'
Guard::CLI.start
Guard::CLI.start

View File

@ -1,6 +1,5 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path('../lib', __FILE__)
require 'guard/version'
Kernel.load File.expand_path('../lib/guard/version.rb', __FILE__)
Gem::Specification.new do |s|
s.name = 'guard'
@ -8,21 +7,22 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.authors = ['Thibaud Guillaume-Gentil']
s.email = ['thibaud@thibaud.me']
s.homepage = 'http://rubygems.org/gems/guard'
s.summary = 'Guard keep an eye on your files modifications.'
s.description = 'Guard is a command line tool to easily handle events on files modifications.'
s.homepage = 'https://github.com/guard/guard'
s.summary = 'Guard keeps an eye on your file modifications'
s.description = 'Guard is a command line tool to easily handle events on file system modifications.'
s.required_rubygems_version = '>= 1.3.6'
s.rubyforge_project = 'guard'
s.add_development_dependency 'bundler', '~> 1.0.3'
s.add_development_dependency 'rspec', '~> 2.0.1'
s.add_development_dependency 'guard-rspec', '~> 0.1.4'
s.add_dependency 'thor', '~> 0.14.3'
s.add_dependency 'open_gem', '~> 1.4.2'
s.files = Dir.glob('{bin,images,lib}/**/*') + %w[LICENSE README.rdoc]
s.add_dependency 'thor', '~> 0.14.6'
s.add_development_dependency 'bundler'
s.add_development_dependency 'rspec', '~> 2.6.0'
s.add_development_dependency 'guard-rspec', '~> 0.3.1'
s.add_development_dependency 'yard', '~> 0.7.2'
s.add_development_dependency 'kramdown', '~> 0.13.3'
s.files = Dir.glob('{bin,images,lib}/**/*') + %w[CHANGELOG.md LICENSE man/guard.1 man/guard.1.html README.md]
s.executable = 'guard'
s.require_path = 'lib'
end
end

View File

@ -1,91 +1,436 @@
require 'bundler'
require 'thread'
# Guard is the main module for all Guard related modules and classes.
# Also other Guard implementation should use this namespace.
#
module Guard
autoload :UI, 'guard/ui'
autoload :Dsl, 'guard/dsl'
autoload :Interactor, 'guard/interactor'
autoload :Listener, 'guard/listener'
autoload :Watcher, 'guard/watcher'
autoload :Notifier, 'guard/notifier'
autoload :UI, 'guard/ui'
autoload :Dsl, 'guard/dsl'
autoload :DslDescriber, 'guard/dsl_describer'
autoload :Group, 'guard/group'
autoload :Interactor, 'guard/interactor'
autoload :Listener, 'guard/listener'
autoload :Watcher, 'guard/watcher'
autoload :Notifier, 'guard/notifier'
autoload :Hook, 'guard/hook'
class << self
attr_accessor :options, :guards, :listener
# initialize this singleton
def init(options = {})
@options = options
@listener = Listener.init
@guards = []
return self
end
def start(options = {})
init options
Dsl.evaluate_guardfile
if guards.empty?
UI.error "No guards found in Guardfile, please add at least one."
attr_accessor :options, :interactor, :listener, :lock
# Creates the initial Guardfile template or add a Guard implementation
# Guardfile template to an existing Guardfile.
#
# @see Guard::Guard.init
#
# @param [String] guard_name the name of the Guard to initialize
#
def initialize_template(guard_name = nil)
if guard_name
guard_class = ::Guard.get_guard_class(guard_name)
guard_class.init(guard_name)
else
Interactor.init_signal_traps
listener.on_change do |files|
run do
guards.each do |guard|
paths = Watcher.match_files(guard, files)
supervised_task(guard, :run_on_change, paths) unless paths.empty?
if !File.exist?('Guardfile')
::Guard::UI.info "Writing new Guardfile to #{ Dir.pwd }/Guardfile"
FileUtils.cp(File.expand_path('../templates/Guardfile', __FILE__), 'Guardfile')
else
::Guard::UI.error "Guardfile already exists at #{ Dir.pwd }/Guardfile"
exit 1
end
end
end
# Initialize the Guard singleton.
#
# @option options [Boolean] clear if auto clear the UI should be done
# @option options [Boolean] notify if system notifications should be shown
# @option options [Boolean] debug if debug output should be shown
# @option options [Array<String>] group the list of groups to start
# @option options [String] watchdir the director to watch
# @option options [String] guardfile the path to the Guardfile
# @option options [Boolean] watch_all_modifications watches all file modifications if true
#
def setup(options = {})
@lock = Mutex.new
@options = options
@guards = []
@groups = [Group.new(:default)]
@interactor = Interactor.new unless @options[:no_interactions]
@listener = Listener.select_and_init(@options[:watchdir] ? File.expand_path(@options[:watchdir]) : Dir.pwd, 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
# Smart accessor for retrieving a specific guard or several guards at once.
#
# @param [String, Symbol] filter return the guard with the given name, or nil if not found
# @param [Regexp] filter returns all guards matching the Regexp, or [] if no guard found
# @param [Hash] filter returns all guards matching the given Hash.
# Example: `{ :name => 'rspec', :group => 'backend' }`, or [] if no guard found
# @param [NilClass] filter returns all guards
#
# @see Guard.groups
#
def guards(filter = nil)
case filter
when String, Symbol
@guards.find { |guard| guard.class.to_s.downcase.sub('guard::', '') == filter.to_s.downcase.gsub('-', '') }
when Regexp
@guards.find_all { |guard| guard.class.to_s.downcase.sub('guard::', '') =~ filter }
when Hash
filter.inject(@guards) do |matches, (k, v)|
if k.to_sym == :name
matches.find_all { |guard| guard.class.to_s.downcase.sub('guard::', '') == v.to_s.downcase.gsub('-', '') }
else
matches.find_all { |guard| guard.send(k).to_sym == v.to_sym }
end
end
else
@guards
end
end
# Smart accessor for retrieving a specific group or several groups at once.
#
# @param [NilClass] filter returns all groups
# @param [String, Symbol] filter return the group with the given name, or nil if not found
# @param [Regexp] filter returns all groups matching the Regexp, or [] if no group found
#
# @see Guard.guards
#
def groups(filter = nil)
case filter
when String, Symbol
@groups.find { |group| group.name == filter.to_sym }
when Regexp
@groups.find_all { |group| group.name.to_s =~ filter }
else
@groups
end
end
# Start Guard by evaluate the `Guardfile`, initialize the declared Guards
# and start the available file change listener.
#
# @option options [Boolean] clear if auto clear the UI should be done
# @option options [Boolean] notify if system notifications should be shown
# @option options [Boolean] debug if debug output should be shown
# @option options [Array<String>] group the list of groups to start
# @option options [String] watchdir the director to watch
# @option options [String] guardfile the path to the Guardfile
#
def start(options = {})
setup(options)
Dsl.evaluate_guardfile(options)
listener.on_change do |files|
Dsl.reevaluate_guardfile if Watcher.match_guardfile?(files)
listener.changed_files += files if Watcher.match_files?(guards, files)
end
UI.info "Guard is now watching at '#{ listener.directory }'"
run_guard_task(:start)
interactor.start if interactor
listener.start
end
# Stop Guard listening to file changes
#
def stop
UI.info 'Bye bye...', :reset => true
run_guard_task(:stop)
listener.stop
abort
end
# Reload all Guards currently enabled.
#
def reload
run do
run_guard_task(:reload)
end
end
# Trigger `run_all` on all Guards currently enabled.
#
def run_all
run do
run_guard_task(:run_all)
end
end
# Pause Guard listening to file changes.
#
def pause
if listener.paused?
UI.info 'Un-paused files modification listening', :reset => true
listener.clear_changed_files
listener.run
else
UI.info 'Paused files modification listening', :reset => true
listener.pause
end
end
# Trigger `run_on_change` on all Guards currently enabled.
#
def run_on_change(paths)
run do
run_guard_task(:run_on_change, paths)
end
end
# Run a block where the listener and the interactor is
# blocked.
#
# @yield the block to run
#
def run
UI.clear if options[:clear]
lock.synchronize do
begin
interactor.stop_if_not_current if interactor
yield
rescue Interrupt
end
interactor.start if interactor
end
end
# Loop through all groups and run the given task for each Guard.
#
# Stop the task run for the all Guards within a group if one Guard
# throws `:task_has_failed`.
#
# @param [Symbol] task the task to run
# @param [Array<String>] files the list of files to pass to the task
#
def run_guard_task(task, files = nil)
groups.each do |group|
catch :task_has_failed do
guards(:group => group.name).each do |guard|
if task == :run_on_change
run_on_change_task(files, guard, task)
else
run_supervised_task(guard, task)
end
end
end
UI.info "Guard is now watching at '#{Dir.pwd}'"
guards.each { |g| supervised_task(g, :start) }
listener.start
end
end
def add_guard(name, watchers = [], options = {})
guard_class = get_guard_class(name)
@guards << guard_class.new(watchers, options)
# Run the `:run_on_change` task. When the option `:watch_all_modifications` is set,
# the task is split to run changed paths on {Guard::Guard#run_on_change}, whereas
# deleted paths run on {Guard::Guard#run_on_deletion}.
#
# @param [Array<String>] files the list of files to pass to the task
# @param [Guard::Guard] guard the guard to run
# @param [Symbol] task the task to run
# @raise [:task_has_failed] when task has failed
#
def run_on_change_task(files, guard, task)
paths = Watcher.match_files(guard, files)
changes = changed_paths(paths)
deletions = deleted_paths(paths)
unless changes.empty?
UI.debug "#{ guard.class.name }##{ task } with #{ changes.inspect }"
run_supervised_task(guard, task, changes)
end
unless deletions.empty?
UI.debug "#{ guard.class.name }#run_on_deletion with #{ deletions.inspect }"
run_supervised_task(guard, :run_on_deletion, deletions)
end
end
# Detects the paths that have changed.
#
# Deleted paths are prefixed by an exclamation point.
# @see Guard::Listener#modified_files
#
# @param [Array<String>] paths the watched paths
# @return [Array<String>] the changed paths
#
def changed_paths(paths)
paths.select { |f| !f.start_with?('!') }
end
# Detects the paths that have been deleted.
#
# Deleted paths are prefixed by an exclamation point.
# @see Guard::Listener#modified_files
#
# @param [Array<String>] paths the watched paths
# @return [Array<String>] the deleted paths
#
def deleted_paths(paths)
paths.select { |f| f.start_with?('!') }.map { |f| f.slice(1..-1) }
end
# Run a Guard task, but remove the Guard when his work leads to a system failure.
#
# When the Group has `:halt_on_fail` disabled, we've to catch `:task_has_failed`
# here in order to avoid an uncaught throw error.
#
# @param [Guard::Guard] guard the Guard to execute
# @param [Symbol] task the task to run
# @param [Array] args the arguments for the task
# @raise [:task_has_failed] when task has failed
#
def run_supervised_task(guard, task, *args)
catch guard_symbol(guard) do
guard.hook("#{ task }_begin", *args)
result = guard.send(task, *args)
guard.hook("#{ task }_end", result)
result
end
rescue Exception => ex
UI.error("#{ guard.class.name } failed to achieve its <#{ task.to_s }>, exception was:" +
"\n#{ ex.class }: #{ ex.message }\n#{ ex.backtrace.join("\n") }")
guards.delete guard
UI.info("\n#{ guard.class.name } has just been fired")
ex
end
# Get the symbol we have to catch when running a supervised task.
# If we are within a Guard group that has the `:halt_on_fail`
# option set, we do NOT catch it here, it will be catched at the
# group level.
#
# @see .run_guard_task
#
# @param [Guard::Guard] guard the Guard to execute
# @return [Symbol] the symbol to catch
#
def guard_symbol(guard)
if guard.group.class == Symbol
group = groups(guard.group)
group.options[:halt_on_fail] ? :no_catch : :task_has_failed
else
:task_has_failed
end
end
# Add a Guard to use.
#
# @param [String] name the Guard name
# @param [Array<Watcher>] watchers the list of declared watchers
# @param [Array<Hash>] callbacks the list of callbacks
# @param [Hash] options the Guard options (see the given Guard documentation)
#
def add_guard(name, watchers = [], callbacks = [], options = {})
if name.to_sym == :ego
UI.deprecation('Guard::Ego is now part of Guard. You can remove it from your Guardfile.')
else
guard_class = get_guard_class(name)
callbacks.each { |callback| Hook.add_callback(callback[:listener], guard_class, callback[:events]) }
@guards << guard_class.new(watchers, options)
end
end
# Add a Guard group.
#
# @param [String] name the group name
# @option options [Boolean] halt_on_fail if a task execution
# should be halted for all Guards in this group if one Guard throws `:task_has_failed`
# @return [Guard::Group] the group added (or retrieved from the `@groups` variable if already present)
#
def add_group(name, options = {})
group = groups(name)
if group.nil?
group = Group.new(name, options)
@groups << group
end
group
end
# Tries to load the Guard main class.
#
# @param [String] name the name of the Guard
# @return [Class, nil] the loaded class
#
def get_guard_class(name)
require "guard/#{name.downcase}"
klasses = []
ObjectSpace.each_object(Class) do |klass|
klasses << klass if klass.to_s.downcase.match "^guard::#{name.downcase}"
end
klasses.first
rescue LoadError
UI.error "Could not find gem 'guard-#{name}' in the current Gemfile."
end
# Let a guard execute his task but
# fire it if his work lead to system failure
def supervised_task(guard, task_to_supervise, *args)
guard.send(task_to_supervise, *args)
rescue Exception
UI.error("#{guard.class.name} guard failed to achieve its <#{task_to_supervise.to_s}> command: #{$!}")
::Guard.guards.delete guard
UI.info("Guard #{guard.class.name} has just been fired")
return $!
end
def locate_guard(name)
`gem open guard-#{name} --latest --command echo`.chomp
rescue
UI.error "Could not find 'guard-#{name}' gem path."
end
def run
listener.stop
UI.clear if options[:clear]
name = name.to_s
try_require = false
const_name = name.downcase.gsub('-', '')
begin
yield
rescue Interrupt
require "guard/#{ name.downcase }" if try_require
self.const_get(self.constants.find { |c| c.to_s.downcase == const_name })
rescue TypeError
unless try_require
try_require = true
retry
else
UI.error "Could not find class Guard::#{ const_name.capitalize }"
end
rescue LoadError => loadError
UI.error "Could not load 'guard/#{ name.downcase }' or find class Guard::#{ const_name.capitalize }"
UI.error loadError.to_s
end
listener.start
end
# Locate a path to a Guard gem.
#
# @param [String] name the name of the Guard without the prefix `guard-`
# @return [String] the full path to the Guard gem
#
def locate_guard(name)
if Gem::Version.create(Gem::VERSION) >= Gem::Version.create('1.8.0')
Gem::Specification.find_by_name("guard-#{ name }").full_gem_path
else
Gem.source_index.find_name("guard-#{ name }").last.full_gem_path
end
rescue
UI.error "Could not find 'guard-#{ name }' gem path."
end
# Returns a list of guard Gem names installed locally.
#
# @return [Array<String>] a list of guard gem names
#
def guard_gem_names
if Gem::Version.create(Gem::VERSION) >= Gem::Version.create('1.8.0')
Gem::Specification.find_all.select { |x| x.name =~ /^guard-/ }
else
Gem.source_index.find_name(/^guard-/)
end.map { |x| x.name.sub /^guard-/, '' }
end
# Adds a command logger in debug mode. This wraps common command
# execution functions and logs the executed command before execution.
#
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
end

View File

@ -2,37 +2,118 @@ require 'thor'
require 'guard/version'
module Guard
# Facade for the Guard command line interface managed by [Thor](https://github.com/wycats/thor).
# This is the main interface to Guard that is called by the Guard binary `bin/guard`.
# Do not put any logic in here, create a class and delegate instead.
#
class CLI < Thor
default_task :start
desc "start", "Starts guard"
method_option :clear, :type => :boolean, :default => false, :aliases => '-c', :banner => "Auto clear shell before each change/run_all/reload"
method_option :debug, :type => :boolean, :default => false, :aliases => '-d', :banner => "Print debug messages"
desc 'start', 'Starts Guard'
method_option :clear,
:type => :boolean,
:default => false,
:aliases => '-c',
:banner => 'Auto clear shell before each change/run_all/reload'
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 :group,
:type => :array,
:default => [],
:aliases => '-g',
:banner => 'Run only the passed groups'
method_option :watchdir,
:type => :string,
:aliases => '-w',
:banner => 'Specify the directory to watch'
method_option :guardfile,
:type => :string,
:aliases => '-G',
:banner => 'Specify a Guardfile'
method_option :watch_all_modifications,
:type => :boolean,
:default => false,
:aliases => '-A',
:banner => 'Watch for all file modifications including moves and deletions'
method_option :no_interactions,
:type => :boolean,
:default => false,
:aliases => '-i',
:banner => 'Turn off completely any guard terminal interactions'
# Start Guard by initialize the defined Guards and watch the file system.
# This is the default task, so calling `guard` is the same as calling `guard start`.
#
# @see Guard.start
#
def start
::Guard.start(options)
end
desc "version", "Prints the guard's version information"
def version
::Guard::UI.info "Guard version #{Guard::VERSION}"
desc 'list', 'Lists guards that can be used with init'
# List the Guards that are available for use in your system and marks
# those that are currently used in your `Guardfile`.
#
# @see Guard::DslDescriber.list
#
def list
::Guard::DslDescriber.list(options)
end
desc 'version', 'Show the Guard version'
map %w(-v --version) => :version
desc "init [GUARD]", "Generates a Guardfile into the current working directory, or add it given guard"
def init(guard_name = nil)
if !File.exist?("Guardfile")
puts "Writing new Guardfile to #{Dir.pwd}/Guardfile"
FileUtils.cp(File.expand_path('../templates/Guardfile', __FILE__), 'Guardfile')
elsif guard_name.nil?
::Guard::UI.error "Guardfile already exists at #{Dir.pwd}/Guardfile"
exit 1
end
if guard_name
guard_class = ::Guard.get_guard_class(guard_name)
guard_class.init(guard_name)
end
# Shows the current version of Guard.
#
# @see Guard::VERSION
#
def version
::Guard::UI.info "Guard version #{ Guard::VERSION }"
end
desc 'init [GUARD]', 'Generates a Guardfile at the current working directory, or insert the given GUARD to an existing Guardfile'
# Appends the Guard template to the `Guardfile`, or creates an initial
# `Guardfile` when no Guard name is passed.
#
# @see Guard.initialize_template
#
# @param [String] guard_name the name of the Guard to initialize
#
def init(guard_name = nil)
::Guard.initialize_template(guard_name)
end
desc 'show', 'Show all defined Guards and their options'
map %w(-T) => :show
# Shows all Guards and their options that are defined in
# the `Guardfile`.
#
# @see Guard::DslDescriber.show
#
def show
::Guard::DslDescriber.show(options)
end
end
end
end

View File

@ -1,35 +1,370 @@
module Guard
# The DSL class provides the methods that are used in each `Guardfile` to describe
# the behaviour of Guard.
#
# The main keywords of the DSL are `guard` and `watch`. These are necessary to define
# the used Guards and the file changes they are watching.
#
# You can optionally group the Guards with the `group` keyword and ignore certain paths
# with the `ignore_paths` keyword.
#
# A more advanced DSL use is the `callback` keyword that allows you to execute arbitrary
# code before or after any of the `start`, `stop`, `reload`, `run_all` and `run_on_change`
# Guards' method. You can even insert more hooks inside these methods.
# Please [checkout the Wiki page](https://github.com/guard/guard/wiki/Hooks-and-callbacks) for more details.
#
# The DSL will also evaluate normal Ruby code.
#
# There are two possible locations for the `Guardfile`:
# - The `Guardfile` in the current directory where Guard has been started
# - The `.Guardfile` in your home directory.
#
# In addition, if a user configuration `.guard.rb` in your home directory is found, it will
# be appended to the current project `Guardfile`.
#
# @example A sample of a complex Guardfile
#
# group 'frontend' do
# guard 'passenger', :ping => true do
# watch('config/application.rb')
# watch('config/environment.rb')
# watch(%r{^config/environments/.+\.rb})
# watch(%r{^config/initializers/.+\.rb})
# end
#
# guard 'livereload', :apply_js_live => false do
# watch(%r{^app/.+\.(erb|haml)})
# watch(%r{^app/helpers/.+\.rb})
# watch(%r{^public/javascripts/.+\.js})
# watch(%r{^public/stylesheets/.+\.css})
# watch(%r{^public/.+\.html})
# watch(%r{^config/locales/.+\.yml})
# end
# end
#
# group 'backend' do
# # Reload the bundle when the Gemfile is modified
# guard 'bundler' do
# watch('Gemfile')
# end
#
# # for big project you can fine tune the "timeout" before Spork's launch is considered failed
# guard 'spork', :wait => 40 do
# watch('Gemfile')
# watch('config/application.rb')
# watch('config/environment.rb')
# watch(%r{^config/environments/.+\.rb})
# watch(%r{^config/initializers/.+\.rb})
# watch('spec/spec_helper.rb')
# end
#
# # use RSpec 2, from the system's gem and with some direct RSpec CLI options
# guard 'rspec', :version => 2, :cli => "--color --drb -f doc", :bundler => false do
# watch('spec/spec_helper.rb') { "spec" }
# watch('app/controllers/application_controller.rb') { "spec/controllers" }
# watch('config/routes.rb') { "spec/routing" }
# watch(%r{^spec/support/(controllers|acceptance)_helpers\.rb}) { |m| "spec/#{m[1]}" }
# watch(%r{^spec/.+_spec\.rb})
#
# watch(%r{^app/controllers/(.+)_(controller)\.rb}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
#
# watch(%r{^app/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
# watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
# end
# end
#
class Dsl
def self.evaluate_guardfile
guardfile = "#{Dir.pwd}/Guardfile"
if File.exists? guardfile
begin
dsl = new
dsl.instance_eval(File.read(guardfile.to_s), guardfile.to_s, 1)
rescue
UI.error "Invalid Guardfile, original error is:\n#{$!}"
exit 1
end
else
UI.error "No Guardfile in current folder, please create one."
class << self
@@options = nil
# Evaluate the DSL methods in the `Guardfile`.
#
# @option options [Array<Symbol,String>] groups the groups to evaluate
# @option options [String] guardfile the path to a valid Guardfile
# @option options [String] guardfile_contents a string representing the content of a valid Guardfile
# @raise [ArgumentError] when options are not a Hash
#
def evaluate_guardfile(options = {})
raise ArgumentError.new('No option hash passed to evaluate_guardfile!') unless options.is_a?(Hash)
@@options = options.dup
fetch_guardfile_contents
instance_eval_guardfile(guardfile_contents_with_user_config)
UI.error 'No guards found in Guardfile, please add at least one.' if !::Guard.guards.nil? && ::Guard.guards.empty?
end
# Re-evaluate the `Guardfile` to update the current Guard configuration.
#
def reevaluate_guardfile
::Guard.guards.clear
::Guard.groups.clear
@@options.delete(:guardfile_contents)
Dsl.evaluate_guardfile(@@options)
msg = 'Guardfile has been re-evaluated.'
UI.info(msg)
Notifier.notify(msg)
end
# Evaluate the content of the `Guardfile`.
#
# @param [String] contents the content to evaluate.
#
def instance_eval_guardfile(contents)
new.instance_eval(contents, @@options[:guardfile_path], 1)
rescue
UI.error "Invalid Guardfile, original error is:\n#{ $! }"
exit 1
end
# Test if the current `Guardfile` contains a specific Guard.
#
# @param [String] guard_name the name of the Guard
# @return [Boolean] whether the Guard has been declared
#
def guardfile_include?(guard_name)
guardfile_contents.match(/^guard\s*\(?\s*['":]#{ guard_name }['"]?/)
end
# Read the current `Guardfile` content.
#
# @param [String] the path to the Guardfile
#
def read_guardfile(guardfile_path)
@@options[:guardfile_path] = guardfile_path
@@options[:guardfile_contents] = File.read(guardfile_path)
rescue
UI.error("Error reading file #{ guardfile_path }")
exit 1
end
# Get the content to evaluate and stores it into
# the options as `:guardfile_contents`.
#
def fetch_guardfile_contents
if @@options[:guardfile_contents]
UI.info 'Using inline Guardfile.'
@@options[:guardfile_path] = 'Inline Guardfile'
elsif @@options[:guardfile]
if File.exist?(@@options[:guardfile])
read_guardfile(@@options[:guardfile])
UI.info "Using Guardfile at #{ @@options[:guardfile] }."
else
UI.error "No Guardfile exists at #{ @@options[:guardfile] }."
exit 1
end
else
if File.exist?(guardfile_default_path)
read_guardfile(guardfile_default_path)
else
UI.error 'No Guardfile found, please create one with `guard init`.'
exit 1
end
end
unless guardfile_contents_usable?
UI.error "The command file(#{ @@options[:guardfile] }) seems to be empty."
exit 1
end
end
# Get the content of the `Guardfile`.
#
# @return [String] the Guardfile content
#
def guardfile_contents
@@options ? @@options[:guardfile_contents] : ''
end
# Get the content of the `Guardfile` and the global
# user configuration file.
#
# @see #user_config_path
#
# @return [String] the Guardfile content
#
def guardfile_contents_with_user_config
config = File.read(user_config_path) if File.exist?(user_config_path)
[guardfile_contents, config].join("\n")
end
# Get the file path to the project `Guardfile`.
#
# @return [String] the path to the Guardfile
#
def guardfile_path
@@options ? @@options[:guardfile_path] : ''
end
# Tests if the current `Guardfile` content is usable.
#
# @return [Boolean] if the Guardfile is usable
#
def guardfile_contents_usable?
guardfile_contents && guardfile_contents.size >= 'guard :a'.size # Smallest Guard definition
end
# Gets the default path of the `Guardfile`. This returns the `Guardfile`
# from the current directory when existing, or the global `.Guardfile`
# at the home directory.
#
# @return [String] the path to the Guardfile
#
def guardfile_default_path
File.exist?(local_guardfile_path) ? local_guardfile_path : home_guardfile_path
end
private
# The path to the `Guardfile` that is located at
# the directory, where Guard has been started from.
#
# @param [String] the path to the local Guardfile
#
def local_guardfile_path
File.join(Dir.pwd, 'Guardfile')
end
# The path to the `.Guardfile` that is located at
# the users home directory.
#
# @param [String] the path to ~/.Guardfile
#
def home_guardfile_path
File.expand_path(File.join('~', '.Guardfile'))
end
# The path to the user configuration `.guard.rb`
# that is located at the users home directory.
#
# @param [String] the path to ~/.guard.rb
#
def user_config_path
File.expand_path(File.join('~', '.guard.rb'))
end
end
def self.guardfile_included?(guard_name)
File.read('Guardfile').include?("guard '#{guard_name}'")
# Declares a group of guards to be run with `guard start --group group_name`.
#
# @example Declare two groups of Guards
#
# group 'backend' do
# guard 'spork'
# guard 'rspec'
# end
#
# group 'frontend' do
# guard 'passenger'
# guard 'livereload'
# end
#
# @param [Symbol, String] name the group's name called from the CLI
# @param [Hash] options the options accepted by the group
# @yield a block where you can declare several guards
#
# @see Guard.add_group
# @see Dsl#guard
# @see Guard::DslDescriber
#
def group(name, options = {})
@groups = @@options[:group] || []
name = name.to_sym
if block_given? && (@groups.empty? || @groups.map(&:to_sym).include?(name))
::Guard.add_group(name.to_s.downcase, options)
@current_group = name
yield if block_given?
@current_group = nil
end
end
def guard(name, options = {}, &definition)
@watchers = []
definition.call if definition
::Guard.add_guard(name, @watchers, options)
# Declare a guard to be used when running `guard start`.
#
# The name parameter is usually the name of the gem without
# the 'guard-' prefix.
#
# The available options are different for each Guard implementation.
#
# @example Declare a Guard
#
# guard 'rspec' do
# end
#
# @param [String] name the Guard name
# @param [Hash] options the options accepted by the Guard
# @yield a block where you can declare several watch patterns and actions
#
# @see Guard.add_guard
# @see Dsl#group
# @see Dsl#watch
# @see Guard::DslDescriber
#
def guard(name, options = {})
@watchers = []
@callbacks = []
yield if block_given?
options.update(:group => (@current_group || :default))
::Guard.add_guard(name.to_s.downcase, @watchers, @callbacks, options)
end
# Define a pattern to be watched in order to run actions on file modification.
#
# @example Declare watchers for a Guard
#
# guard 'rspec' do
# watch('spec/spec_helper.rb')
# watch(%r{^.+_spec.rb})
# watch(%r{^app/controllers/(.+).rb}) { |m| 'spec/acceptance/#{m[1]}s_spec.rb' }
# end
#
# @param [String, Regexp] pattern the pattern to be watched by the guard
# @yield a block to be run when the pattern is matched
# @yieldparam [MatchData] m matches of the pattern
# @yieldreturn a directory, a filename, an array of directories / filenames, or nothing (can be an arbitrary command)
#
# @see Guard::Watcher
# @see Dsl#guard
#
def watch(pattern, &action)
@watchers << ::Guard::Watcher.new(pattern, action)
end
# Define a callback to execute arbitrary code before or after any of
# the `start`, `stop`, `reload`, `run_all` and `run_on_change` guards' method.
#
# @param [Array] args the callback arguments
# @yield a block with listeners
#
# @see Guard::Hook
#
def callback(*args, &listener)
listener, events = args.size > 1 ? args : [listener, args[0]]
@callbacks << { :events => events, :listener => listener }
end
# Ignore certain paths globally.
#
# @example Ignore some paths
# ignore_paths ".git", ".svn"
#
# @param [Array] paths the list of paths to ignore
#
# @see Guard::Listener
#
def ignore_paths(*paths)
UI.info "Ignoring paths: #{ paths.join(', ') }"
::Guard.listener.ignore_paths.push(*paths)
end
end
end

150
lib/guard/dsl_describer.rb Normal file
View File

@ -0,0 +1,150 @@
require 'guard/dsl'
module Guard
autoload :UI, 'guard/ui'
# The DslDescriber overrides methods to create an internal structure
# of the Guardfile that is used in some inspection utility methods
# like the CLI commands `show` and `list`.
#
# @see Guard::Dsl
# @see Guard::CLI
#
class DslDescriber < Dsl
class << self
# Evaluate the DSL methods in the `Guardfile`.
#
# @option options [Array<Symbol,String>] groups the groups to evaluate
# @option options [String] guardfile the path to a valid Guardfile
# @option options [String] guardfile_contents a string representing the content of a valid Guardfile
# @raise [ArgumentError] when options are not a Hash
#
def evaluate_guardfile(options = {})
@@guardfile_structure = [{ :guards => [] }]
super options
end
# List the Guards that are available for use in your system and marks
# those that are currently used in your `Guardfile`.
#
# @example Guard list output
#
# Available guards:
# bundler *
# livereload
# ronn
# rspec *
# spork
#
# See also https://github.com/guard/guard/wiki/List-of-available-Guards
# * denotes ones already in your Guardfile
#
# @param [Hash] options the Guard options
#
def list(options)
evaluate_guardfile(options)
installed = guardfile_structure.inject([]) do |installed, group|
group[:guards].each { |guard| installed << guard[:name] } if group[:guards]
installed
end
UI.info 'Available guards:'
::Guard.guard_gem_names.sort.uniq.each do |name|
UI.info " #{ name }#{ installed.include?(name) ? '*' : '' }"
end
UI.info ''
UI.info 'See also https://github.com/guard/guard/wiki/List-of-available-Guards'
UI.info '* denotes ones already in your Guardfile'
end
# Shows all Guards and their options that are defined in
# the `Guardfile`.
#
# @example guard show output
#
# (global):
# bundler
# coffeescript: input => "app/assets/javascripts", noop => true
# jasmine
# rspec: cli => "--fail-fast --format Fuubar
#
# @param [Hash] options the Guard options
#
def show(options)
evaluate_guardfile(options)
guardfile_structure.each do |group|
unless group[:guards].empty?
if group[:group]
UI.info "Group #{ group[:group] }:"
else
UI.info '(global):'
end
group[:guards].each do |guard|
line = " #{ guard[:name] }"
unless guard[:options].empty?
line += ": #{ guard[:options].sort.collect { |k, v| "#{ k } => #{ v.inspect }" }.join(', ') }"
end
UI.info line
end
end
end
UI.info ''
end
private
# Get the Guardfile structure.
#
# @return [Array<Hash>] the structure
#
def guardfile_structure
@@guardfile_structure
end
end
private
# Declares a group of guards.
#
# @param [String] name the group's name called from the CLI
# @yield a block where you can declare several guards
#
# @see Guard::Dsl#group
#
def group(name)
@@guardfile_structure << { :group => name.to_sym, :guards => [] }
@group = true
yield if block_given?
@group = false
end
# Declares a Guard.
#
# @param [String] name the Guard name
# @param [Hash] options the options accepted by the Guard
# @yield a block where you can declare several watch patterns and actions
#
# @see Guard::Dsl#guard
#
def guard(name, options = { })
node = (@group ? @@guardfile_structure.last : @@guardfile_structure.first)
node[:guards] << { :name => name, :options => options }
end
end
end

37
lib/guard/group.rb Normal file
View File

@ -0,0 +1,37 @@
module Guard
# A group of Guards. There are two reasons why you want to group your guards:
#
# - You can start only certain Groups from the command line by passing the `--group` option.
# - Abort task execution chain on failure within a group.
#
# @example Group that aborts on failure
#
# group :frontend, :halt_on_fail => true do
# guard 'coffeescript', :input => 'spec/coffeescripts', :output => 'spec/javascripts'
# guard 'jasmine-headless-webkit' do
# watch(%r{^spec/javascripts/(.*)\..*}) { |m| newest_js_file("spec/javascripts/#{m[1]}_spec") }
# end
# end
#
# @see Guard::CLI
#
class Group
attr_accessor :name, :options
# Initialize a Group.
#
# @param [String] name the name of the group
# @param [Hash] options the group options
# @option options [Boolean] halt_on_fail if a task execution
# should be halted for all Guards in this group if one Guard throws `:task_has_failed`
#
def initialize(name, options = {})
@name = name.to_sym
@options = options
end
end
end

View File

@ -1,55 +1,129 @@
module Guard
# Main class that every Guard implementation must subclass.
#
# Guard will trigger the `start`, `stop`, `reload`, `run_all`, `run_on_change` and
# `run_on_deletion` task methods depending on user interaction and file modification.
#
# In each of these Guard task methods you have to implement some work when you want to
# support this kind of task. The return value of each Guard task method is not evaluated
# by Guard, but I'll be passed to the "_end" hook for further evaluation. You can
# throw `:task_has_failed` to indicate that your Guard method was not successful,
# and successive guard tasks will be aborted when the group has set the `:halt_on_fail`
# option.
#
# @see Guard::Hook
# @see Guard::Group
#
# @example Throw :task_has_failed
#
# def run_all
# if !runner.run(['all'])
# throw :task_has_failed
# end
# end
#
# Each Guard should provide a template Guardfile located within the Gem
# at `lib/guard/guard-name/templates/Guardfile`.
#
# By default all watchers for a Guard are returning strings of paths to the
# Guard, but if your Guard want to allow any return value from a watcher,
# you can set the `any_return` option to true.
#
# If one of those methods raise an exception other than `:task_has_failed`,
# the Guard::GuardName instance will be removed from the active guards.
#
class Guard
attr_accessor :watchers, :options
include Hook
attr_accessor :watchers, :options, :group
# Initialize a Guard.
#
# @param [Array<Guard::Watcher>] watchers the Guard file watchers
# @param [Hash] options the custom Guard options
# @options [Symbol] group the group this Guard belongs to
# @options [Boolean] any_return allow any object to be returned from a watcher
#
def initialize(watchers = [], options = {})
@group = options[:group] ? options.delete(:group).to_sym : :default
@watchers, @options = watchers, options
end
# Guardfile template needed inside guard gem
# Initialize the Guard. This will copy the Guardfile template inside the Guard gem.
# The template Guardfile must be located within the Gem at `lib/guard/guard-name/templates/Guardfile`.
#
# @param [String] name the name of the Guard
#
def self.init(name)
if ::Guard::Dsl.guardfile_included?(name)
::Guard::UI.info "Guardfile already include #{name} guard"
if ::Guard::Dsl.guardfile_include?(name)
::Guard::UI.info "Guardfile already includes #{ name } guard"
else
content = File.read('Guardfile')
guard = File.read("#{::Guard.locate_guard(name)}/lib/guard/#{name}/templates/Guardfile")
guard = File.read("#{ ::Guard.locate_guard(name) }/lib/guard/#{ name }/templates/Guardfile")
File.open('Guardfile', 'wb') do |f|
f.puts content
f.puts ""
f.puts guard
f.puts(content)
f.puts("")
f.puts(guard)
end
::Guard::UI.info "#{name} guard added to Guardfile, feel free to edit it"
::Guard::UI.info "#{ name } guard added to Guardfile, feel free to edit it"
end
end
# ================
# = Guard method =
# ================
# Call once when guard starts
# Please override initialize method to init stuff
# Call once when Guard starts. Please override initialize method to init stuff.
#
# @raise [:task_has_failed] when start has failed
# @return [Object] the task result
#
def start
true
end
# Call once when guard quit
# Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
#
# @raise [:task_has_failed] when stop has failed
# @return [Object] the task result
#
def stop
true
end
# Should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
# Called when `reload|r|z + enter` is pressed.
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
#
# @raise [:task_has_failed] when reload has failed
# @return [Object] the task result
#
def reload
true
end
# Should be principally used for long action like running all specs/tests/...
# Called when just `enter` is pressed
# This method should be principally used for long action like running all specs/tests/...
#
# @raise [:task_has_failed] when run_all has failed
# @return [Object] the task result
#
def run_all
true
end
# Called on file(s) modifications that the Guard watches.
#
# @param [Array<String>] paths the changes files or paths
# @raise [:task_has_failed] when run_on_change has failed
# @return [Object] the task result
#
def run_on_change(paths)
true
end
# Called on file(s) deletions that the Guard watches.
#
# @param [Array<String>] paths the deleted files or paths
# @raise [:task_has_failed] when run_on_change has failed
# @return [Object] the task result
#
def run_on_deletion(paths)
end
end
end
end

118
lib/guard/hook.rb Normal file
View File

@ -0,0 +1,118 @@
module Guard
# Guard has a hook mechanism that allows you to insert callbacks for individual Guards.
# By default, each of the Guard instance methods has a "_begin" and an "_end" hook.
# For example, the Guard::Guard#start method has a :start_begin hook that is runs immediately
# before Guard::Guard#start, and a :start_end hook that runs immediately after Guard::Guard#start.
#
# Read more about [hooks and callbacks on the wiki](https://github.com/guard/guard/wiki/Hooks-and-callbacks).
#
module Hook
# The Hook module gets included.
#
# @param [Class] base the class that includes the module
#
def self.included(base)
base.send :include, InstanceMethods
end
# Instance methods that gets included in the base class.
#
module InstanceMethods
# When event is a Symbol, {#hook} will generate a hook name
# by concatenating the method name from where {#hook} is called
# with the given Symbol.
#
# @example Add a hook with a Symbol
#
# def run_all
# hook :foo
# end
#
# Here, when {Guard::Guard#run_all} is called, {#hook} will notify callbacks
# registered for the "run_all_foo" event.
#
# When event is a String, {#hook} will directly turn the String
# into a Symbol.
#
# @example Add a hook with a String
#
# def run_all
# hook "foo_bar"
# end
#
# When {Guard::Guard#run_all} is called, {#hook} will notify callbacks
# registered for the "foo_bar" event.
#
# @param [Symbol, String] event the name of the Guard event
# @param [Array] args the parameters are passed as is to the callbacks registered for the given event.
#
def hook(event, *args)
hook_name = if event.is_a? Symbol
calling_method = caller[0][/`([^']*)'/, 1]
"#{ calling_method }_#{ event }"
else
event
end.to_sym
UI.debug "Hook :#{ hook_name } executed for #{ self.class }"
Hook.notify(self.class, hook_name, *args)
end
end
class << self
# Get all callbacks.
#
def callbacks
@callbacks ||= Hash.new { |hash, key| hash[key] = [] }
end
# Add a callback.
#
# @param [Block] listener the listener to notify
# @param [Guard::Guard] guard_class the Guard class to add the callback
# @param [Array<Symbol>] events the events to register
#
def add_callback(listener, guard_class, events)
_events = events.is_a?(Array) ? events : [events]
_events.each do |event|
callbacks[[guard_class, event]] << listener
end
end
# Checks if a callback has been registered.
#
# @param [Block] listener the listener to notify
# @param [Guard::Guard] guard_class the Guard class to add the callback
# @param [Symbol] event the event to look for
#
def has_callback?(listener, guard_class, event)
callbacks[[guard_class, event]].include?(listener)
end
# Notify a callback.
#
# @param [Guard::Guard] guard_class the Guard class to add the callback
# @param [Symbol] event the event to trigger
# @param [Array] args the arguments for the listener
#
def notify(guard_class, event, *args)
callbacks[[guard_class, event]].each do |listener|
listener.call(guard_class, event, *args)
end
end
# Reset all callbacks.
#
def reset_callbacks!
@callbacks = nil
end
end
end
end

View File

@ -1,29 +1,44 @@
module Guard
module Interactor
def self.init_signal_traps
# Run all (Ctrl-\)
Signal.trap('QUIT') do
::Guard.run do
::Guard.guards.each { |g| ::Guard.supervised_task g, :run_all }
end
end
# Stop (Ctrl-C)
Signal.trap('INT') do
::Guard.listener.stop
::Guard.guards.each { |g| ::Guard.supervised_task g, :stop }
UI.info "Bye bye...", :reset => true
abort("\n")
end
# Reload (Ctrl-Z)
Signal.trap('TSTP') do
::Guard.run do
::Guard.guards.each { |g| ::Guard.supervised_task g, :reload }
# The interactor reads user input and triggers
# specific action upon them unless its locked.
#
# Currently the following actions are implemented:
#
# - stop, quit, exit, s, q, e => Exit Guard
# - reload, r, z => Reload Guard
# - pause, p => Pause Guard
# - Everything else => Run all
#
class Interactor
# Start the interactor in its own thread.
#
def start
return if ENV["GUARD_ENV"] == 'test'
if !@thread || @thread.stop?
@thread = Thread.new do
while entry = $stdin.gets.chomp
case entry
when 'stop', 'quit', 'exit', 's', 'q', 'e'
::Guard.stop
when 'reload', 'r', 'z'
::Guard::Dsl.reevaluate_guardfile
::Guard.reload
when 'pause', 'p'
::Guard.pause
else
::Guard.run_all
end
end
end
end
end
def stop_if_not_current
unless Thread.current == @thread
@thread.kill
end
end
end
end
end

View File

@ -1,58 +1,350 @@
require 'rbconfig'
require 'digest/sha1'
module Guard
autoload :Darwin, 'guard/listeners/darwin'
autoload :Linux, 'guard/listeners/linux'
autoload :Windows, 'guard/listeners/windows'
autoload :Polling, 'guard/listeners/polling'
# The Listener is the base class for all listener
# implementations.
#
# @abstract
#
class Listener
attr_reader :last_event
def self.init
# Default paths that gets ignored by the listener
DEFAULT_IGNORE_PATHS = %w[. .. .bundle .git log tmp vendor]
attr_accessor :changed_files
attr_reader :directory, :ignore_paths
def paused?
@paused
end
# Select the appropriate listener implementation for the
# current OS and initializes it.
#
# @param [Array] args the arguments for the listener
# @return [Guard::Listener] the chosen listener
#
def self.select_and_init(*args)
if mac? && Darwin.usable?
Darwin.new
Darwin.new(*args)
elsif linux? && Linux.usable?
Linux.new
Linux.new(*args)
elsif windows? && Windows.usable?
Windows.new(*args)
else
UI.info "Using polling (Please help us to support your system better than that.)"
Polling.new
UI.info 'Using polling (Please help us to support your system better than that).'
Polling.new(*args)
end
end
def initialize
# Initialize the listener.
#
# @param [String] directory the root directory to listen to
# @option options [Boolean] relativize_paths use only relative paths
# @option options [Array<String>] ignore_paths the paths to ignore by the listener
#
def initialize(directory = Dir.pwd, options = {})
@directory = directory.to_s
@sha1_checksums_hash = {}
@file_timestamp_hash = {}
@relativize_paths = options.fetch(:relativize_paths, true)
@changed_files = []
@paused = false
@ignore_paths = DEFAULT_IGNORE_PATHS
@ignore_paths |= options[:ignore_paths] if options[:ignore_paths]
@watch_all_modifications = options.fetch(:watch_all_modifications, false)
update_last_event
start_reactor
end
private
def modified_files(dirs, options = {})
files = potentially_modified_files(dirs, options).select { |path| File.file?(path) && recent_file?(path) }
files.map! { |file| file.gsub("#{Dir.pwd}/", '') }
# Start the listener thread.
#
def start_reactor
return if ENV["GUARD_ENV"] == 'test'
Thread.new do
loop do
if @changed_files != [] && !@paused
changed_files = @changed_files.dup
clear_changed_files
::Guard.run_on_change(changed_files)
else
sleep 0.1
end
end
end
end
def potentially_modified_files(dirs, options = {})
match = options[:all] ? "**/*" : "*"
Dir.glob(dirs.map { |dir| "#{dir}#{match}" })
# Start watching the root directory.
#
def start
watch(@directory)
timestamp_files
end
def recent_file?(file)
File.mtime(file) >= last_event
rescue
false
# Stop listening for events.
#
def stop
end
# Pause the listener to ignore change events.
#
def pause
@paused = true
end
# Unpause the listener to listen again to change events.
#
def run
@paused = false
end
# Clear the list of changed files.
#
def clear_changed_files
@changed_files.clear
end
# Store a listener callback.
#
# @param [Block] callback the callback to store
#
def on_change(&callback)
@callback = callback
end
# Updates the timestamp of the last event.
#
def update_last_event
@last_event = Time.now
end
# Get the modified files.
#
# If the `:watch_all_modifications` option is true, then moved and
# deleted files are also reported, but prefixed by an exclamation point.
#
# @example Deleted or moved file
# !/home/user/dir/file.rb
#
# @param [Array<String>] dirs the watched directories
# @param [Hash] options the listener options
# @option options [Symbol] all whether to files in sub directories
# @return [Array<String>] paths of files that have been modified
#
def modified_files(dirs, options = {})
last_event = @last_event
files = []
if @watch_all_modifications
deleted_files = @file_timestamp_hash.collect do |path, ts|
unless File.exists?(path)
@sha1_checksums_hash.delete(path)
@file_timestamp_hash.delete(path)
"!#{path}"
end
end
files.concat(deleted_files.compact)
end
update_last_event
files.concat(potentially_modified_files(dirs, options).select { |path| file_modified?(path, last_event) })
relativize_paths(files)
end
# Register a directory to watch.
# Must be implemented by the subclasses.
#
# @param [String] directory the directory to watch
#
def watch(directory)
raise NotImplementedError, "do whatever you want here, given the directory as only argument"
end
# Get all files that are in the watched directory.
#
# @return [Array<String>] the list of files
#
def all_files
potentially_modified_files([@directory], :all => true)
end
# Scopes all given paths to the current directory.
#
# @param [Array<String>] paths the paths to change
# @return [Array<String>] all paths now relative to the current dir
#
def relativize_paths(paths)
return paths unless relativize_paths?
paths.map do |path|
path.gsub(%r{^(!)?#{ @directory }/},'\1')
end
end
# Use paths relative to the current directory.
#
# @return [Boolean] whether to use relative or absolute paths
#
def relativize_paths?
!!@relativize_paths
end
# Populate initial timestamp file hash to watch for deleted or moved files.
#
def timestamp_files
all_files.each {|path| set_file_timestamp_hash(path, file_timestamp(path)) } if @watch_all_modifications
end
# Removes the ignored paths from the directory list.
#
# @param [Array<String>] dirs the directory to listen to
# @param [Array<String>] ignore_paths the paths to ignore
# @return children of the passed dirs that are not in the ignore_paths list
#
def exclude_ignored_paths(dirs, ignore_paths = self.ignore_paths)
Dir.glob(dirs.map { |d| "#{d.sub(%r{/+$}, '')}/*" }, File::FNM_DOTMATCH).reject do |path|
ignore_paths.include?(File.basename(path))
end
end
private
# Gets a list of files that are in the modified directories.
#
# @param [Array<String>] dirs the list of directories
# @param [Hash] options the find file option
# @option options [Symbol] all whether to files in sub directories
#
def potentially_modified_files(dirs, options = {})
paths = exclude_ignored_paths(dirs)
if options[:all]
paths.inject([]) do |array, path|
if File.file?(path)
array << path
else
array += Dir.glob("#{ path }/**/*", File::FNM_DOTMATCH).select { |p| File.file?(p) }
end
array
end
else
paths.select { |path| File.file?(path) }
end
end
# Test if the file content has changed.
#
# Depending on the filesystem, mtime/ctime is probably only precise to the second, so round
# both values down to the second for the comparison.
#
# ctime is used only on == comparison to always catches Rails 3.1 Assets pipelined on Mac OSX
#
# @param [String] path the file path
# @param [Time] last_event the time of the last event
# @return [Boolean] Whether the file content has changed or not.
#
def file_modified?(path, last_event)
ctime = File.ctime(path).to_i
mtime = File.mtime(path).to_i
if [mtime, ctime].max == last_event.to_i
file_content_modified?(path, sha1_checksum(path))
elsif mtime > last_event.to_i
set_sha1_checksums_hash(path, sha1_checksum(path))
true
elsif @watch_all_modifications
ts = file_timestamp(path)
if ts != @file_timestamp_hash[path]
set_file_timestamp_hash(path, ts)
true
end
else
false
end
rescue
false
end
# Tests if the file content has been modified by
# comparing the SHA1 checksum.
#
# @param [String] path the file path
# @param [String] sha1_checksum the checksum of the file
#
def file_content_modified?(path, sha1_checksum)
if @sha1_checksums_hash[path] != sha1_checksum
set_sha1_checksums_hash(path, sha1_checksum)
true
else
false
end
end
# Set save a files current timestamp
#
# @param [String] path the file path
# @param [Int] file_timestamp the files modified timestamp
#
def set_file_timestamp_hash(path, file_timestamp)
@file_timestamp_hash[path] = file_timestamp
end
# Set the current checksum of a file.
#
# @param [String] path the file path
# @param [String] sha1_checksum the checksum of the file
#
def set_sha1_checksums_hash(path, sha1_checksum)
@sha1_checksums_hash[path] = sha1_checksum
end
# Gets a files modified timestamp
#
# @path [String] path the file path
# @return [Int] file modified timestamp
#
def file_timestamp(path)
File.mtime(path).to_i
end
# Calculates the SHA1 checksum of a file.
#
# @param [String] path the path to the file
# @return [String] the SHA1 checksum
#
def sha1_checksum(path)
Digest::SHA1.file(path).to_s
end
# Test if the OS is Mac OS X.
#
# @return [Boolean] Whether the OS is Mac OS X
#
def self.mac?
Config::CONFIG['target_os'] =~ /darwin/i
RbConfig::CONFIG['target_os'] =~ /darwin/i
end
# Test if the OS is Linux.
#
# @return [Boolean] Whether the OS is Linux
#
def self.linux?
Config::CONFIG['target_os'] =~ /linux/i
RbConfig::CONFIG['target_os'] =~ /linux/i
end
# Test if the OS is Windows.
#
# @return [Boolean] Whether the OS is Windows
#
def self.windows?
RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
end
end
end
end

View File

@ -1,40 +1,66 @@
module Guard
# Listener implementation for Mac OS X `FSEvents`.
#
class Darwin < Listener
attr_reader :fsevent
def initialize
# Initialize the Listener.
#
def initialize(*)
super
@fsevent = FSEvent.new
end
def on_change(&callback)
@fsevent.watch Dir.pwd do |modified_dirs|
files = modified_files(modified_dirs)
update_last_event
callback.call(files)
end
end
# Start the listener.
#
def start
@fsevent.run
super
worker.run
end
# Stop the listener.
#
def stop
@fsevent.stop
super
worker.stop
end
# Check if the listener is usable on the current OS.
#
# @return [Boolean] whether usable or not
#
def self.usable?
require 'rb-fsevent'
if !defined?(FSEvent::VERSION) || Gem::Version.new(FSEvent::VERSION) < Gem::Version.new('0.3.5')
UI.info "Please update rb-fsevent (>= 0.3.5)"
if !defined?(FSEvent::VERSION) || (defined?(Gem::Version) &&
Gem::Version.new(FSEvent::VERSION) < Gem::Version.new('0.4.0'))
UI.info 'Please update rb-fsevent (>= 0.4.0)'
false
else
true
end
rescue LoadError
UI.info "Please install rb-fsevent gem for Mac OSX FSEvents support"
UI.info 'Please install rb-fsevent gem for Mac OSX FSEvents support'
false
end
private
# Get the listener worker.
#
def worker
@fsevent
end
# Watch the given directory for file changes.
#
# @param [String] directory the directory to watch
#
def watch(directory)
worker.watch(directory) do |modified_dirs|
files = modified_files(modified_dirs)
@callback.call(files) unless files.empty?
end
end
end
end
end

View File

@ -1,28 +1,65 @@
module Guard
# Listener implementation for Linux `inotify`.
#
class Linux < Listener
attr_reader :inotify, :files, :latency, :callback
def initialize
# Initialize the Listener.
#
def initialize(*)
super
@inotify = INotify::Notifier.new
@files = []
@latency = 0.5
end
# Start the listener.
#
def start
@stop = false
super
watch_change unless watch_change?
end
# Stop the listener.
#
def stop
super
@stop = true
sleep latency
end
def on_change(&callback)
@callback = callback
inotify.watch(Dir.pwd, :recursive, :modify, :create, :delete, :move) do |event|
# Check if the listener is usable on the current OS.
#
# @return [Boolean] whether usable or not
#
def self.usable?
require 'rb-inotify'
if !defined?(INotify::VERSION) || (defined?(Gem::Version) &&
Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.8.5'))
UI.info 'Please update rb-inotify (>= 0.8.5)'
false
else
true
end
rescue LoadError
UI.info 'Please install rb-inotify gem for Linux inotify support'
false
end
private
# Get the listener worker.
#
def worker
@inotify
end
# Watch the given directory for file changes.
#
# @param [String] directory the directory to watch
#
def watch(directory)
worker.watch(directory, :recursive, :attrib, :create, :move_self, :close_write) do |event|
unless event.name == "" # Event on root directory
@files << event.absolute_name
end
@ -30,44 +67,31 @@ module Guard
rescue Interrupt
end
def self.usable?
require 'rb-inotify'
if !defined?(INotify::VERSION) || Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.5.1')
UI.info "Please update rb-inotify (>= 0.5.1)"
false
else
true
end
rescue LoadError
UI.info "Please install rb-inotify gem for Linux inotify support"
false
end
# Test if inotify is watching for changes.
#
# @return [Boolean] whether inotify is active or not
#
def watch_change?
!!@watch_change
end
private
# Watch for file system changes.
#
def watch_change
@watch_change = true
while !@stop
if Config::CONFIG['build'] =~ /java/ || IO.select([inotify.to_io], [], [], latency)
until @stop
if RbConfig::CONFIG['build'] =~ /java/ || IO.select([worker.to_io], [], [], @latency)
break if @stop
sleep latency
inotify.process
update_last_event
sleep(@latency)
worker.process
unless files.empty?
files.map! { |file| file.gsub("#{Dir.pwd}/", '') }
callback.call(files)
files.clear
end
files = modified_files(@files.shift(@files.size).map { |f| File.dirname(f) }.uniq)
@callback.call(files) unless files.empty?
end
end
@watch_change = false
end
end
end
end

View File

@ -1,37 +1,55 @@
module Guard
# Polling listener that works cross-platform and
# has no dependencies. This is the listener that
# uses the most CPU processing power and has higher
# file IO that the other implementations.
#
class Polling < Listener
attr_reader :callback, :latency
def initialize
# Initialize the Listener.
#
def initialize(*)
super
@latency = 1.5
end
def on_change(&callback)
@callback = callback
end
# Start the listener.
#
def start
@stop = false
super
watch_change
end
# Stop the listener.
#
def stop
super
@stop = true
end
private
# Watch the given directory for file changes.
#
# @param [String] directory the directory to watch
#
def watch(directory)
@existing = all_files
end
private
# Watch for file system changes.
#
def watch_change
while !@stop
until @stop
start = Time.now.to_f
files = modified_files([Dir.pwd + '/'], :all => true)
update_last_event
callback.call(files) unless files.empty?
nap_time = latency - (Time.now.to_f - start)
files = modified_files([@directory], :all => true)
@callback.call(files) unless files.empty?
nap_time = @latency - (Time.now.to_f - start)
sleep(nap_time) if nap_time > 0
end
end
end
end
end

View File

@ -0,0 +1,61 @@
module Guard
# Listener implementation for Windows `fchange`.
#
class Windows < Listener
# Initialize the Listener.
#
def initialize(*)
super
@fchange = FChange::Notifier.new
end
# Start the listener.
#
def start
super
worker.run
end
# Stop the listener.
#
def stop
super
worker.stop
end
# Check if the listener is usable on the current OS.
#
# @return [Boolean] whether usable or not
#
def self.usable?
require 'rb-fchange'
true
rescue LoadError
UI.info 'Please install rb-fchange gem for Windows file events support'
false
end
private
# Watch the given directory for file changes.
#
# @param [String] directory the directory to watch
#
def watch(directory)
worker.watch(directory, :all_events, :recursive) do |event|
paths = [File.expand_path(event.watcher.path)]
files = modified_files(paths, :all => true)
@callback.call(files) unless files.empty?
end
end
# Get the listener worker.
#
def worker
@fchange
end
end
end

View File

@ -1,62 +1,290 @@
require 'rbconfig'
require 'pathname'
require 'guard/ui'
module Guard
# The notifier class handles cross-platform system notifications that supports:
#
# - Growl on Mac OS X
# - Libnotify on Linux
# - Notifu on Windows
#
module Notifier
def self.notify(message, options = {})
unless ENV["GUARD_ENV"] == "test"
image = options[:image] || :success
title = options[:title] || "Guard"
case Config::CONFIG['target_os']
when /darwin/i
if growl_installed?
Growl.notify message, :title => title, :icon => image_path(image), :name => "Guard"
end
when /linux/i
if libnotify_installed?
Libnotify.show :body => message, :summary => title, :icon_path => image_path(image)
# Application name as shown in the specific notification settings
APPLICATION_NAME = "Guard"
class << self
attr_accessor :growl_library, :gntp
# Turn notifications off.
#
def turn_off
ENV["GUARD_NOTIFY"] = 'false'
end
# Turn notifications on. This tries to load the platform
# specific notification library.
#
# @return [Boolean] whether the notification could be enabled.
#
def turn_on
ENV["GUARD_NOTIFY"] = 'true'
case RbConfig::CONFIG['target_os']
when /darwin/i
require_growl
when /linux/i
require_libnotify
when /mswin|mingw/i
require_rbnotifu
end
end
# Show a message with the system notification.
#
# @see .image_path
#
# @param [String] the message to show
# @option options [Symbol, String] image the image symbol or path to an image
# @option options [String] title the notification title
#
def notify(message, options = { })
if enabled?
image = options.delete(:image) || :success
title = options.delete(:title) || "Guard"
case RbConfig::CONFIG['target_os']
when /darwin/i
notify_mac(title, message, image, options)
when /linux/i
notify_linux(title, message, image, options)
when /mswin|mingw/i
notify_windows(title, message, image, options)
end
end
end
end
private
def self.image_path(image)
images_path = Pathname.new(File.dirname(__FILE__)).join('../../images')
case image
when :failed
images_path.join("failed.png").to_s
when :pending
images_path.join("pending.png").to_s
when :success
images_path.join("success.png").to_s
else
# path given
image
# Test if the notifications are enabled and available.
#
# @return [Boolean] whether the notifications are available
#
def enabled?
ENV["GUARD_NOTIFY"] == 'true'
end
end
def self.growl_installed?
@installed ||= begin
private
# Send a message to Growl either with the `growl` gem or the `growl_notify` gem.
#
# @param [String] title the notification title
# @param [String] message the message to show
# @param [Symbol, String] the image to user
# @param [Hash] options the growl options
#
def notify_mac(title, message, image, options = { })
require_growl # need for guard-rspec formatter that is called out of guard scope
notification = { :title => title, :icon => image_path(image) }.merge(options)
case self.growl_library
when :growl_notify
notification.delete(:name)
GrowlNotify.send_notification({
:description => message,
:application_name => APPLICATION_NAME
}.merge(notification))
when :ruby_gntp
icon = "file://#{ notification.delete(:icon) }"
self.gntp.notify({
:name => [:pending, :success, :failed].include?(image) ? image.to_s : 'notify',
:text => message,
:icon => icon
}.merge(notification))
when :growl
Growl.notify(message, {
:name => APPLICATION_NAME
}.merge(notification))
end
end
# Send a message to libnotify.
#
# @param [String] title the notification title
# @param [String] message the message to show
# @param [Symbol, String] the image to user
# @param [Hash] options the libnotify options
#
def notify_linux(title, message, image, options = { })
require_libnotify # need for guard-rspec formatter that is called out of guard scope
notification = { :body => message, :summary => title, :icon_path => image_path(image), :transient => true }
Libnotify.show notification.merge(options)
end
# Send a message to notifu.
#
# @param [String] title the notification title
# @param [String] message the message to show
# @param [Symbol, String] the image to user
# @param [Hash] options the notifu options
#
def notify_windows(title, message, image, options = { })
require_rbnotifu # need for guard-rspec formatter that is called out of guard scope
notification = { :message => message, :title => title, :type => image_level(image), :time => 3 }
Notifu.show notification.merge(options)
end
# Get the image path for an image symbol.
#
# Known symbols are:
#
# - failed
# - pending
# - success
#
# @param [Symbol] image the image name
# @return [String] the image path
#
def image_path(image)
images_path = Pathname.new(File.dirname(__FILE__)).join('../../images')
case image
when :failed
images_path.join("failed.png").to_s
when :pending
images_path.join("pending.png").to_s
when :success
images_path.join("success.png").to_s
else
# path given
image
end
end
# The notification level type for the given image.
#
# @param [Symbol] image the image
# @return [Symbol] the level
#
def image_level(image)
case image
when :failed
:error
when :pending
:warn
when :success
:info
else
:info
end
end
# Try to safely load growl and turns notifications off on load failure.
# The Guard notifier knows three different library to handle sending
# Growl messages and tries to loading them in the given order:
#
# - [Growl Notify](https://github.com/scottdavis/growl_notify)
# - [Ruby GNTP](https://github.com/snaka/ruby_gntp)
# - [Growl](https://github.com/visionmedia/growl)
#
# On successful loading of any of the libraries, the active library name is
# accessible through `.growl_library`.
#
def require_growl
self.growl_library = try_growl_notify || try_ruby_gntp || try_growl
unless self.growl_library
turn_off
UI.info "Please install growl_notify or growl gem for Mac OS X notification support and add it to your Gemfile"
end
end
# Try to load the `growl_notify` gem.
#
# @return [Symbol, nil] A symbol with the name of the loaded library
#
def try_growl_notify
require 'growl_notify'
begin
if GrowlNotify.application_name != APPLICATION_NAME
GrowlNotify.config do |c|
c.notifications = c.default_notifications = [APPLICATION_NAME]
c.application_name = c.notifications.first
end
end
rescue ::GrowlNotify::GrowlNotFound
turn_off
UI.info "Please install Growl from http://growl.info"
end
:growl_notify
rescue LoadError
end
# Try to load the `ruby_gntp` gem and register the available
# notification channels.
#
# @return [Symbol, nil] A symbol with the name of the loaded library
#
def try_ruby_gntp
require 'ruby_gntp'
self.gntp = GNTP.new(APPLICATION_NAME)
self.gntp.register(:notifications => [
{ :name => 'notify', :enabled => true },
{ :name => 'failed', :enabled => true },
{ :name => 'pending', :enabled => true },
{ :name => 'success', :enabled => true }
])
:ruby_gntp
rescue LoadError
end
# Try to load the `growl_notify` gem.
#
# @return [Symbol, nil] A symbol with the name of the loaded library
#
def try_growl
require 'growl'
true
:growl
rescue LoadError
UI.info "Please install growl gem for Mac OS X notification support and add it to your Gemfile"
false
end
end
def self.libnotify_installed?
@installed ||= begin
# Try to safely load libnotify and turns notifications
# off on load failure.
#
def require_libnotify
require 'libnotify'
true
rescue LoadError
turn_off
UI.info "Please install libnotify gem for Linux notification support and add it to your Gemfile"
false
end
# Try to safely load rb-notifu and turns notifications
# off on load failure.
#
def require_rbnotifu
require 'rb-notifu'
rescue LoadError
turn_off
UI.info "Please install rb-notifu gem for Windows notification support and add it to your Gemfile"
end
end
end
end
end

View File

@ -1,2 +1,2 @@
# A sample Guardfile
# More info at http://github.com/guard/guard#readme
# More info at https://github.com/guard/guard#readme

View File

@ -1,42 +1,193 @@
module Guard
# The UI class helps to format messages for the user. Everything that is logged
# through this class is considered either as an error message or a diagnostic
# message and is written to standard error (STDERR).
#
# If your Guard does some output that is piped into another process for further
# processing, please just write it to STDOUT with `puts`.
#
module UI
class << self
def info(message, options = {})
unless ENV["GUARD_ENV"] == "test"
color_enabled = nil
# Show an info message.
#
# @param [String] message the message to show
# @option options [Boolean] reset whether to clean the output before
#
def info(message, options = { })
unless ENV['GUARD_ENV'] == 'test'
reset_line if options[:reset]
puts reset_color(message) if message != ''
STDERR.puts color(message) if message != ''
end
end
def error(message)
puts "ERROR: #{message}"
end
def debug(message)
unless ENV["GUARD_ENV"] == "test"
puts "DEBUG: #{message}" if ::Guard.options && ::Guard.options[:debug]
# Show a red error message that is prefixed with ERROR.
#
# @param [String] message the message to show
# @option options [Boolean] reset whether to clean the output before
#
def error(message, options = { })
unless ENV['GUARD_ENV'] == 'test'
reset_line if options[:reset]
STDERR.puts color('ERROR: ', :red) + message
end
end
# Show a red deprecation message that is prefixed with DEPRECATION.
#
# @param [String] message the message to show
# @option options [Boolean] reset whether to clean the output before
#
def deprecation(message, options = { })
unless ENV['GUARD_ENV'] == 'test'
reset_line if options[:reset]
STDERR.puts color('DEPRECATION: ', :red) + message
end
end
# Show a debug message that is prefixed with DEBUG and a timestamp.
#
# @param [String] message the message to show
# @option options [Boolean] reset whether to clean the output before
#
def debug(message, options = { })
unless ENV['GUARD_ENV'] == 'test'
reset_line if options[:reset]
STDERR.puts color("DEBUG (#{Time.now.strftime('%T')}): ", :yellow) + message if ::Guard.options && ::Guard.options[:debug]
end
end
# Reset a line.
#
def reset_line
print "\r\e "
STDERR.print(color_enabled? ? "\r\e[0m" : "\r\n")
end
# Clear the output.
#
def clear
system("clear;")
system('clear;')
end
private
private
# Reset a color sequence.
#
# @deprecated
# @param [String] text the text
#
def reset_color(text)
color(text, "\e[0m")
deprecation('UI.reset_color(text) is deprecated, please use color(text, ' ') instead.')
color(text, '')
end
def color(text, color_code)
"#{color_code}#{text}\e[0m"
# Checks if color output can be enabled.
#
# @return [Boolean] whether color is enabled or not
#
def color_enabled?
if @color_enabled.nil?
if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
if ENV['ANSICON']
@color_enabled = true
else
begin
require 'rubygems' unless ENV['NO_RUBYGEMS']
require 'Win32/Console/ANSI'
@color_enabled = true
rescue LoadError
@color_enabled = false
info "You must 'gem install win32console' to use color on Windows"
end
end
else
@color_enabled = true
end
end
@color_enabled
end
# Colorizes a text message. See the constant in the UI class for possible
# color_options parameters. You can pass optionally :bright, a foreground
# color and a background color.
#
# @example
#
# color('Hello World', :red, :bright)
#
# @param [String] the text to colorize
# @param [Array] color_options the color options
#
def color(text, *color_options)
color_code = ''
color_options.each do |color_option|
color_option = color_option.to_s
if color_option != ''
if !(color_option =~ /\d+/)
color_option = const_get("ANSI_ESCAPE_#{ color_option.upcase }")
end
color_code += ';' + color_option
end
end
color_enabled? ? "\e[0#{ color_code }m#{ text }\e[0m" : text
end
end
# Brighten the color
ANSI_ESCAPE_BRIGHT = '1'
# Black foreground color
ANSI_ESCAPE_BLACK = '30'
# Red foreground color
ANSI_ESCAPE_RED = '31'
# Green foreground color
ANSI_ESCAPE_GREEN = '32'
# Yellow foreground color
ANSI_ESCAPE_YELLOW = '33'
# Blue foreground color
ANSI_ESCAPE_BLUE = '34'
# Magenta foreground color
ANSI_ESCAPE_MAGENTA = '35'
# Cyan foreground color
ANSI_ESCAPE_CYAN = '36'
# White foreground color
ANSI_ESCAPE_WHITE = '37'
# Black background color
ANSI_ESCAPE_BGBLACK = '40'
# Red background color
ANSI_ESCAPE_BGRED = '41'
# Green background color
ANSI_ESCAPE_BGGREEN = '42'
# Yellow background color
ANSI_ESCAPE_BGYELLOW = '43'
# Blue background color
ANSI_ESCAPE_BGBLUE = '44'
# Magenta background color
ANSI_ESCAPE_BGMAGENTA = '45'
# Cyan background color
ANSI_ESCAPE_BGCYAN = '46'
# White background color
ANSI_ESCAPE_BGWHITE = '47'
end
end

View File

@ -1,3 +1,6 @@
module Guard
VERSION = "0.2.2"
end
unless defined? Guard::VERSION
# The current gem version of Guard
VERSION = '0.8.4'
end
end

View File

@ -1,34 +1,114 @@
module Guard
# The watcher defines a RegExp that will be matched against file system modifications.
# When a watcher matches a change, an optional action block is executed to enable
# processing the file system change result.
#
class Watcher
attr_accessor :pattern, :action
# Initialize a file watcher.
#
# @param [String, Regexp] pattern the pattern to be watched by the guard
# @param [Block] action the action to execute before passing the result to the Guard
#
def initialize(pattern, action = nil)
@pattern, @action = pattern, action
@@warning_printed ||= false
# deprecation warning
if @pattern.is_a?(String) && @pattern =~ /(^(\^))|(>?(\\\.)|(\.\*))|(\(.*\))|(\[.*\])|(\$$)/
unless @@warning_printed
UI.info "*"*20 + "\nDEPRECATION WARNING!\n" + "*"*20
UI.info <<-MSG
You have a string in your Guardfile watch patterns that seem to represent a Regexp.
Guard matches String with == and Regexp with Regexp#match.
You should either use plain String (without Regexp special characters) or real Regexp.
MSG
@@warning_printed = true
end
UI.info "\"#{@pattern}\" has been converted to #{ Regexp.new(@pattern).inspect }\n"
@pattern = Regexp.new(@pattern)
end
end
# Finds the files that matches a Guard.
#
# @param [Guard::Guard] guard the guard which watchers are used
# @param [Array<String>] files the changed files
# @return [Array<Object>] the matched watcher response
#
def self.match_files(guard, files)
guard.watchers.inject([]) do |paths, watcher|
files.each do |file|
if matches = file.match(watcher.pattern)
if matches = watcher.match_file?(file)
if watcher.action
begin
if watcher.action.arity == 1
result = watcher.action.call(matches)
else
result = watcher.action.call
end
rescue
UI.info "Problem with watch action"
result = watcher.call_action(matches)
if guard.options[:any_return]
paths << result
elsif result.respond_to?(:empty?) && !result.empty?
paths << Array(result)
end
paths << result if result.is_a?(String) && result != ''
else
paths << matches[0]
end
end
end
paths
guard.options[:any_return] ? paths : paths.flatten.map { |p| p.to_s }
end
end
# Test if a file would be matched by any of the Guards watchers.
#
# @param [Array<Guard::Guard>] guards the guards to use the watchers from
# @param [Array<String>] files the files to test
# @return [Boolean] Whether a file matches
#
def self.match_files?(guards, files)
guards.any? do |guard|
guard.watchers.any? do |watcher|
files.any? { |file| watcher.match_file?(file) }
end
end
end
# Test the watchers pattern against a file.
#
# @param [String] file the file to test
# @return [Boolean] whether the given file is matched
#
def match_file?(file)
if @pattern.is_a?(Regexp)
file.match(@pattern)
else
file == @pattern ? [file] : nil
end
end
# Test if any of the files is the Guardfile.
#
# @param [Array<String>] the files to test
# @return [Boolean] whether one of these files is the Guardfile
#
def self.match_guardfile?(files)
files.any? { |file| "#{ Dir.pwd }/#{ file }" == Dsl.guardfile_path }
end
# Executes a watcher action.
#
# @param [String, MatchData] the matched path or the match from the Regex
# @return [String] the final paths
#
def call_action(matches)
begin
@action.arity > 0 ? @action.call(matches) : @action.call
rescue Exception => e
UI.error "Problem with watch action!\n#{ e.message }\n\n#{ e.backtrace.join("\n") }"
end
end
end
end
end

93
man/guard.1 Normal file
View File

@ -0,0 +1,93 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GUARD" "1" "September 2011" "" ""
.
.SH "NAME"
\fBguard\fR \- Guard keeps an eye on your file modifications\.
.
.SH "DESCRIPTION"
Guard is a command line tool that easily handle events on files modifications\.
.
.SH "SYNOPSIS"
\fBguard <COMMAND> <OPTIONS>\fR
.
.SH "COMMANDS"
.
.SS "start"
Starts Guard\. This is the default command if none is provided\.
.
.P
The following options are available:
.
.P
\fB\-c\fR, \fB\-\-clear\fR Clears the Shell after each change\.
.
.P
\fB\-n\fR, \fB\-\-notify\fR \fIFLAG\fR Disable notifications (Growl or Libnotify depending on your system)\. Notifications can be disabled globally by setting a GUARD_NOTIFY environment variable to false\. FLAG can be \fBtrue\fR/\fBfalse\fR or \fBt\fR/\fBf\fR\.
.
.P
\fB\-d\fR, \fB\-\-debug\fR Runs Guard in debug mode\.
.
.P
\fB\-g\fR, \fB\-\-group\fR \fIGROUP1\fR \fIGROUP2\fR\.\.\. Runs only the groups specified by GROUP1, GROUP2 etc\. Groups name should be separated by spaces\. Guards that don\'t belong to a group are considered global and are always run\.
.
.P
\fB\-w\fR, \fB\-\-watchdir\fR \fIPATH\fR
.
.P
Tells Guard to watch PATH instead of \fB\./\fR\.
.
.P
\fB\-G\fR, \fB\-\-guardfile\fR \fIFILE\fR Tells Guard to use FILE as its Guardfile instead of \fB\./Guardfile\fR or \fB~/\.Guardfile\fR\.
.
.SS "init [GUARD]"
If no Guardfile is present in the current directory, creates an empty Guardfile\.
.
.P
If \fIGUARD\fR is present, add its default Guardfile configuration to the current Guardfile\. Note that \fIGUARD\fR is the guard\'s name without the \fBguard\-\fR prefix\. For instance to initialize guard\-rspec, run \fBguard init rspec\fR\.
.
.SS "list"
Lists guards that can be used with the \fBinit\fR command\.
.
.SS "\-T, show"
List defined groups and guards for the current Guardfile\.
.
.SS "\-h, help [COMMAND]"
List all of Guard\'s available commands\.
.
.P
If \fICOMMAND\fR is given, displays a specific help for \fITASK\fR\.
.
.SH "EXAMPLES"
Initialize Guard and a specific guard at the same time:
.
.P
\fB[bundle exec] guard init [rspec]\fR
.
.P
Run Guard:
.
.P
\fB[bundle exec] guard [start] \-\-watchdir ~/dev \-\-guardfile ~/env/Guardfile \-\-clear \-\-group backend frontend \-\-notify false \-\-debug\fR
.
.P
or in a more concise way:
.
.P
\fB[bundle exec] guard [start] \-w ~/dev \-G ~/env/Guardfile \-c \-g backend frontend \-n f \-d\fR
.
.SH "AUTHORS / CONTRIBUTORS"
Thibaud Guillaume\-Gentil is the main author\.
.
.P
A list of contributors based on all commits can be found here: https://github\.com/guard/guard/contributors
.
.P
For an exhaustive list of all the contributors, please see the CHANGELOG: https://github\.com/guard/guard/blob/master/CHANGELOG\.md
.
.P
This manual has been written by Remy Coutable\.
.
.SH "WWW"
https://github\.com/guard/guard

176
man/guard.1.html Normal file
View File

@ -0,0 +1,176 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='content-type' value='text/html;charset=utf8'>
<meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
<title>guard(1) - Guard keeps an eye on your file modifications.</title>
<style type='text/css' media='all'>
/* style: man */
body#manpage {margin:0}
.mp {max-width:100ex;padding:0 9ex 1ex 4ex}
.mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
.mp h2 {margin:10px 0 0 0}
.mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
.mp h3 {margin:0 0 0 4ex}
.mp dt {margin:0;clear:left}
.mp dt.flush {float:left;width:8ex}
.mp dd {margin:0 0 0 9ex}
.mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
.mp pre {margin-bottom:20px}
.mp pre+h2,.mp pre+h3 {margin-top:22px}
.mp h2+pre,.mp h3+pre {margin-top:5px}
.mp img {display:block;margin:auto}
.mp h1.man-title {display:none}
.mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
.mp h2 {font-size:16px;line-height:1.25}
.mp h1 {font-size:20px;line-height:2}
.mp {text-align:justify;background:#fff}
.mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
.mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
.mp u {text-decoration:underline}
.mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
.mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
.mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
.mp b.man-ref {font-weight:normal;color:#434241}
.mp pre {padding:0 4ex}
.mp pre code {font-weight:normal;color:#434241}
.mp h2+pre,h3+pre {padding-left:0}
ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
ol.man-decor {width:100%}
ol.man-decor li.tl {text-align:left}
ol.man-decor li.tc {text-align:center;letter-spacing:4px}
ol.man-decor li.tr {text-align:right;float:right}
</style>
</head>
<!--
The following styles are deprecated and will be removed at some point:
div#man, div#man ol.man, div#man ol.head, div#man ol.man.
The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
.man-navigation should be used instead.
-->
<body id='manpage'>
<div class='mp' id='man'>
<div class='man-navigation' style='display:none'>
<a href="#NAME">NAME</a>
<a href="#DESCRIPTION">DESCRIPTION</a>
<a href="#SYNOPSIS">SYNOPSIS</a>
<a href="#COMMANDS">COMMANDS</a>
<a href="#EXAMPLES">EXAMPLES</a>
<a href="#AUTHORS-CONTRIBUTORS">AUTHORS / CONTRIBUTORS</a>
<a href="#WWW">WWW</a>
</div>
<ol class='man-decor man-head man head'>
<li class='tl'>guard(1)</li>
<li class='tc'></li>
<li class='tr'>guard(1)</li>
</ol>
<h2 id="NAME">NAME</h2>
<p class="man-name">
<code>guard</code> - <span class="man-whatis">Guard keeps an eye on your file modifications.</span>
</p>
<h2 id="DESCRIPTION">DESCRIPTION</h2>
<p>Guard is a command line tool that easily handle events on files modifications.</p>
<h2 id="SYNOPSIS">SYNOPSIS</h2>
<p><code>guard &lt;COMMAND> &lt;OPTIONS></code></p>
<h2 id="COMMANDS">COMMANDS</h2>
<h3 id="start">start</h3>
<p>Starts Guard. This is the default command if none is provided.</p>
<p>The following options are available:</p>
<p><code>-c</code>, <code>--clear</code>
Clears the Shell after each change.</p>
<p><code>-n</code>, <code>--notify</code> <var>FLAG</var>
Disable notifications (Growl or Libnotify depending on your system).
Notifications can be disabled globally by setting a GUARD_NOTIFY environment variable to false.
FLAG can be <code>true</code>/<code>false</code> or <code>t</code>/<code>f</code>.</p>
<p><code>-d</code>, <code>--debug</code>
Runs Guard in debug mode.</p>
<p><code>-g</code>, <code>--group</code> <var>GROUP1</var> <var>GROUP2</var>...
Runs only the groups specified by GROUP1, GROUP2 etc.
Groups name should be separated by spaces.
Guards that don't belong to a group are considered global and are always run.</p>
<p><code>-w</code>, <code>--watchdir</code> <var>PATH</var></p>
<p>Tells Guard to watch PATH instead of <code>./</code>.</p>
<p><code>-G</code>, <code>--guardfile</code> <var>FILE</var>
Tells Guard to use FILE as its Guardfile instead of <code>./Guardfile</code> or <code>~/.Guardfile</code>.</p>
<h3 id="init-GUARD-">init [GUARD]</h3>
<p>If no Guardfile is present in the current directory, creates an empty Guardfile.</p>
<p>If <var>GUARD</var> is present, add its default Guardfile configuration to the current Guardfile.
Note that <var>GUARD</var> is the guard's name without the <code>guard-</code> prefix.
For instance to initialize guard-rspec, run <code>guard init rspec</code>.</p>
<h3 id="list">list</h3>
<p>Lists guards that can be used with the <code>init</code> command.</p>
<h3 id="-T-show">-T, show</h3>
<p>List defined groups and guards for the current Guardfile.</p>
<h3 id="-h-help-COMMAND-">-h, help [COMMAND]</h3>
<p>List all of Guard's available commands.</p>
<p>If <var>COMMAND</var> is given, displays a specific help for <var>TASK</var>.</p>
<h2 id="EXAMPLES">EXAMPLES</h2>
<p>Initialize Guard and a specific guard at the same time:</p>
<p><code>[bundle exec] guard init [rspec]</code></p>
<p>Run Guard:</p>
<p><code>[bundle exec] guard [start] --watchdir ~/dev --guardfile ~/env/Guardfile --clear --group backend frontend --notify false --debug</code></p>
<p>or in a more concise way:</p>
<p><code>[bundle exec] guard [start] -w ~/dev -G ~/env/Guardfile -c -g backend frontend -n f -d</code></p>
<h2 id="AUTHORS-CONTRIBUTORS">AUTHORS / CONTRIBUTORS</h2>
<p>Thibaud Guillaume-Gentil is the main author.</p>
<p>A list of contributors based on all commits can be found here:
https://github.com/guard/guard/contributors</p>
<p>For an exhaustive list of all the contributors, please see the CHANGELOG:
https://github.com/guard/guard/blob/master/CHANGELOG.md</p>
<p>This manual has been written by Remy Coutable.</p>
<h2 id="WWW">WWW</h2>
<p>https://github.com/guard/guard</p>
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>September 2011</li>
<li class='tr'>guard(1)</li>
</ol>
</div>
</body>
</html>

93
man/guard.1.ronn Normal file
View File

@ -0,0 +1,93 @@
guard(1) -- Guard keeps an eye on your file modifications.
========================================================
## DESCRIPTION
Guard is a command line tool that easily handle events on files modifications.
## SYNOPSIS
`guard <COMMAND> <OPTIONS>`
## COMMANDS
### start
Starts Guard. This is the default command if none is provided.
The following options are available:
`-c`, `--clear`
Clears the Shell after each change.
`-n`, `--notify` <FLAG>
Disable notifications (Growl or Libnotify depending on your system).
Notifications can be disabled globally by setting a GUARD_NOTIFY environment variable to false.
FLAG can be `true`/`false` or `t`/`f`.
`-d`, `--debug`
Runs Guard in debug mode.
`-g`, `--group` <GROUP1> <GROUP2>...
Runs only the groups specified by GROUP1, GROUP2 etc.
Groups name should be separated by spaces.
Guards that don't belong to a group are considered global and are always run.
`-w`, `--watchdir` <PATH>
Tells Guard to watch PATH instead of `./`.
`-G`, `--guardfile` <FILE>
Tells Guard to use FILE as its Guardfile instead of `./Guardfile` or `~/.Guardfile`.
### init [GUARD]
If no Guardfile is present in the current directory, creates an empty Guardfile.
If <GUARD> is present, add its default Guardfile configuration to the current Guardfile.
Note that <GUARD> is the guard's name without the `guard-` prefix.
For instance to initialize guard-rspec, run `guard init rspec`.
### list
Lists guards that can be used with the `init` command.
### -T, show
List defined groups and guards for the current Guardfile.
### -h, help [COMMAND]
List all of Guard's available commands.
If <COMMAND> is given, displays a specific help for <TASK>.
## EXAMPLES
Initialize Guard and a specific guard at the same time:
`[bundle exec] guard init [rspec]`
Run Guard:
`[bundle exec] guard [start] --watchdir ~/dev --guardfile ~/env/Guardfile --clear --group backend frontend --notify false --debug`
or in a more concise way:
`[bundle exec] guard [start] -w ~/dev -G ~/env/Guardfile -c -g backend frontend -n f -d`
## AUTHORS / CONTRIBUTORS
Thibaud Guillaume-Gentil is the main author.
A list of contributors based on all commits can be found here:
https://github.com/guard/guard/contributors
For an exhaustive list of all the contributors, please see the CHANGELOG:
https://github.com/guard/guard/blob/master/CHANGELOG.md
This manual has been written by Remy Coutable.
## WWW
https://github.com/guard/guard

0
spec/fixtures/.dotfile vendored Normal file
View File

1
spec/fixtures/Guardfile vendored Normal file
View File

@ -0,0 +1 @@
# nothing here, it's just for feeding the specs! :)

0
spec/fixtures/folder1/file1.txt vendored Normal file → Executable file
View File

View File

@ -0,0 +1,70 @@
require 'spec_helper'
describe Guard::DslDescriber do
let(:describer) { ::Guard::DslDescriber }
let(:guardfile) do
<<-GUARD
guard 'test', :a => :b do
watch('c')
end
group :a do
guard 'test', :x => 1 do
watch('c')
end
end
group "b" do
guard 'another' do
watch('c')
end
end
GUARD
end
before do
@output = ''
Guard::UI.stub(:info) { |msg| @output << msg + "\n" }
end
after do
Guard::UI.unstub(:info)
end
describe '.list' do
it 'lists the available Guards' do
Guard.stub(:guard_gem_names).and_return ['test', 'another', 'even', 'more']
describer.list(:guardfile_contents => guardfile)
@output.should eql <<OUTPUT
Using inline Guardfile.
Available guards:
another*
even
more
test*
See also https://github.com/guard/guard/wiki/List-of-available-Guards
* denotes ones already in your Guardfile
OUTPUT
end
end
describe '.show' do
it 'shows the Guards and their options' do
describer.show(:guardfile_contents => guardfile)
@output.should eql <<OUTPUT
Using inline Guardfile.
(global):
test: a => :b
Group a:
test: x => 1
Group b:
another
OUTPUT
end
end
end

View File

@ -1,62 +1,383 @@
require 'spec_helper'
require 'guard/dsl'
require 'guard/guard'
describe Guard::Dsl do
subject { Guard::Dsl }
class Guard::Dummy < Guard::Guard; end
before(:each) do
::Guard.stub!(:add_guard)
@local_guardfile_path = File.join(Dir.pwd, 'Guardfile')
@home_guardfile_path = File.expand_path(File.join("~", ".Guardfile"))
@user_config_path = File.expand_path(File.join("~", ".guard.rb"))
::Guard.setup
::Guard.stub!(:options).and_return(:debug => true)
::Guard.stub!(:guards).and_return([mock('Guard')])
end
it "write an error message when no Guardfile is found" do
Dir.stub!(:pwd).and_return("no_guardfile_here")
Guard::UI.should_receive(:error).with("No Guardfile in current folder, please create one.")
lambda { subject.evaluate_guardfile }.should raise_error
def self.disable_user_config
before(:each) { File.stub(:exist?).with(@user_config_path) { false } }
end
it "write an error message when Guardfile is not valid" do
mock_guardfile_content("This Guardfile is invalid!")
Guard::UI.should_receive(:error).with(/Invalid Guardfile, original error is:\n/)
lambda { subject.evaluate_guardfile }.should raise_error
end
it "load a guard from the DSL" do
mock_guardfile_content("guard 'test'")
::Guard.should_receive(:add_guard).with('test', [], {})
subject.evaluate_guardfile
end
it "receive watchers when specified" do
mock_guardfile_content("
guard 'test' do
watch('a') { 'b' }
watch('c')
end")
::Guard.should_receive(:add_guard).with('test', anything, {}) do |name, watchers, options|
watchers.size.should == 2
watchers[0].pattern.should == 'a'
watchers[0].action.call.should == proc { 'b' }.call
watchers[1].pattern.should == 'c'
watchers[1].action.should be_nil
describe "it should select the correct data source for Guardfile" do
before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) }
disable_user_config
it "should use a string for initializing" do
Guard::UI.should_not_receive(:error)
lambda { described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.should_not raise_error
described_class.guardfile_contents.should == valid_guardfile_string
end
subject.evaluate_guardfile
it "should use a given file over the default loc" do
fake_guardfile('/abc/Guardfile', "guard :foo")
Guard::UI.should_not_receive(:error)
lambda { described_class.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.should_not raise_error
described_class.guardfile_contents.should == "guard :foo"
end
it "should use a default file if no other options are given" do
fake_guardfile(@local_guardfile_path, "guard :bar")
Guard::UI.should_not_receive(:error)
lambda { described_class.evaluate_guardfile }.should_not raise_error
described_class.guardfile_contents.should == "guard :bar"
end
it "should use a string over any other method" do
fake_guardfile('/abc/Guardfile', "guard :foo")
fake_guardfile(@local_guardfile_path, "guard :bar")
Guard::UI.should_not_receive(:error)
lambda { described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.should_not raise_error
described_class.guardfile_contents.should == valid_guardfile_string
end
it "should use the given Guardfile over default Guardfile" do
fake_guardfile('/abc/Guardfile', "guard :foo")
fake_guardfile(@local_guardfile_path, "guard :bar")
Guard::UI.should_not_receive(:error)
lambda { described_class.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.should_not raise_error
described_class.guardfile_contents.should == "guard :foo"
end
it 'should append the user config file if present' do
fake_guardfile('/abc/Guardfile', "guard :foo")
fake_guardfile(@user_config_path, "guard :bar")
Guard::UI.should_not_receive(:error)
lambda { described_class.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.should_not raise_error
described_class.guardfile_contents_with_user_config.should == "guard :foo\nguard :bar"
end
end
it "receive options when specified" do
mock_guardfile_content("guard 'test', :opt_a => 1, :opt_b => 'fancy'")
::Guard.should_receive(:add_guard).with('test', anything, { :opt_a => 1, :opt_b => 'fancy' })
subject.evaluate_guardfile
it "displays an error message when no Guardfile is found" do
described_class.stub(:guardfile_default_path).and_return("no_guardfile_here")
Guard::UI.should_receive(:error).with("No Guardfile found, please create one with `guard init`.")
lambda { described_class.evaluate_guardfile }.should raise_error
end
it "displays an error message when no guard are defined in Guardfile" do
::Guard::Dsl.stub!(:instance_eval_guardfile)
::Guard.stub!(:guards).and_return([])
Guard::UI.should_receive(:error)
described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string)
end
describe "correctly reads data from its valid data source" do
before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) }
disable_user_config
it "reads correctly from a string" do
lambda { described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.should_not raise_error
described_class.guardfile_contents.should == valid_guardfile_string
end
it "reads correctly from a Guardfile" do
fake_guardfile('/abc/Guardfile', "guard :foo" )
lambda { described_class.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.should_not raise_error
described_class.guardfile_contents.should == "guard :foo"
end
it "reads correctly from a Guardfile" do
fake_guardfile(File.join(Dir.pwd, 'Guardfile'), valid_guardfile_string)
lambda { described_class.evaluate_guardfile }.should_not raise_error
described_class.guardfile_contents.should == valid_guardfile_string
end
end
describe "correctly throws errors when initializing with invalid data" do
before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) }
it "raises error when there's a problem reading a file" do
File.stub!(:exist?).with('/def/Guardfile') { true }
File.stub!(:read).with('/def/Guardfile') { raise Errno::EACCES.new("permission error") }
Guard::UI.should_receive(:error).with(/^Error reading file/)
lambda { described_class.evaluate_guardfile(:guardfile => '/def/Guardfile') }.should raise_error
end
it "raises error when given Guardfile doesn't exist" do
File.stub!(:exist?).with('/def/Guardfile') { false }
Guard::UI.should_receive(:error).with(/No Guardfile exists at/)
lambda { described_class.evaluate_guardfile(:guardfile => '/def/Guardfile') }.should raise_error
end
it "raises error when resorting to use default, finds no default" do
File.stub!(:exist?).with(@local_guardfile_path) { false }
File.stub!(:exist?).with(@home_guardfile_path) { false }
Guard::UI.should_receive(:error).with("No Guardfile found, please create one with `guard init`.")
lambda { described_class.evaluate_guardfile }.should raise_error
end
it "raises error when guardfile_content ends up empty or nil" do
Guard::UI.should_receive(:error).with(/The command file/)
lambda { described_class.evaluate_guardfile(:guardfile_contents => "") }.should raise_error
end
it "doesn't raise error when guardfile_content is nil (skipped)" do
Guard::UI.should_not_receive(:error)
lambda { described_class.evaluate_guardfile(:guardfile_contents => nil) }.should_not raise_error
end
end
it "displays an error message when Guardfile is not valid" do
Guard::UI.should_receive(:error).with(/Invalid Guardfile, original error is:/)
lambda { described_class.evaluate_guardfile(:guardfile_contents => invalid_guardfile_string ) }.should raise_error
end
describe ".reevaluate_guardfile" do
before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) }
it "resets already definded guards before calling evaluate_guardfile" do
Guard::Notifier.turn_off
described_class.evaluate_guardfile(:guardfile_contents => invalid_guardfile_string)
::Guard.guards.should_not be_empty
::Guard::Dsl.should_receive(:evaluate_guardfile)
described_class.reevaluate_guardfile
::Guard.guards.should be_empty
end
end
describe ".guardfile_default_path" do
let(:local_path) { File.join(Dir.pwd, 'Guardfile') }
let(:user_path) { File.expand_path(File.join("~", '.Guardfile')) }
before(:each) { File.stub(:exist? => false) }
context "when there is a local Guardfile" do
it "returns the path to the local Guardfile" do
File.stub(:exist?).with(local_path).and_return(true)
described_class.guardfile_default_path.should == local_path
end
end
context "when there is a Guardfile in the user's home directory" do
it "returns the path to the user Guardfile" do
File.stub(:exist?).with(user_path).and_return(true)
described_class.guardfile_default_path.should == user_path
end
end
context "when there's both a local and user Guardfile" do
it "returns the path to the local Guardfile" do
File.stub(:exist?).with(local_path).and_return(true)
File.stub(:exist?).with(user_path).and_return(true)
described_class.guardfile_default_path.should == local_path
end
end
end
describe ".guardfile_include?" do
it "detects a guard specified by a string with double quotes" do
described_class.stub(:guardfile_contents => 'guard "test" {watch("c")}')
described_class.guardfile_include?('test').should be_true
end
it "detects a guard specified by a string with single quote" do
described_class.stub(:guardfile_contents => 'guard \'test\' {watch("c")}')
described_class.guardfile_include?('test').should be_true
end
it "detects a guard specified by a symbol" do
described_class.stub(:guardfile_contents => 'guard :test {watch("c")}')
described_class.guardfile_include?('test').should be_true
end
it "detects a guard wrapped in parentheses" do
described_class.stub(:guardfile_contents => 'guard(:test) {watch("c")}')
described_class.guardfile_include?('test').should be_true
end
end
describe "#ignore_paths" do
disable_user_config
it "adds the paths to the listener's ignore_paths" do
::Guard.stub!(:listener).and_return(mock('Listener'))
::Guard.listener.should_receive(:ignore_paths).and_return(ignore_paths = ['faz'])
described_class.evaluate_guardfile(:guardfile_contents => "ignore_paths 'foo', 'bar'")
ignore_paths.should == ['faz', 'foo', 'bar']
end
end
describe "#group" do
disable_user_config
it "evaluates only the specified string group" do
::Guard.should_receive(:add_guard).with('pow', [], [], { :group => :default })
::Guard.should_receive(:add_guard).with('test', [], [], { :group => :w })
described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => [:w])
end
it "evaluates only the specified symbol group" do
::Guard.should_receive(:add_guard).with('pow', [], [], { :group => :default })
::Guard.should_receive(:add_guard).with('test', [], [], { :group => :w })
described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => [:w])
end
it "evaluates only the specified groups (with their options)" do
::Guard.should_receive(:add_guard).with('pow', [], [], { :group => :default })
::Guard.should_receive(:add_guard).with('rspec', [], [], { :group => :x })
::Guard.should_receive(:add_guard).with('ronn', [], [], { :group => :x })
::Guard.should_receive(:add_guard).with('less', [], [], { :group => :y })
described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => [:x, :y])
end
it "evaluates always guard outside any group (even when a group is given)" do
::Guard.should_receive(:add_guard).with('pow', [], [], { :group => :default })
::Guard.should_receive(:add_guard).with('test', [], [], { :group => :w })
described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => [:w])
end
it "evaluates all groups when no group option is specified (with their options)" do
::Guard.should_receive(:add_guard).with('pow', [], [], { :group => :default })
::Guard.should_receive(:add_guard).with('test', [], [], { :group => :w })
::Guard.should_receive(:add_guard).with('rspec', [], [], { :group => :x })
::Guard.should_receive(:add_guard).with('ronn', [], [], { :group => :x })
::Guard.should_receive(:add_guard).with('less', [], [], { :group => :y })
described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string)
end
end
describe "#guard" do
disable_user_config
it "loads a guard specified as a quoted string from the DSL" do
::Guard.should_receive(:add_guard).with('test', [], [], { :group => :default })
described_class.evaluate_guardfile(:guardfile_contents => "guard 'test'")
end
it "loads a guard specified as a double quoted string from the DSL" do
::Guard.should_receive(:add_guard).with('test', [], [], { :group => :default })
described_class.evaluate_guardfile(:guardfile_contents => 'guard "test"')
end
it "loads a guard specified as a symbol from the DSL" do
::Guard.should_receive(:add_guard).with('test', [], [], { :group => :default })
described_class.evaluate_guardfile(:guardfile_contents => "guard :test")
end
it "loads a guard specified as a symbol and called with parens from the DSL" do
::Guard.should_receive(:add_guard).with('test', [], [], { :group => :default })
described_class.evaluate_guardfile(:guardfile_contents => "guard(:test)")
end
it "receives options when specified, from normal arg" do
::Guard.should_receive(:add_guard).with('test', [], [], { :opt_a => 1, :opt_b => 'fancy', :group => :default })
described_class.evaluate_guardfile(:guardfile_contents => "guard 'test', :opt_a => 1, :opt_b => 'fancy'")
end
end
describe "#watch" do
disable_user_config
it "should receive watchers when specified" do
::Guard.should_receive(:add_guard).with('dummy', anything, anything, { :group => :default }) do |name, watchers, callbacks, options|
watchers.size.should == 2
watchers[0].pattern.should == 'a'
watchers[0].action.call.should == proc { 'b' }.call
watchers[1].pattern.should == 'c'
watchers[1].action.should == nil
end
described_class.evaluate_guardfile(:guardfile_contents => "
guard :dummy do
watch('a') { 'b' }
watch('c')
end")
end
end
describe "#callback" do
it "creates callbacks for the guard" do
class MyCustomCallback
def self.call(guard_class, event, args)
# do nothing
end
end
::Guard.should_receive(:add_guard).with('dummy', anything, anything, { :group => :default }) do |name, watchers, callbacks, options|
callbacks.should have(2).items
callbacks[0][:events].should == :start_end
callbacks[0][:listener].call(Guard::Dummy, :start_end, 'foo').should == "Guard::Dummy executed 'start_end' hook with foo!"
callbacks[1][:events].should == [:start_begin, :run_all_begin]
callbacks[1][:listener].should == MyCustomCallback
end
described_class.evaluate_guardfile(:guardfile_contents => '
guard :dummy do
callback(:start_end) { |guard_class, event, args| "#{guard_class} executed \'#{event}\' hook with #{args}!" }
callback(MyCustomCallback, [:start_begin, :run_all_begin])
end')
end
end
private
def mock_guardfile_content(content)
File.stub!(:read).with(File.expand_path('../../../Guardfile', __FILE__)) { content }
def fake_guardfile(name, contents)
File.stub!(:exist?).with(name) { true }
File.stub!(:read).with(name) { contents }
end
def valid_guardfile_string
"
guard :pow
group :w do
guard :test
end
group :x, :halt_on_fail => true do
guard :rspec
guard :ronn
end
group :y do
guard :less
end
"
end
def invalid_guardfile_string
"Bad Guardfile"
end
end

19
spec/guard/group_spec.rb Normal file
View File

@ -0,0 +1,19 @@
require 'spec_helper'
describe Guard::Group do
describe ".initialize" do
it "accepts a name as a string and provides an accessor for it (returning a symbol)" do
described_class.new('foo').name.should eql :foo
end
it "accepts a name as a symbol and provides an accessor for it (returning a symbol)" do
described_class.new(:foo).name.should eql :foo
end
it "accepts options and provides an accessor for it" do
described_class.new('foo', :halt_on_fail => true).options.should == { :halt_on_fail => true }
end
end
end

60
spec/guard/guard_spec.rb Normal file
View File

@ -0,0 +1,60 @@
require 'spec_helper'
describe Guard::Guard do
describe '#initialize' do
it 'assigns the defined watchers' do
watchers = [ Guard::Watcher.new('*') ]
guard = Guard::Guard.new(watchers)
guard.watchers.should eql watchers
end
it 'assigns the defined options' do
options = { :a => 1, :b => 2 }
guard = Guard::Guard.new([], options)
guard.options.should eql options
end
context 'with a group in the options' do
it 'assigns the given group' do
options = { :group => :test }
guard = Guard::Guard.new([], options)
guard.group.should eql :test
end
end
context 'without a group in the options' do
it 'assigns a default group' do
options = { }
guard = Guard::Guard.new([], options)
guard.group.should eql :default
end
end
end
describe '#init' do
context 'when the Guard is already in the Guardfile' do
before { ::Guard::Dsl.stub(:guardfile_include?).and_return true }
it 'shows an info message' do
::Guard::UI.should_receive(:info).with 'Guardfile already includes myguard guard'
Guard::Guard.init('myguard')
end
end
context 'when the Guard is not in the Guardfile' do
before { ::Guard::Dsl.stub(:guardfile_include?).and_return false }
it 'appends the template to the Guardfile' do
File.should_receive(:read).with('Guardfile').and_return 'Guardfile content'
::Guard.should_receive(:locate_guard).with('myguard').and_return '/Users/me/projects/guard-myguard'
File.should_receive(:read).with('/Users/me/projects/guard-myguard/lib/guard/myguard/templates/Guardfile').and_return('Template content')
io = StringIO.new
File.should_receive(:open).with('Guardfile', 'wb').and_yield io
Guard::Guard.init('myguard')
io.string.should eql "Guardfile content\n\nTemplate content\n"
end
end
end
end

89
spec/guard/hook_spec.rb Normal file
View File

@ -0,0 +1,89 @@
require 'spec_helper'
require 'guard/guard'
describe Guard::Hook do
class Guard::Dummy < Guard::Guard; end
let(:guard_class) { ::Guard::Dummy }
let(:listener) { double('listener').as_null_object }
after { described_class.reset_callbacks! }
describe "--module methods--" do
before { described_class.add_callback(listener, guard_class, :start_begin) }
describe ".add_callback" do
it "can add a single callback" do
described_class.has_callback?(listener, guard_class, :start_begin).should be_true
end
it "can add multiple callbacks" do
described_class.add_callback(listener, guard_class, [:event1, :event2])
described_class.has_callback?(listener, guard_class, :event1).should be_true
described_class.has_callback?(listener, guard_class, :event2).should be_true
end
end
describe ".notify" do
it "sends :call to the given Guard class's callbacks" do
listener.should_receive(:call).with(guard_class, :start_begin, "args")
described_class.notify(guard_class, :start_begin, "args")
end
it "runs only the given callbacks" do
listener2 = double('listener2')
described_class.add_callback(listener2, guard_class, :start_end)
listener2.should_not_receive(:call).with(guard_class, :start_end)
described_class.notify(guard_class, :start_begin)
end
it "runs callbacks only for the guard given" do
guard2_class = double('Guard::Dummy2').class
described_class.add_callback(listener, guard2_class, :start_begin)
listener.should_not_receive(:call).with(guard2_class, :start_begin)
described_class.notify(guard_class, :start_begin)
end
end
end
describe "#hook" do
before(:all) do
guard_class.class_eval do
def start
hook "my_hook"
end
def run_all
hook :begin
hook :end
end
def stop
hook :begin, 'args'
hook 'special_sauce', 'first_arg', 'second_arg'
end
end
@guard = guard_class.new
end
it "calls Guard::Hook.notify" do
Guard::Hook.should_receive(:notify).with(guard_class, :run_all_begin)
Guard::Hook.should_receive(:notify).with(guard_class, :run_all_end)
@guard.run_all
end
it "if passed a string parameter, will use that for the hook name" do
Guard::Hook.should_receive(:notify).with(guard_class, :my_hook)
@guard.start
end
it "accepts extra args" do
Guard::Hook.should_receive(:notify).with(guard_class, :stop_begin, 'args')
Guard::Hook.should_receive(:notify).with(guard_class, :special_sauce, 'first_arg', 'second_arg')
@guard.stop
end
end
end

View File

@ -0,0 +1,6 @@
require 'spec_helper'
describe Guard::Interactor do
subject { Guard::Interactor.new }
end

View File

@ -1,34 +1,291 @@
require 'spec_helper'
describe Guard::Listener do
subject { described_class }
describe "init" do
before(:each) { @target_os = Config::CONFIG['target_os'] }
after(:each) { Config::CONFIG['target_os'] = @target_os }
it "should use darwin listener on Mac OS X" do
Config::CONFIG['target_os'] = 'darwin10.4.0'
describe '.select_and_init' do
before(:each) { @target_os = RbConfig::CONFIG['target_os'] }
after(:each) { RbConfig::CONFIG['target_os'] = @target_os }
it 'uses the Darwin listener on Mac OS X' do
RbConfig::CONFIG['target_os'] = 'darwin10.4.0'
Guard::Darwin.stub(:usable?).and_return(true)
Guard::Darwin.should_receive(:new)
subject.init
described_class.select_and_init
end
it "should use polling listener on Windows" do
Config::CONFIG['target_os'] = 'win32'
Guard::Polling.stub(:usable?).and_return(true)
Guard::Polling.should_receive(:new)
subject.init
it 'uses the Windows listener on Windows' do
RbConfig::CONFIG['target_os'] = 'mingw'
Guard::Windows.stub(:usable?).and_return(true)
Guard::Windows.should_receive(:new)
described_class.select_and_init
end
it "should use linux listener on Linux" do
Config::CONFIG['target_os'] = 'linux'
it 'uses the Linux listener on Linux' do
RbConfig::CONFIG['target_os'] = 'linux'
Guard::Linux.stub(:usable?).and_return(true)
Guard::Linux.should_receive(:new)
subject.init
described_class.select_and_init
end
it 'forwards its arguments to the constructor' do
described_class.stub!(:mac?).and_return(true)
Guard::Darwin.stub!(:usable?).and_return(true)
path, opts = 'path', { :foo => 23 }
Guard::Darwin.should_receive(:new).with(path, opts).and_return(true)
described_class.select_and_init(path, opts)
end
end
end
describe '#all_files' do
subject { described_class.new(@fixture_path) }
it 'should return all files' do
subject.all_files.should =~
Dir.glob("#{ @fixture_path }/**/*", File::FNM_DOTMATCH).select { |file| File.file?(file) }
end
end
describe '#relativize_paths' do
subject { described_class.new('/tmp') }
let(:paths) { %w( /tmp/a /tmp/a/b /tmp/a.b/c.d ) }
it 'should relativize paths to the configured directory' do
subject.relativize_paths(paths).should =~ %w( a a/b a.b/c.d )
end
context 'when set to false' do
subject { described_class.new('/tmp', :relativize_paths => false) }
it 'can be disabled' do
subject.relativize_paths(paths).should eql paths
end
end
end
describe '#update_last_event' do
subject { described_class.new }
it 'updates the last event to the current time' do
time = Time.now
subject.update_last_event
subject.instance_variable_get(:@last_event).to_i.should >= time.to_i
end
end
describe '#modified_files' do
subject { described_class.new }
let(:file1) { fixture('folder1', 'file1.txt') }
let(:file2) { fixture('folder1', 'folder2', 'file2.txt') }
let(:file3) { fixture('folder1', 'deletedfile1.txt') }
let(:file4) { fixture('folder1', 'movedfile1.txt') }
let(:file5) { fixture('folder1', 'folder2', 'movedfile1.txt') }
before { listen_to subject }
context 'without the :all option' do
it 'finds modified files only in the directory supplied' do
watch do
FileUtils.touch([file1, file2, file3])
subject.modified_files([fixture('folder1')], {}).should =~
['spec/fixtures/folder1/deletedfile1.txt', 'spec/fixtures/folder1/file1.txt']
end
end
end
context 'with the :all options' do
it 'finds modified files within subdirectories' do
watch do
FileUtils.touch([file1, file2, file3])
subject.modified_files([fixture('folder1')], { :all => true }).should =~
['spec/fixtures/folder1/deletedfile1.txt',
'spec/fixtures/folder1/file1.txt',
'spec/fixtures/folder1/folder2/file2.txt']
end
end
end
context 'without updating the content' do
it 'ignores the files for the second time' do
watch do
FileUtils.touch([file1, file2, file3])
subject.modified_files([fixture('folder1')], {}).should =~
['spec/fixtures/folder1/deletedfile1.txt', 'spec/fixtures/folder1/file1.txt']
subject.update_last_event
FileUtils.touch([file1, file2, file3])
subject.modified_files([fixture('folder1')], {}).should be_empty
end
end
end
context 'with content that has changed' do
after { File.open(file1, 'w') { |f| f.write('') } }
it 'identifies the files for the second time' do
watch do
FileUtils.touch([file1, file2, file3])
subject.modified_files([fixture('folder1')], {}).should =~
['spec/fixtures/folder1/deletedfile1.txt', 'spec/fixtures/folder1/file1.txt']
subject.update_last_event
FileUtils.touch([file2, file3])
File.open(file1, 'w') { |f| f.write('changed content') }
subject.modified_files([fixture('folder1')], {}).should =~
['spec/fixtures/folder1/file1.txt']
end
end
end
context 'without the :watch_all_modifications option' do
after { FileUtils.touch(file3) }
it 'defaults to false' do
subject.instance_variable_get(:@watch_all_modifications).should eql false
end
context 'for a deleted file' do
after { FileUtils.touch(file3) }
it 'does not catch the deletion' do
File.exists?(file3).should be_true
watch do
FileUtils.remove_file(file3)
end
subject.modified_files([fixture('folder1')], {}).should =~ []
end
end
context 'for a moved file' do
after { FileUtils.move(file4, file1) }
it 'does not catch the move' do
File.exists?(file1).should be_true
File.exists?(file4).should be_false
watch do
FileUtils.move(file1, file4)
end
subject.modified_files([@fixture_path.join('folder1')], {}).should =~ []
end
end
end
context 'with the :watch_all_modifications option' do
subject { described_class.new(Dir.pwd, :watch_all_modifications => true) }
before do
subject.timestamp_files
subject.update_last_event
end
it 'should be true when set' do
subject.instance_variable_get(:@watch_all_modifications).should eql true
end
context 'for a deleted file' do
after { FileUtils.touch(file3) }
it 'catches the deletion' do
File.exists?(file3).should be_true
watch do
FileUtils.remove_file(file3)
end
subject.modified_files([fixture('folder1')], {}).should =~
['!spec/fixtures/folder1/deletedfile1.txt']
end
end
context 'for a moved file' do
after { FileUtils.move(file4, file1) }
it 'catches the move' do
File.exists?(file1).should be_true
File.exists?(file4).should be_false
watch do
FileUtils.move(file1, file4)
end
subject.modified_files([@fixture_path.join('folder1')], {}).should =~
['!spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/movedfile1.txt']
end
end
end
end
describe 'working directory' do
context 'unspecified' do
subject { described_class.new }
it 'defaults to Dir.pwd' do
subject.instance_variable_get(:@directory).should eql Dir.pwd
end
it 'can be not changed' do
subject.should_not respond_to(:directory=)
end
end
context 'specified as first argument to ::new' do
let(:working_directory) { fixture('folder1') }
subject { described_class.new working_directory }
before { listen_to subject }
it 'can be inspected' do
subject.instance_variable_get(:@directory).should eql working_directory.to_s
end
it 'can be not changed' do
subject.should_not respond_to(:directory=)
end
it 'will be used to watch' do
subject.should_receive(:watch).with(working_directory.to_s)
start
stop
end
end
end
describe '#ignore_paths' do
it 'defaults to the default ignore paths' do
described_class.new.ignore_paths.should == Guard::Listener::DEFAULT_IGNORE_PATHS
end
it 'can be added to via :ignore_paths option' do
listener = described_class.new 'path', :ignore_paths => ['foo', 'bar']
listener.ignore_paths.should include('foo', 'bar')
end
end
describe '#exclude_ignored_paths [<dirs>]' do
let(:ignore_paths) { nil }
subject { described_class.new(@fixture_path, { :ignore_paths => ignore_paths }) }
it 'returns children of <dirs>' do
subject.exclude_ignored_paths(['spec/fixtures']).should =~
['spec/fixtures/.dotfile', 'spec/fixtures/folder1', 'spec/fixtures/Guardfile']
end
describe 'when ignore_paths set to some of <dirs> children' do
let(:ignore_paths) { ['Guardfile', '.dotfile'] }
it 'excludes the ignored paths' do
subject.exclude_ignored_paths(['spec/fixtures']).should =~ ['spec/fixtures/folder1']
end
end
end
end

View File

@ -2,72 +2,26 @@ require 'spec_helper'
require 'guard/listeners/darwin'
describe Guard::Darwin do
subject { Guard::Darwin }
if windows?
it "isn't usable on windows" do
described_class.should_not be_usable
end
end
if linux?
it "should not be usable on linux" do
subject.should_not be_usable
it "isn't usable on linux" do
described_class.should_not be_usable
end
end
if mac?
it "should be usable on 10.6" do
subject.should be_usable
end
describe "watch" do
before(:each) do
@results = []
@listener = Guard::Darwin.new
@listener.on_change do |files|
@results += files
end
end
it "should catch new file" do
file = @fixture_path.join("newfile.rb")
File.exists?(file).should be_false
start
FileUtils.touch file
stop
File.delete file
@results.should == ['spec/fixtures/newfile.rb']
end
it "should catch file update" do
file = @fixture_path.join("folder1/file1.txt")
File.exists?(file).should be_true
start
FileUtils.touch file
stop
@results.should == ['spec/fixtures/folder1/file1.txt']
end
it "should catch files update" do
file1 = @fixture_path.join("folder1/file1.txt")
file2 = @fixture_path.join("folder1/folder2/file2.txt")
File.exists?(file1).should be_true
File.exists?(file2).should be_true
start
FileUtils.touch file1
FileUtils.touch file2
stop
@results.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt']
end
if mac? && Guard::Darwin.usable?
it "is usable on 10.6" do
described_class.should be_usable
end
it_should_behave_like "a listener that reacts to #on_change"
it_should_behave_like "a listener scoped to a specific directory"
end
private
def start
sleep 1
Thread.new { @listener.start }
sleep 1
end
def stop
sleep 1
@listener.stop
end
end

View File

@ -3,30 +3,35 @@ require 'fileutils'
require 'guard/listeners/linux'
describe Guard::Linux do
subject { Guard::Linux }
if mac?
it "should not be usable on 10.6" do
subject.should_not be_usable
it "isn't usable on 10.6" do
described_class.should_not be_usable
end
end
if linux?
it "should be usable on linux" do
subject.should be_usable
if windows?
it "isn't usable on windows" do
described_class.should_not be_usable
end
end
if linux? && Guard::Linux.usable?
it "is usable on linux" do
described_class.should be_usable
end
describe "start" do
describe "#start", :long_running => true do
before(:each) do
@listener = Guard::Linux.new
end
it "should call watch_change if first start" do
it "calls watch_change on the first start" do
@listener.should_receive(:watch_change)
start
end
it "should not call watch_change if start after stop" do
it "doesn't call watch_change on subsequent starts after a stop" do
@listener.stub!(:stop)
start
stop
@ -37,94 +42,35 @@ describe Guard::Linux do
stop
@listener.should_not be_watch_change
end
end
describe "watch" do
before(:each) do
@results = []
@listener = Guard::Linux.new
@listener.on_change do |files|
@results += files
end
end
it "should catch new file" do
file = @fixture_path.join("newfile.rb")
File.exists?(file).should be_false
start
FileUtils.touch file
stop
File.delete file
@results.should == ['spec/fixtures/newfile.rb']
end
it "should catch file update" do
file = @fixture_path.join("folder1/file1.txt")
File.exists?(file).should be_true
start
File.open(file, 'w') {|f| f.write('') }
stop
@results.should == ['spec/fixtures/folder1/file1.txt']
end
it "should catch files update" do
file1 = @fixture_path.join("folder1/file1.txt")
file2 = @fixture_path.join("folder1/folder2/file2.txt")
File.exists?(file1).should be_true
File.exists?(file2).should be_true
start
File.open(file1, 'w') {|f| f.write('') }
File.open(file2, 'w') {|f| f.write('') }
stop
@results.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt']
end
it "should catch deleted file" do
file = @fixture_path.join("folder1/file1.txt")
File.exists?(file).should be_true
start
File.delete file
stop
FileUtils.touch file
@results.should == ['spec/fixtures/folder1/file1.txt']
end
it "should catch moved file" do
file1 = @fixture_path.join("folder1/file1.txt")
file2 = @fixture_path.join("folder1/movedfile1.txt")
File.exists?(file1).should be_true
File.exists?(file2).should be_false
start
FileUtils.mv file1, file2
stop
FileUtils.mv file2, file1
@results.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/movedfile1.txt']
end
it "should not process change if stopped" do
file = @fixture_path.join("folder1/file1.txt")
File.exists?(file).should be_true
start
@listener.inotify.should_not_receive(:process)
stop
File.open(file, 'w') {|f| f.write('') }
end
it_should_behave_like "a listener that reacts to #on_change"
it_should_behave_like "a listener scoped to a specific directory"
# Fun fact: FileUtils.touch seems not to be enough on Linux to trigger a modify event
it "catches modified files with glib saving routine (like Vim, Emacs or Gedit)" do
@listener = described_class.new
record_results
file = @fixture_path.join("folder1/file1.txt")
File.exists?(file).should be_true
start
File.open(file, 'r+').close
FileUtils.touch(file)
stop
results.should =~ ['spec/fixtures/folder1/file1.txt']
end
it "doesn't process a change when it is stopped" do
@listener = described_class.new
record_results
file = @fixture_path.join("folder1/file1.txt")
File.exists?(file).should be_true
start
@listener.instance_variable_get(:@inotify).should_not_receive(:process)
stop
File.open(file, 'w') {|f| f.write('') }
end
end
private
def start
sleep 1
Thread.new { @listener.start }
sleep 1
end
def stop
sleep 1
@listener.stop
sleep 1
end
end

View File

@ -2,56 +2,8 @@ require 'spec_helper'
require 'guard/listeners/polling'
describe Guard::Polling do
before(:each) do
@results = []
@listener = Guard::Polling.new
@listener.on_change do |files|
@results += files
end
end
it "should catch new file" do
file = @fixture_path.join("newfile.rb")
File.exists?(file).should be_false
start
FileUtils.touch file
stop
File.delete file
@results.should == ['spec/fixtures/newfile.rb']
end
it "should catch file update" do
file = @fixture_path.join("folder1/file1.txt")
File.exists?(file).should be_true
start
FileUtils.touch file
stop
@results.should == ['spec/fixtures/folder1/file1.txt']
end
it "should catch files update" do
file1 = @fixture_path.join("folder1/file1.txt")
file2 = @fixture_path.join("folder1/folder2/file2.txt")
File.exists?(file1).should be_true
File.exists?(file2).should be_true
start
FileUtils.touch file1
FileUtils.touch file2
stop
@results.sort.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt']
end
private
def start
Thread.new { @listener.start }
sleep 1
end
def stop
sleep 1
@listener.stop
end
it_should_behave_like "a listener that reacts to #on_change"
it_should_behave_like "a listener scoped to a specific directory"
end

View File

@ -0,0 +1,27 @@
require 'spec_helper'
require 'guard/listeners/windows'
describe Guard::Windows do
if linux?
it "isn't usable on linux" do
described_class.should_not be_usable
end
end
if mac?
it "isn't usable on Mac" do
described_class.should_not be_usable
end
end
if windows?
it "is usable on Windows 2000 and later" do
described_class.should be_usable
end
it_should_behave_like "a listener that reacts to #on_change"
it_should_behave_like "a listener scoped to a specific directory"
end
end

View File

@ -1,36 +1,428 @@
require 'spec_helper'
describe Guard::Notifier do
subject { Guard::Notifier }
describe "notify" do
before(:each) { ENV["GUARD_ENV"] = 'special_test' }
if mac?
require 'growl'
it "should use Growl on Mac OS X" do
Growl.should_receive(:notify).with("great",
:title => "Guard",
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:name => "Guard"
)
subject.notify 'great', :title => 'Guard'
describe ".turn_off" do
before do
ENV["GUARD_NOTIFY"] = 'true'
described_class.turn_off
end
it "disables the notifications" do
ENV["GUARD_NOTIFY"].should eql 'false'
end
end
describe ".turn_on" do
context "on Mac OS" do
before do
RbConfig::CONFIG.should_receive(:[]).with('target_os').and_return 'darwin'
end
context "with the GrowlNotify library available" do
before do
class ::GrowlNotify
class GrowlNotFound < Exception; end
def self.config ; end
end
end
it "loads the library and enables the notifications" do
described_class.should_receive(:require).with('growl_notify').and_return true
GrowlNotify.should_receive(:application_name).and_return ''
described_class.turn_on
described_class.should be_enabled
end
it "should respond properly to a GrowlNotify exception" do
::GrowlNotify.should_receive(:config).and_raise ::GrowlNotify::GrowlNotFound
::GrowlNotify.should_receive(:application_name).and_return ''
::Guard::UI.should_receive(:info)
described_class.should_receive(:require).with('growl_notify').and_return true
described_class.turn_on
described_class.should_not be_enabled
described_class.growl_library.should eql :growl_notify
end
after do
Object.send(:remove_const, :GrowlNotify)
end
end
context "with the GNTP library available" do
before do
class ::GNTP
def initialize(app); end
def register(config) ; end
end
end
it "loads the library and enables the notifications" do
described_class.should_receive(:require).with('growl_notify').and_raise LoadError
described_class.should_receive(:require).with('ruby_gntp').and_return true
described_class.turn_on
described_class.should be_enabled
described_class.growl_library.should eql :ruby_gntp
end
after do
Object.send(:remove_const, :GNTP)
end
end
context "with the Growl library available" do
it "loads the library and enables the notifications" do
described_class.should_receive(:require).with('growl_notify').and_raise LoadError
described_class.should_receive(:require).with('ruby_gntp').and_raise LoadError
described_class.should_receive(:require).with('growl').and_return true
described_class.turn_on
described_class.should be_enabled
described_class.growl_library.should eql :growl
end
end
context "without a Growl library available" do
it "disables the notifications" do
described_class.should_receive(:require).with('growl_notify').and_raise LoadError
described_class.should_receive(:require).with('ruby_gntp').and_raise LoadError
described_class.should_receive(:require).with('growl').and_raise LoadError
described_class.turn_on
described_class.should_not be_enabled
described_class.growl_library.should be nil
end
end
end
if linux?
require 'libnotify'
it "should use Libnotify on Linux" do
context "on Linux" do
before do
RbConfig::CONFIG.should_receive(:[]).with('target_os').and_return 'linux'
end
context "with the Libnotify library available" do
it "loads the library and enables the notifications" do
described_class.should_receive(:require).with('libnotify').and_return true
described_class.turn_on
described_class.should be_enabled
end
end
context "without the Libnotify library available" do
it "disables the notifications" do
described_class.should_receive(:require).with('libnotify').and_raise LoadError
described_class.turn_on
described_class.should_not be_enabled
end
end
end
context "on Windows" do
before do
RbConfig::CONFIG.should_receive(:[]).with('target_os').and_return 'mswin'
end
context "with the rb-notifu library available" do
it "loads the library and enables the notifications" do
described_class.should_receive(:require).with('rb-notifu').and_return true
described_class.turn_on
described_class.should be_enabled
end
end
context "without the rb-notify library available" do
it "disables the notifications" do
described_class.should_receive(:require).with('rb-notifu').and_raise LoadError
described_class.turn_on
described_class.should_not be_enabled
end
end
end
end
describe ".notify" do
before { described_class.stub(:enabled?).and_return(true) }
context "on Mac OS" do
before do
RbConfig::CONFIG.stub(:[]).and_return 'darwin'
described_class.stub(:require_growl)
end
context 'with growl gem' do
before do
Object.send(:remove_const, :Growl) if defined?(Growl)
Growl = Object.new
described_class.growl_library = :growl
end
after do
Object.send(:remove_const, :Growl)
end
it "passes the notification to Growl" do
Growl.should_receive(:notify).with("great",
:title => "Guard",
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:name => "Guard"
)
described_class.notify 'great', :title => 'Guard'
end
it "don't passes the notification to Growl if library is not available" do
Growl.should_not_receive(:notify)
described_class.growl_library = nil
described_class.should_receive(:enabled?).and_return(false)
described_class.notify 'great', :title => 'Guard'
end
it "allows additional notification options" do
Growl.should_receive(:notify).with("great",
:title => "Guard",
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:name => "Guard",
:priority => 1
)
described_class.notify 'great', :title => 'Guard', :priority => 1
end
it "allows to overwrite a default notification option" do
Growl.should_receive(:notify).with("great",
:title => "Guard",
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:name => "Guard-Cucumber"
)
described_class.notify 'great', :title => 'Guard', :name => "Guard-Cucumber"
end
end
context 'with growl_notify gem' do
before do
Object.send(:remove_const, :GrowlNotify) if defined?(GrowlNotify)
GrowlNotify = Object.new
described_class.growl_library = :growl_notify
end
after do
Object.send(:remove_const, :GrowlNotify)
end
it "passes the notification to Growl" do
GrowlNotify.should_receive(:send_notification).with(
:title => "Guard",
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:application_name => "Guard",
:description => 'great'
)
described_class.notify 'great', :title => 'Guard'
end
it "don't passes the notification to Growl if library is not available" do
GrowlNotify.should_not_receive(:send_notification)
described_class.growl_library = nil
described_class.should_receive(:enabled?).and_return(false)
described_class.notify 'great', :title => 'Guard'
end
it "allows additional notification options" do
GrowlNotify.should_receive(:send_notification).with(
:title => "Guard",
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:application_name => "Guard",
:description => 'great',
:priority => 1
)
described_class.notify 'great', :title => 'Guard', :priority => 1
end
it "throws out the application name since Guard should only use one Growl App Name while running" do
GrowlNotify.should_receive(:send_notification).with(
:title => "Guard",
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:application_name => "Guard",
:description => 'great'
)
described_class.notify 'great', :title => 'Guard', :name => "Guard-Cucumber"
end
end
context 'with ruby_gntp gem' do
before do
described_class.growl_library = :ruby_gntp
described_class.gntp = Object.new
end
it "passes a success notification to Ruby GNTP" do
described_class.gntp.should_receive(:notify).with(
:name => "success",
:text => 'great',
:title => "Guard",
:icon => 'file://' + Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s
)
described_class.notify 'great', :title => 'Guard'
end
it "passes a pending notification to Ruby GNTP" do
described_class.gntp.should_receive(:notify).with(
:name => "pending",
:text => 'great',
:title => "Guard",
:icon => 'file://' + Pathname.new(File.dirname(__FILE__)).join('../../images/pending.png').to_s
)
described_class.notify 'great', :title => 'Guard', :image => :pending
end
it "passes a failure notification to Ruby GNTP" do
described_class.gntp.should_receive(:notify).with(
:name => "failed",
:text => 'great',
:title => "Guard",
:icon => 'file://' + Pathname.new(File.dirname(__FILE__)).join('../../images/failed.png').to_s
)
described_class.notify 'great', :title => 'Guard', :image => :failed
end
it "passes a general notification to Ruby GNTP" do
described_class.gntp.should_receive(:notify).with(
:name => "notify",
:text => 'great',
:title => "Guard",
:icon => 'file:///path/to/custom.png'
)
described_class.notify 'great', :title => 'Guard', :image => '/path/to/custom.png'
end
it "don't passes the notification to Ruby GNTP if library is not available" do
described_class.gntp.should_not_receive(:notify)
described_class.growl_library = nil
described_class.should_receive(:enabled?).and_return(false)
described_class.notify 'great', :title => 'Guard'
end
it "allows additional notification options" do
described_class.gntp.should_receive(:notify).with(
:name => "success",
:text => 'great',
:title => "Guard",
:icon => 'file://' + Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:sticky => true
)
described_class.notify 'great', :title => 'Guard', :sticky => true
end
end
end
context "on Linux" do
before do
RbConfig::CONFIG.stub(:[]).and_return 'linux'
described_class.stub(:require_libnotify)
Object.send(:remove_const, :Libnotify) if defined?(Libnotify)
Libnotify = Object.new
end
after do
Object.send(:remove_const, :Libnotify)
end
it "passes the notification to Libnotify" do
Libnotify.should_receive(:show).with(
:body => "great",
:summary => 'Guard',
:icon_path => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s
:icon_path => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:transient => true
)
subject.notify 'great', :title => 'Guard'
described_class.notify 'great', :title => 'Guard'
end
it "don't passes the notification to Libnotify if library is not available" do
Libnotify.should_not_receive(:show)
described_class.should_receive(:enabled?).and_return(false)
described_class.notify 'great', :title => 'Guard'
end
it "allows additional notification options" do
Libnotify.should_receive(:show).with(
:body => "great",
:summary => 'Guard',
:icon_path => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:transient => true,
:urgency => :critical
)
described_class.notify 'great', :title => 'Guard', :urgency => :critical
end
it "allows to overwrite a default notification option" do
Libnotify.should_receive(:show).with(
:body => "great",
:summary => 'Guard',
:icon_path => '~/.guard/success.png',
:transient => true
)
described_class.notify 'great', :title => 'Guard', :icon_path => '~/.guard/success.png'
end
end
context "on Windows" do
before do
RbConfig::CONFIG.stub(:[]).and_return 'mswin'
described_class.stub(:require_rbnotifu)
Object.send(:remove_const, :Notifu) if defined?(Notifu)
Notifu = Object.new
end
after do
Object.send(:remove_const, :Notifu)
end
it "passes the notification to rb-notifu" do
Notifu.should_receive(:show).with(
:message => "great",
:title => 'Guard',
:type => :info,
:time => 3
)
described_class.notify 'great', :title => 'Guard'
end
it "don't passes the notification to rb-notifu if library is not available" do
Notifu.should_not_receive(:show)
described_class.should_receive(:enabled?).and_return(false)
described_class.notify 'great', :title => 'Guard'
end
it "allows additional notification options" do
Notifu.should_receive(:show).with(
:message => "great",
:title => 'Guard',
:type => :info,
:time => 3,
:nosound => true
)
described_class.notify 'great', :title => 'Guard', :nosound => true
end
it "allows to overwrite a default notification option" do
Notifu.should_receive(:show).with(
:message => "great",
:title => 'Guard',
:type => :info,
:time => 10
)
described_class.notify 'great', :title => 'Guard', :time => 10
end
end
after(:each) { ENV["GUARD_ENV"] = 'test' }
end
end
describe ".enabled?" do
context "when enabled" do
before { ENV["GUARD_NOTIFY"] = 'true' }
it { should be_enabled }
end
context "when disabled" do
before { ENV["GUARD_NOTIFY"] = 'false' }
it { should_not be_enabled }
end
end
end

309
spec/guard/watcher_spec.rb Normal file
View File

@ -0,0 +1,309 @@
require 'spec_helper'
require 'guard/guard'
describe Guard::Watcher do
describe "#initialize" do
it "requires a pattern parameter" do
expect { described_class.new }.to raise_error(ArgumentError)
end
context "with a pattern parameter" do
context "that is a string" do
it "keeps the string pattern unmodified" do
described_class.new('spec_helper.rb').pattern.should == 'spec_helper.rb'
end
end
context "that is a regexp" do
it "keeps the regex pattern unmodified" do
described_class.new(/spec_helper\.rb/).pattern.should == /spec_helper\.rb/
end
end
context "that is a string looking like a regex (deprecated)" do
before(:each) { Guard::UI.should_receive(:info).any_number_of_times }
it "converts the string automatically to a regex" do
described_class.new('^spec_helper.rb').pattern.should == /^spec_helper.rb/
described_class.new('spec_helper.rb$').pattern.should == /spec_helper.rb$/
described_class.new('spec_helper\.rb').pattern.should == /spec_helper\.rb/
described_class.new('.*_spec.rb').pattern.should == /.*_spec.rb/
end
end
end
end
describe "#action" do
it "sets the action to nothing by default" do
described_class.new(/spec_helper\.rb/).action.should be_nil
end
it "sets the action to the supplied block" do
action = lambda { |m| "spec/#{m[1]}_spec.rb" }
described_class.new(%r{^lib/(.*).rb}, action).action.should == action
end
end
describe ".match_files" do
before(:all) do
@guard = Guard::Guard.new
@guard_any_return = Guard::Guard.new
@guard_any_return.options[:any_return] = true
end
context "with a watcher without action" do
context "that is a regex pattern" do
before(:all) { @guard.watchers = [described_class.new(/.*_spec\.rb/)] }
it "returns the paths that matches the regex" do
described_class.match_files(@guard, ['guard_rocks_spec.rb', 'guard_rocks.rb']).should == ['guard_rocks_spec.rb']
end
end
context "that is a string pattern" do
before(:all) { @guard.watchers = [described_class.new('guard_rocks_spec.rb')] }
it "returns the path that matches the string" do
described_class.match_files(@guard, ['guard_rocks_spec.rb', 'guard_rocks.rb']).should == ['guard_rocks_spec.rb']
end
end
end
context "with a watcher action without parameter" do
context "for a watcher that matches file strings" do
before(:all) do
@guard.watchers = [
described_class.new('spec_helper.rb', lambda { 'spec' }),
described_class.new('addition.rb', lambda { 1 + 1 }),
described_class.new('hash.rb', lambda { Hash[:foo, 'bar'] }),
described_class.new('array.rb', lambda { ['foo', 'bar'] }),
described_class.new('blank.rb', lambda { '' }),
described_class.new(/^uptime\.rb/, lambda { `uptime > /dev/null` })
]
end
it "returns a single file specified within the action" do
described_class.match_files(@guard, ['spec_helper.rb']).should == ['spec']
end
it "returns multiple files specified within the action" do
described_class.match_files(@guard, ['hash.rb']).should == ['foo', 'bar']
end
it "returns multiple files by combining the results of different actions" do
described_class.match_files(@guard, ['spec_helper.rb', 'array.rb']).should == ['spec', 'foo', 'bar']
end
it "returns nothing if the action returns something other than a string or an array of strings" do
described_class.match_files(@guard, ['addition.rb']).should == []
end
it "returns nothing if the action response is empty" do
described_class.match_files(@guard, ['blank.rb']).should == []
end
it "returns nothing if the action returns nothing" do
described_class.match_files(@guard, ['uptime.rb']).should == []
end
end
context 'for a watcher that matches information objects' do
before(:all) do
@guard_any_return.watchers = [
described_class.new('spec_helper.rb', lambda { 'spec' }),
described_class.new('addition.rb', lambda { 1 + 1 }),
described_class.new('hash.rb', lambda { Hash[:foo, 'bar'] }),
described_class.new('array.rb', lambda { ['foo', 'bar'] }),
described_class.new('blank.rb', lambda { '' }),
described_class.new(/^uptime\.rb/, lambda { `uptime > /dev/null` })
]
end
it "returns a single file specified within the action" do
described_class.match_files(@guard_any_return, ['spec_helper.rb']).class.should == Array
described_class.match_files(@guard_any_return, ['spec_helper.rb']).empty?.should == false
end
it "returns multiple files specified within the action" do
described_class.match_files(@guard_any_return, ['hash.rb']).should == [{:foo => 'bar'}]
end
it "returns multiple files by combining the results of different actions" do
described_class.match_files(@guard_any_return, ['spec_helper.rb', 'array.rb']).should == ['spec', ['foo', 'bar']]
end
it "returns the evaluated addition argument in an array" do
described_class.match_files(@guard_any_return, ['addition.rb']).class.should == Array
described_class.match_files(@guard_any_return, ['addition.rb'])[0].should == 2
end
it "returns nothing if the action response is empty string" do
described_class.match_files(@guard_any_return, ['blank.rb']).should == ['']
end
it "returns nothing if the action returns empty string" do
described_class.match_files(@guard_any_return, ['uptime.rb']).should == ['']
end
end
end
context "with a watcher action that takes a parameter" do
context "for a watcher that matches file strings" do
before(:all) do
@guard.watchers = [
described_class.new(%r{lib/(.*)\.rb}, lambda { |m| "spec/#{m[1]}_spec.rb" }),
described_class.new(/addition(.*)\.rb/, lambda { |m| 1 + 1 }),
described_class.new('hash.rb', lambda { |m| Hash[:foo, 'bar'] }),
described_class.new(/array(.*)\.rb/, lambda { |m| ['foo', 'bar'] }),
described_class.new(/blank(.*)\.rb/, lambda { |m| '' }),
described_class.new(/uptime(.*)\.rb/, lambda { |m| `uptime > /dev/null` })
]
end
it "returns a substituted single file specified within the action" do
described_class.match_files(@guard, ['lib/my_wonderful_lib.rb']).should == ['spec/my_wonderful_lib_spec.rb']
end
it "returns multiple files specified within the action" do
described_class.match_files(@guard, ['hash.rb']).should == ['foo', 'bar']
end
it "returns multiple files by combining the results of different actions" do
described_class.match_files(@guard, ['lib/my_wonderful_lib.rb', 'array.rb']).should == ['spec/my_wonderful_lib_spec.rb', 'foo', 'bar']
end
it "returns nothing if the action returns something other than a string or an array of strings" do
described_class.match_files(@guard, ['addition.rb']).should == []
end
it "returns nothing if the action response is empty" do
described_class.match_files(@guard, ['blank.rb']).should == []
end
it "returns nothing if the action returns nothing" do
described_class.match_files(@guard, ['uptime.rb']).should == []
end
end
context "for a watcher that matches information objects" do
before(:all) do
@guard_any_return.watchers = [
described_class.new(%r{lib/(.*)\.rb}, lambda { |m| "spec/#{m[1]}_spec.rb" }),
described_class.new(/addition(.*)\.rb/, lambda { |m| (1 + 1).to_s + m[0] }),
described_class.new('hash.rb', lambda { |m| Hash[:foo, 'bar', :file_name, m[0]] }),
described_class.new(/array(.*)\.rb/, lambda { |m| ['foo', 'bar', m[0]] }),
described_class.new(/blank(.*)\.rb/, lambda { |m| '' }),
described_class.new(/uptime(.*)\.rb/, lambda { |m| `uptime > /dev/null` })
]
end
it "returns a substituted single file specified within the action" do
described_class.match_files(@guard_any_return, ['lib/my_wonderful_lib.rb']).should == ['spec/my_wonderful_lib_spec.rb']
end
it "returns a hash specified within the action" do
described_class.match_files(@guard_any_return, ['hash.rb']).should == [{:foo => 'bar', :file_name => 'hash.rb'}]
end
it "returns multiple files by combining the results of different actions" do
described_class.match_files(@guard_any_return, ['lib/my_wonderful_lib.rb', 'array.rb']).should == ['spec/my_wonderful_lib_spec.rb', ['foo', 'bar', "array.rb"]]
end
it "returns the evaluated addition argument + the path" do
described_class.match_files(@guard_any_return, ['addition.rb']).should == ["2addition.rb"]
end
it "returns nothing if the action response is empty string" do
described_class.match_files(@guard_any_return, ['blank.rb']).should == ['']
end
it "returns nothing if the action returns empty string" do
described_class.match_files(@guard_any_return, ['uptime.rb']).should == ['']
end
end
end
context "with an exception that is raised" do
before(:all) { @guard.watchers = [described_class.new('evil.rb', lambda { raise "EVIL" })] }
it "displays the error and backtrace" do
Guard::UI.should_receive(:error) do |msg|
msg.should include("Problem with watch action!")
msg.should include("EVIL")
end
described_class.match_files(@guard, ['evil.rb'])
end
end
end
describe ".match_files?" do
before(:all) do
@guard1 = Guard::Guard.new([described_class.new(/.*_spec\.rb/)])
@guard2 = Guard::Guard.new([described_class.new('spec_helper.rb', 'spec')])
@guards = [@guard1, @guard2]
end
context "with a watcher that matches a file" do
specify { described_class.match_files?(@guards, ['lib/my_wonderful_lib.rb', 'guard_rocks_spec.rb']).should be_true }
end
context "with no watcher that matches a file" do
specify { described_class.match_files?(@guards, ['lib/my_wonderful_lib.rb']).should be_false }
end
end
describe "#match_file?" do
context "with a string pattern" do
context "that is a normal string" do
subject { described_class.new('guard_rocks_spec.rb') }
context "with a watcher that matches a file" do
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
end
context "with no watcher that matches a file" do
specify { subject.match_file?('lib/my_wonderful_lib.rb').should be_false }
end
end
context "that is a string representing a regexp (deprecated)" do
subject { described_class.new('^guard_rocks_spec\.rb$') }
context "with a watcher that matches a file" do
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
end
context "with no watcher that matches a file" do
specify { subject.match_file?('lib/my_wonderful_lib.rb').should be_false }
end
end
end
context "that is a regexp pattern" do
subject { described_class.new(/.*_spec\.rb/) }
context "with a watcher that matches a file" do
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
end
context "with no watcher that matches a file" do
specify { subject.match_file?('lib/my_wonderful_lib.rb').should be_false }
end
end
end
describe ".match_guardfile?" do
before(:all) { Guard::Dsl.stub(:guardfile_path) { Dir.pwd + '/Guardfile' } }
context "with files that match the Guardfile" do
specify { described_class.match_guardfile?(['Guardfile', 'guard_rocks_spec.rb']).should be_true }
end
context "with no files that match the Guardfile" do
specify { described_class.match_guardfile?(['guard_rocks.rb', 'guard_rocks_spec.rb']).should be_false }
end
end
end

View File

@ -1,97 +1,638 @@
require 'spec_helper'
# mute UI
module Guard::UI
class << self
def info(message, options = {})
end
def error(message)
end
def debug(message)
end
end
end
require 'guard/guard'
describe Guard do
describe "get_guard_class" do
it "should return Guard::RSpec" do
Guard.get_guard_class('rspec').should == Guard::RSpec
describe ".initialize_template" do
context "with a Guard name" do
it "initializes a the Guard" do
class Guard::TestGuard < Guard::Guard
end
Guard::TestGuard.should_receive(:init)
Guard.initialize_template('test-guard')
end
end
context "without a Guard name" do
context "with an existing Guardfile" do
before do
File.stub(:exist?).and_return true
Dir.stub(:pwd).and_return "/home/user"
end
it "shows an error" do
Guard.should_receive(:exit).with 1
::Guard::UI.should_receive(:error).with("Guardfile already exists at /home/user/Guardfile")
Guard.initialize_template()
end
end
context "without an existing Guardfile" do
before do
File.stub(:exist?).and_return false
Dir.stub(:pwd).and_return "/home/user"
end
it "copies the Guardfile template" do
::Guard::UI.should_receive(:info).with("Writing new Guardfile to /home/user/Guardfile")
FileUtils.should_receive(:cp).with(an_instance_of(String), 'Guardfile')
Guard.initialize_template()
end
end
end
end
describe "locate_guard" do
it "should return guard-rspec gem path" do
guard_path = Guard.locate_guard('rspec')
guard_path.should match(/^.*\/guard-rspec-.*$/)
guard_path.should == guard_path.chomp
describe ".setup" do
subject { ::Guard.setup }
it "returns itself for chaining" do
subject.should be ::Guard
end
end
describe "init" do
subject { ::Guard.init }
it "Should retrieve itself for chaining" do
subject.should be_kind_of(Module)
it "initializes @guards" do
subject.guards.should eql []
end
it "Should init guards array" do
::Guard.guards.should be_kind_of(Array)
it "initializes @groups" do
described_class.groups[0].name.should eql :default
described_class.groups[0].options.should == {}
end
it "Should init options" do
opts = {:my_opts => true}
::Guard.init(opts).options.should be_include(:my_opts)
it "initializes the options" do
opts = { :my_opts => true }
Guard.setup(opts).options.should include(:my_opts)
end
it "Should init listeners" do
it "initializes the listener" do
::Guard.listener.should be_kind_of(Guard::Listener)
end
end
describe "supervised_task" do
subject { ::Guard.init }
before :each do
@g = mock(Guard::Guard)
@g.stub!(:regular).and_return { true }
@g.stub!(:spy).and_return { raise "I break your system" }
@g.stub!(:pirate).and_raise Exception.new("I blow your system up")
@g.stub!(:regular_arg).with("given_path").and_return { "given_path" }
subject.guards.push @g
it "respect the watchdir option" do
::Guard.setup(:watchdir => "/foo/bar")
::Guard.listener.directory.should eql "/foo/bar"
end
it "should let it go when nothing special occurs" do
subject.guards.should be_include(@g)
subject.supervised_task(@g, :regular).should be_true
subject.guards.should be_include(@g)
it "turns on the notifier by default" do
ENV["GUARD_NOTIFY"] = nil
::Guard::Notifier.should_receive(:turn_on)
::Guard.setup(:notify => true)
end
it "should let it work with some tools" do
subject.guards.should be_include(@g)
subject.supervised_task(@g, :regular).should be_true
subject.guards.should be_include(@g)
it "turns off the notifier if the notify option is false" do
::Guard::Notifier.should_receive(:turn_off)
::Guard.setup(:notify => false)
end
it "should fire the guard on spy act discovery" do
subject.guards.should be_include(@g)
::Guard.supervised_task(@g, :spy).should be_kind_of(Exception)
subject.guards.should_not be_include(@g)
::Guard.supervised_task(@g, :spy).message.should == 'I break your system'
it "turns off the notifier if environment variable GUARD_NOTIFY is false" do
ENV["GUARD_NOTIFY"] = 'false'
::Guard::Notifier.should_receive(:turn_off)
::Guard.setup(:notify => true)
end
it "should fire the guard on pirate act discovery" do
subject.guards.should be_include(@g)
::Guard.supervised_task(@g, :regular_arg, "given_path").should be_kind_of(String)
subject.guards.should be_include(@g)
::Guard.supervised_task(@g, :regular_arg, "given_path").should == "given_path"
it "logs command execution if the debug option is true" do
::Guard.should_receive(:debug_command_execution)
::Guard.setup(:debug => true)
end
it "initializes the interactor" do
::Guard.setup
::Guard.interactor.should be_kind_of(Guard::Interactor)
end
it "skips the interactor initalization if no-interactions is true" do
::Guard.interactor = nil
::Guard.setup(:no_interactions => true)
::Guard.interactor.should be_nil
end
end
describe ".guards" do
class Guard::FooBar < Guard::Guard; end
class Guard::FooBaz < Guard::Guard; end
subject do
guard = ::Guard.setup
@guard_foo_bar_backend = Guard::FooBar.new([], { :group => 'backend' })
@guard_foo_bar_frontend = Guard::FooBar.new([], { :group => 'frontend' })
@guard_foo_baz_backend = Guard::FooBaz.new([], { :group => 'backend' })
@guard_foo_baz_frontend = Guard::FooBaz.new([], { :group => 'frontend' })
guard.instance_variable_get("@guards").push(@guard_foo_bar_backend)
guard.instance_variable_get("@guards").push(@guard_foo_bar_frontend)
guard.instance_variable_get("@guards").push(@guard_foo_baz_backend)
guard.instance_variable_get("@guards").push(@guard_foo_baz_frontend)
guard
end
it "return @guards without any argument" do
subject.guards.should eql subject.instance_variable_get("@guards")
end
describe "find a guard by as string/symbol" do
it "find a guard by a string" do
subject.guards('foo-bar').should eql @guard_foo_bar_backend
end
it "find a guard by a symbol" do
subject.guards(:'foo-bar').should eql @guard_foo_bar_backend
end
it "returns nil if guard is not found" do
subject.guards('foo-foo').should be_nil
end
end
describe "find guards matching a regexp" do
it "with matches" do
subject.guards(/^foobar/).should eql [@guard_foo_bar_backend, @guard_foo_bar_frontend]
end
it "without matches" do
subject.guards(/foo$/).should eql []
end
end
describe "find guards by their group" do
it "group name is a string" do
subject.guards(:group => 'backend').should eql [@guard_foo_bar_backend, @guard_foo_baz_backend]
end
it "group name is a symbol" do
subject.guards(:group => :frontend).should eql [@guard_foo_bar_frontend, @guard_foo_baz_frontend]
end
it "returns [] if guard is not found" do
subject.guards(:group => :unknown).should eql []
end
end
describe "find guards by their group & name" do
it "group name is a string" do
subject.guards(:group => 'backend', :name => 'foo-bar').should eql [@guard_foo_bar_backend]
end
it "group name is a symbol" do
subject.guards(:group => :frontend, :name => :'foo-baz').should eql [@guard_foo_baz_frontend]
end
it "returns [] if guard is not found" do
subject.guards(:group => :unknown, :name => :'foo-baz').should eql []
end
end
end
describe ".groups" do
subject do
guard = ::Guard.setup
@group_backend = guard.add_group(:backend)
@group_backflip = guard.add_group(:backflip)
guard
end
it "return @groups without any argument" do
subject.groups.should eql subject.instance_variable_get("@groups")
end
describe "find a group by as string/symbol" do
it "find a group by a string" do
subject.groups('backend').should eql @group_backend
end
it "find a group by a symbol" do
subject.groups(:backend).should eql @group_backend
end
it "returns nil if group is not found" do
subject.groups(:foo).should be_nil
end
end
describe "find groups matching a regexp" do
it "with matches" do
subject.groups(/^back/).should eql [@group_backend, @group_backflip]
end
it "without matches" do
subject.groups(/back$/).should eql []
end
end
end
describe ".start" do
it "basic check that core methods are called" do
opts = { :my_opts => true, :guardfile => File.join(@fixture_path, "Guardfile") }
::Guard.should_receive(:setup).with(opts)
::Guard::Dsl.should_receive(:evaluate_guardfile).with(opts)
::Guard.listener.should_receive(:start)
::Guard.start(opts)
end
end
describe ".add_guard" do
before(:each) do
@guard_rspec_class = double('Guard::RSpec')
@guard_rspec = double('Guard::RSpec')
Guard.stub!(:get_guard_class) { @guard_rspec_class }
Guard.setup
end
it "accepts guard name as string" do
@guard_rspec_class.should_receive(:new).and_return(@guard_rspec)
Guard.add_guard('rspec')
end
it "accepts guard name as symbol" do
@guard_rspec_class.should_receive(:new).and_return(@guard_rspec)
Guard.add_guard(:rspec)
end
it "adds guard to the @guards array" do
@guard_rspec_class.should_receive(:new).and_return(@guard_rspec)
Guard.add_guard(:rspec)
Guard.guards.should eql [@guard_rspec]
end
context "with no watchers given" do
it "gives an empty array of watchers" do
@guard_rspec_class.should_receive(:new).with([], {}).and_return(@guard_rspec)
Guard.add_guard(:rspec, [])
end
end
context "with watchers given" do
it "give the watchers array" do
@guard_rspec_class.should_receive(:new).with([:foo], {}).and_return(@guard_rspec)
Guard.add_guard(:rspec, [:foo])
end
end
context "with no options given" do
it "gives an empty hash of options" do
@guard_rspec_class.should_receive(:new).with([], {}).and_return(@guard_rspec)
Guard.add_guard(:rspec, [], [], {})
end
end
context "with options given" do
it "give the options hash" do
@guard_rspec_class.should_receive(:new).with([], { :foo => true, :group => :backend }).and_return(@guard_rspec)
Guard.add_guard(:rspec, [], [], { :foo => true, :group => :backend })
end
end
end
describe ".add_group" do
subject { ::Guard.setup }
it "accepts group name as string" do
subject.add_group('backend')
subject.groups[0].name.should eql :default
subject.groups[1].name.should eql :backend
end
it "accepts group name as symbol" do
subject.add_group(:backend)
subject.groups[0].name.should eql :default
subject.groups[1].name.should eql :backend
end
it "accepts options" do
subject.add_group(:backend, { :halt_on_fail => true })
subject.groups[0].options.should == {}
subject.groups[1].options.should == { :halt_on_fail => true }
end
end
describe ".get_guard_class" do
after do
[:Classname, :DashedClassName, :Inline].each do |const|
Guard.send(:remove_const, const) rescue nil
end
end
it "reports an error if the class is not found" do
::Guard::UI.should_receive(:error).twice
Guard.get_guard_class('notAGuardClass')
end
context 'with a nested Guard class' do
it "resolves the Guard class from string" do
Guard.should_receive(:require) { |classname|
classname.should == 'guard/classname'
class Guard::Classname
end
}
Guard.get_guard_class('classname').should == Guard::Classname
end
it "resolves the Guard class from symbol" do
Guard.should_receive(:require) { |classname|
classname.should == 'guard/classname'
class Guard::Classname
end
}
Guard.get_guard_class(:classname).should == Guard::Classname
end
end
context 'with a name with dashes' do
it "returns the Guard class" do
Guard.should_receive(:require) { |classname|
classname.should == 'guard/dashed-class-name'
class Guard::DashedClassName
end
}
Guard.get_guard_class('dashed-class-name').should == Guard::DashedClassName
end
end
context 'with an inline Guard class' do
it 'returns the Guard class' do
module Guard
class Inline < Guard
end
end
Guard.should_not_receive(:require)
Guard.get_guard_class('inline').should == Guard::Inline
end
end
end
describe ".locate_guard" do
it "returns the path of a Guard gem" do
if Gem::Version.create(Gem::VERSION) >= Gem::Version.create('1.8.0')
gem_location = Gem::Specification.find_by_name("guard-rspec").full_gem_path
else
gem_location = Gem.source_index.find_name("guard-rspec").last.full_gem_path
end
Guard.locate_guard('rspec').should == gem_location
end
end
describe ".guard_gem_names" do
it "returns the list of guard gems" do
gems = Guard.guard_gem_names
gems.should include("rspec")
end
end
describe ".run_guard_task" do
subject { ::Guard.setup }
before do
class Guard::Dummy < Guard::Guard; end
subject.add_group(:foo, { :halt_on_fail => true })
subject.add_group(:bar)
subject.add_guard(:dummy, [], [], { :group => :foo })
subject.add_guard(:dummy, [], [], { :group => :foo })
subject.add_guard(:dummy, [], [], { :group => :bar })
subject.add_guard(:dummy, [], [], { :group => :bar })
@sum = { :foo => 0, :bar => 0}
end
context "all tasks succeed" do
before do
subject.guards.each { |guard| guard.stub!(:task) { @sum[guard.group] += 1; true } }
end
it "executes the task for each guard in each group" do
subject.run_guard_task(:task)
@sum.all? { |k, v| v == 2 }.should be_true
end
end
context "one guard fails" do
before do
subject.guards.each_with_index do |g, i|
g.stub!(:task) do
@sum[g.group] += i+1
if i % 2 == 0
throw :task_has_failed
else
true
end
end
end
end
it "executes the task only for guards that didn't fail for group with :halt_on_fail == true" do
subject.run_guard_task(:task)
@sum[:foo].should eql 1
@sum[:bar].should eql 7
end
end
end
describe ".run_on_change_task" do
let(:guard) do
class Guard::Dummy < Guard::Guard
def watchers
[Guard::Watcher.new(/.+\.rb/)]
end
end
Guard::Dummy.new
end
it 'runs the :run_on_change task with the watched file changes' do
Guard.should_receive(:run_supervised_task).with(guard, :run_on_change, ['a.rb', 'b.rb'])
Guard.run_on_change_task(['a.rb', 'b.rb', 'templates/d.haml'], guard, :run_on_change)
end
it 'runs the :run_on_deletion task with the watched file deletions' do
Guard.should_receive(:run_supervised_task).with(guard, :run_on_deletion, ['c.rb'])
Guard.run_on_change_task(['!c.rb', '!templates/e.haml'], guard, :run_on_change)
end
end
describe ".changed_paths" do
let(:paths) { ['a.rb', 'b.rb', '!c.rb', 'templates/d.haml', '!templates/e.haml'] }
it 'returns the changed paths' do
Guard.changed_paths(paths).should =~ ['a.rb', 'b.rb', 'templates/d.haml']
end
end
describe ".deleted_paths" do
let(:paths) { ['a.rb', 'b.rb', '!c.rb', 'templates/d.haml', '!templates/e.haml'] }
it 'returns the deleted paths' do
Guard.deleted_paths(paths).should =~ ['c.rb', 'templates/e.haml']
end
end
describe ".run_supervised_task" do
subject { ::Guard.setup }
before do
@g = mock(Guard::Guard).as_null_object
subject.guards.push(@g)
subject.add_group(:foo, { :halt_on_fail => true })
subject.add_group(:bar, { :halt_on_fail => false })
end
context "with a task that succeed" do
context 'without any arguments' do
before(:each) do
@g.stub!(:regular_without_arg) { true }
end
it "doesn't fire the Guard" do
lambda { subject.run_supervised_task(@g, :regular_without_arg) }.should_not change(subject.guards, :size)
end
it "returns the result of the task" do
::Guard.run_supervised_task(@g, :regular_without_arg).should be_true
end
it "passes the args to the :begin hook" do
@g.should_receive(:hook).with("regular_without_arg_begin", "given_path")
::Guard.run_supervised_task(@g, :regular_without_arg, "given_path")
end
it "passes the result of the supervised method to the :end hook" do
@g.should_receive(:hook).with("regular_without_arg_begin", "given_path")
@g.should_receive(:hook).with("regular_without_arg_end", true)
::Guard.run_supervised_task(@g, :regular_without_arg, "given_path")
end
end
context 'with arguments' do
before(:each) do
@g.stub!(:regular_with_arg).with("given_path") { "I'm a success" }
end
it "doesn't fire the Guard" do
lambda { subject.run_supervised_task(@g, :regular_with_arg, "given_path") }.should_not change(subject.guards, :size)
end
it "returns the result of the task" do
::Guard.run_supervised_task(@g, :regular_with_arg, "given_path").should eql "I'm a success"
end
it "calls the default begin hook but not the default end hook" do
@g.should_receive(:hook).with("failing_begin")
@g.should_not_receive(:hook).with("failing_end")
::Guard.run_supervised_task(@g, :failing)
end
end
end
context "with a task that throw :task_has_failed" do
context "for a guard's group has the :halt_on_fail option == true" do
before(:each) { @g.stub!(:group) { :foo }; @g.stub!(:failing) { throw :task_has_failed } }
it "throws :task_has_failed" do
expect { subject.run_supervised_task(@g, :failing) }.to throw_symbol(:task_has_failed)
end
end
context "for a guard's group has the :halt_on_fail option == false" do
before(:each) { @g.stub!(:group) { :bar }; @g.stub!(:failing) { throw :task_has_failed } }
it "catches :task_has_failed" do
expect { subject.run_supervised_task(@g, :failing) }.to_not throw_symbol(:task_has_failed)
end
end
end
context "with a task that raises an exception" do
before(:each) { @g.stub!(:group) { :foo }; @g.stub!(:failing) { raise "I break your system" } }
it "fires the Guard" do
lambda { subject.run_supervised_task(@g, :failing) }.should change(subject.guards, :size).by(-1)
subject.guards.should_not include(@g)
end
it "returns the exception" do
failing_result = ::Guard.run_supervised_task(@g, :failing)
failing_result.should be_kind_of(Exception)
failing_result.message.should == 'I break your system'
end
end
end
describe '.guard_symbol' do
let(:guard) { mock(Guard::Guard).as_null_object }
it 'returns :task_has_failed when the group is missing' do
subject.guard_symbol(guard).should eql :task_has_failed
end
context 'for a group with :halt_on_fail' do
let(:group) { mock(Guard::Group) }
before do
guard.stub(:group).and_return :foo
group.stub(:options).and_return({ :halt_on_fail => true })
end
it 'returns :no_catch' do
subject.should_receive(:groups).with(:foo).and_return group
subject.guard_symbol(guard).should eql :no_catch
end
end
context 'for a group without :halt_on_fail' do
let(:group) { mock(Guard::Group) }
before do
guard.stub(:group).and_return :foo
group.stub(:options).and_return({ :halt_on_fail => false })
end
it 'returns :task_has_failed' do
subject.should_receive(:groups).with(:foo).and_return group
subject.guard_symbol(guard).should eql :task_has_failed
end
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

View File

@ -2,20 +2,21 @@ require 'rubygems'
require 'guard'
require 'rspec'
ENV["GUARD_ENV"] = 'test'
Dir["#{File.expand_path('..', __FILE__)}/support/**/*.rb"].each { |f| require f }
puts "Please do not update/create files while tests are running."
RSpec.configure do |config|
config.color_enabled = true
config.filter_run :focus => true
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.before(:each) do
ENV["GUARD_ENV"] = 'test'
@fixture_path = Pathname.new(File.expand_path('../fixtures/', __FILE__))
end
config.after(:each) do
ENV["GUARD_ENV"] = nil
end
end
end

View File

@ -0,0 +1,20 @@
def growl_installed?
require 'growl'
true
rescue LoadError
false
end
def libnotify_installed?
require 'libnotify'
true
rescue LoadError
false
end
def rbnotifu_installed?
require 'rb-notifu'
true
rescue LoadError
false
end

View File

@ -0,0 +1,225 @@
private
# Set the sleep time around start/stop the listener. This defaults
# to one second but can be overridden by setting the environment
# variable `GUARD_SLEEP`.
#
def sleep_time
@sleep_time ||= ENV['GUARD_SLEEP'] ? ENV['GUARD_SLEEP'].to_f : 1
end
# Make the spec listen to a specific listener.
# This automatically starts to record results for the supplied listener.
#
# @param [Guard::Listener] listener the Guard listener
#
def listen_to(listener)
@listener = listener
record_results
end
# Start the listener. Normally you use {#watch} to wrap
# the code block that should be listen to instead of starting
# it manually.
#
def start
sleep(sleep_time)
@listener.update_last_event
Thread.new { @listener.start }
sleep(sleep_time)
end
# Stop the listener. Normally you use {#watch} to wrap
# the code block that should be listen to instead of stopping
# it manually.
#
def stop
sleep(sleep_time)
@listener.stop
sleep(sleep_time)
end
# Watch file changes in a code block.
#
# @example Watch file changes
# watch do
# File.mv file1, file2
# end
#
# @yield The block to listen for file changes
#
def watch
start
yield if block_given?
stop
end
# Start recording results from the current listener.
# You may want to use {#listen_to} to set a listener
# instead of set it up manually.
#
def record_results
# Don't fail specs due to editor swap files, etc.
noise = %r|\.sw.$|
@results = []
@listener.on_change do |files|
@results += files.reject { |f| f =~ noise }
end
end
# Get the recorded result from the listener.
#
# @return [Array<String>] the result files
#
def results
@results.flatten
end
# Define a file absolute to the fixture path.
#
# @param [String, Array<String>] file the relative file name, separated by segment
# @return [String] the absolute file
#
def fixture(*file)
@fixture_path.join(*file)
end
shared_examples_for 'a listener that reacts to #on_change' do
before do
listen_to described_class.new
end
context 'for a new file' do
let(:file) { fixture('newfile.rb') }
before { File.delete(file) if File.exists?(file) }
after { File.delete file }
it 'catches the new file' do
File.exists?(file).should be_false
watch do
FileUtils.touch file
end
results.should =~ ['spec/fixtures/newfile.rb']
end
end
context 'for a single file update' do
let(:file) { fixture('folder1', 'file1.txt') }
it 'catches the update' do
File.exists?(file).should be_true
watch do
File.open(file, 'w') { |f| f.write('') }
end
results.should =~ ['spec/fixtures/folder1/file1.txt']
end
end
context 'for a single file chmod update' do
let(:file) { fixture('folder1/file1.txt') }
it 'does not catch the update' do
File.exists?(file).should be_true
watch do
File.chmod(0777, file)
end
results.should =~ []
end
end
context 'for a dotfile update' do
let(:file) { fixture('.dotfile') }
it "catches the update" do
File.exists?(file).should be_true
watch do
File.open(file, 'w') { |f| f.write('') }
end
results.should =~ ['spec/fixtures/.dotfile']
end
end
context 'for multiple file updates' do
let(:file1) { fixture('folder1', 'file1.txt') }
let(:file2) { fixture('folder1', 'folder2', 'file2.txt') }
it 'catches the updates' do
File.exists?(file1).should be_true
File.exists?(file2).should be_true
watch do
File.open(file1, 'w') { |f| f.write('') }
File.open(file2, 'w') { |f| f.write('') }
end
results.should =~ ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt']
end
end
context 'for a deleted file' do
let(:file) { fixture('folder1', 'file1.txt') }
after { FileUtils.touch file }
it 'does not catch the deletion' do
File.exists?(file).should be_true
watch do
File.delete file
end
results.should =~ []
end
end
context 'for a moved file' do
let(:file1) { fixture('folder1', 'file1.txt') }
let(:file2) { fixture('folder1', 'movedfile1.txt') }
after { FileUtils.mv file2, file1 }
it 'does not catch the move' do
File.exists?(file1).should be_true
File.exists?(file2).should be_false
watch do
FileUtils.mv file1, file2
end
results.should =~ []
end
end
end
shared_examples_for "a listener scoped to a specific directory" do
let(:work_directory) { fixture('folder1') }
let(:new_file) { work_directory.join('folder2', 'newfile.rb') }
let(:modified) { work_directory.join('file1.txt') }
before { listen_to described_class.new(work_directory) }
after { File.delete new_file }
it 'should base paths within this directory' do
File.exists?(modified).should be_true
File.exists?(new_file).should be_false
watch do
FileUtils.touch new_file
File.open(modified, 'w') { |f| f.write('') }
end
results.should =~ ['folder2/newfile.rb', 'file1.txt']
end
end

View File

@ -1,7 +1,11 @@
def mac?
Config::CONFIG['target_os'] =~ /darwin/i
RbConfig::CONFIG['target_os'] =~ /darwin/i
end
def linux?
Config::CONFIG['target_os'] =~ /linux/i
end
RbConfig::CONFIG['target_os'] =~ /linux/i
end
def windows?
RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
end