guard/guard — pull request #368 by jfolkins (2012-11-30 01:50:41+00:00)
Title: `bundle exec guard init` is adding duplicate definitions to the Guardfile

Hello,

In using guard, I found that the specs were running twice. I Google'd around and found several cases where other users were complaining of similar issues. I finally came to understand that it was because there were duplicate definitions in the Guardfile. In my case, the duplications were the result of me accidentally running `guard init` 1+n times and not being keen to the fact that I had done this.

I do not know if this functionality is by design, but I implemented the basic spec tests and code to detect if there were multiple definitions and alert the user to their existence.

Example:

[jfolkins@jfolkins-mbp:~/Programming/Ruby/guard]$ bundle exec guard init
16:40:15 - INFO - ronn guard added to Guardfile, feel free to edit it
16:40:15 - INFO - There are 23 definitions in your Guardfile for 'ronn', you may want to clean up your Guardfile as this could cause issues.
16:40:15 - INFO - rspec guard added to Guardfile, feel free to edit it
16:40:15 - INFO - There are 20 definitions in your Guardfile for 'rspec', you may want to clean up your Guardfile as this could cause issues.

How to duplicate my findings on OSX 10.7.5:

`cd ~`
`git clone git@github.com:guard/guard.git`
`cd guard`
`vi Gemfile`

#Add the following line and :wq
gem 'guard', :path => '~/guard/'

`rvm --create ruby-1.9.2-p290@guard_test_jfolkins_pre`
`bundle install`
`bundle exec guard init`
`bundle exec guard init`
`cat Guardfile`

From here you will hopefully see multiple definitions.

How to test my proposal:

`cd ~`
`git clone git@github.com:jfolkins/guard.git
`cd guard`
`vi Gemfile`

#Add the following line and :wq
gem 'guard', :path => '~/guard/'

`rvm --create ruby-1.9.2-p290@guard_test_jfolkins_post`
`bundle install`
`bundle exec guard init`
`bundle exec guard init`
`cat Guardfile`

Value Proposition:

I believe the solution I have implemented is a reasonable way to clue in the user to potential issues in their Guard file. In my case, I thought it was Guard being buggy and this barrier almost had me drop the use of it in my project. Instead, I decided to be proactive and solve this issue for others.

Thanks for your time and for the software!
jared