rspec setup autotest

RSpec, autotest and Snarl on Windows

Earlier this year I started using RSpec and loved it immediately. Testing is not the most exciting or glamorous part of software development but a behavioural driven approach really appealed to me, as did the much more readable RSpec syntax.

To get me started I bought the RSpec Basics screencast from PeepCode (which has since expanded into a 3 part series). It was a good introduction but, as is often the case in Rails-land, it left me with a case of Mac envy.

The screencast includes a section on using autotest (part of the ZenTest package) and Growl to get instant pop-up notifications when specifications pass or fail. But what about me on my trusty Dell laptop? Where are my shiny notifications?

The good news is that autotest also includes support for Snarl, a Windows alternative to Growl. Hurrah!

Here’s how to set it up – I’m assuming that you’ve already got a Rails application with the RSpec plugins installed:

   1.

      Download and install Snarl (version 1.6). You’ll also be asked to install Melon, a Windows development toolkit, but you only need to install the core component when prompted.
   2.

      Install ZenTest (version 3.6.1): gem install --include-dependencies ZenTest
   3.

      Install diff-lcs (version 1.1.2): gem install diff-lcs

      Update: see the comments for additional information about this gem.
   4.

      Install ruby-snarl (version 0.0.8): gem install ruby-snarl
   5.

      Set the HOME user environment variable to your user profile directory, for example on my system it is set to: C:\Documents and Settings\Rob
   6.

      Download the install the GNU DiffUtils package – I installed this into my C:\Windows\System32 directory.
   7.

      Download and unzip the famfamfam Silk icons and copy the following files into $RUBY_HOME\lib\ruby\gems\1.8\gems\ZenTest-3.6.1\lib\icons where $RUBY_HOME is the directory where Ruby is installed:
          * accept.png
          * exclamation.png
          * information.png

      You can of course use any icons you prefer: I’m currently using Crystal icons from Everaldo Coelho. Just make sure you use PNGs and, if necessary, rename them to accept.png, exclamation.png and information.png.
   8.

      Create a file called .autotest in your Rails application root containing:

      require 'autotest/snarl'

   9.

      Open the spec/spec.opts file in your Rails application and remove the --color option (if it is present). My file looks like this:

      --format
      progress
      --loadby
      mtime
      --reverse

  10. A screenshot of Snarl in action

      From your Rails application root type autotest to start the testing process and you should see Snarl notifications popping up as shown in the screenshot on the right.

      Autotest will re-run your specifications each time you change your code and a Snarl notification will popup to tell you if you broke anything.

And finally: if you’re looking for a way to annoy your co-workers then you should take a look at Foz’s sound effects plugin for autotest and maybe use a DHH-style whoops when your specifications fail!

你可能感兴趣的:(windows,Ruby,UP,Rails,rspec)