We’ve been using this great tool in the Da Vinci Coders class called guard-rubocop. It’s a gem for ruby that checks your code for conventions and good code grammar (is that a legit term?). Anyway, I’ll walk through how to install rubocop for a particular directory on your computer.
First, in your terminal, navigate to the directory where you want rubocop to patrol. I wanted to install it in my homework_assignments folder, so for me, this looks like:
$ cd workspace/davinci_coders_t2_2014/homework_assignments
Now, I like to do as much as I can from the terminal, so i typed
This creates a file called Gemfile, which is where your computer will look to find specific gems that you want to install. open the Gemfile in whatever text editor you use (I use Ruby Mine) and type the following:
Save the file and go back to your terminal. In the terminal type
This will look for the Gemfile, and install the gems listed in it.
One last step, which is to initialize guard by typing
You can then run
guard in the terminal from the directory in which it is installed, and it will detect any offensive violations in any of your ruby files within that directory.
The problem that I have encountered is that sometimes when I go back to that directory and try to run guard, it seems to not know what I’m talking about. I don’t know why this happens, but I think I’ve found a fix to this, which is to type
Any insight on why guard seems to forget that it’s there would be appreciated. Thanks!