Topic: Autotest with RSpec on Leopard & autotests on vendor/plugins/my_plugin

Hi all,


Partial solution in the post below this, so read on, or skip this post

This is a pleading for anyone out there that knows how to get this working!  After almost an entire weekend of frustration, shattered confidence and a bleeding forehead, I give up, and hope for the miracle of help from someone that knows how.

The story so far:

I have just setup a clean install of Leopard and have after that installed all the required ruby gems, including rubygems (0.9.5). I've also downloaded Rails 2.0 RC2 and have generated a clean new Rails 2.0 app in which to do my development work. In my Rails app rails_2_0 I have installed the rspec and the rspec_on_rails plugins (rev:3037) from their SVN trunks.

In other words, unless something have changed without me knowing it, I'm 99.9% up to date with the latest.

Now what I want to achieve is to have ZenTest's (v 3.6.1) autotest running in the background as I develop and then output the results via Growl (I have an ~/.autotest file and growlnotify installed), just like I had on Tiger previously.

Now this is where the problems begin. I have managed to get autotest to work relatively stable and it does fire on a change in a file, but it only outputs the results from certain files. ie: changes in the file rails_2_0/spec/ruby/array_extensions_spec.rb does trigger an autotest refresh, BUT it's not part of the result output, which I would like it to be.

Q1:  Is there some way that I could keep the file in it's logical position and still get it included in the autotest output ??

Q2: Why is this so seemingly complicated ? == Why does autotest NOT pick up everything in spec/ with a *_spec.rb file name?


I am developing much of my project in the form of generators and plugins, so I would like to have autotest running on the current plugin directory.  I store my plugins in ~/Code/Rails/Plugins/__PLUGIN_NAME__/, and then symlink them into the rails_2_0 project.

Q3: HOW do I get autotest to recognize a free-standing project like this?

Q4: How can I make it work both free-standing and when the plugin is part of a rails app ?

Q5: How do I make the Test::Unit and RSpec tests in any plugin a part of the rails app in the eyes of the highly discriminating autotest ?

OK, one final, but important, point.
During these past two days, I have tried every single method that could think of, find via Google or sort of work out from the sparse documentation, in order to make this work. I have tried all manners of .autotest configs in both $HOME and inside the projects/rails app. I have tried autotest/discover.rb files in the root and lib directories of plugins, and at various times I have managed to get all sorts of error messages.

IF you have this setup and it is working for you, please spread the knowledge.

Any help extremely much appreciated.

Last edited by kematzy (2007-12-03 20:22:04)

Re: Autotest with RSpec on Leopard & autotests on vendor/plugins/my_plugin

Hi all again wink


No takers (so far) on my previous post, so here's how I got it to semi-work. All of it while using OS X Leopard, Rails 2.0 RC2 and the latest versions of the various components needed.

Rather than write a long spiel about things, here's some dumps of my files & settings:

1. In <RAILS_ROOT>/spec/
-- default version of ../spec_helper.rb
-- default version of ../spec_opts.rb
-- default version of ../rcov_opts.rb

-- Added a sub-directory ../lib/
-- Added a spec file for each of my plugins, ie: ../lib/__NAME_OF_PLUGIN___spec.rb which looks something like this:

require File.dirname(__FILE__) + '/../spec_helper'

# make dummy edits in this file to force refresh of autotest,
# or else just switch to your Terminal and type Ctrl + C to force a autotest refresh

# add an array of all the spec files you wish to test here.
['array','object','hash','class','string','regexp'].each do |file|
  require "vendor/plugins/__NAME_OF_PLUGIN__/spec/lib/ruby/#{file}_extensions_spec.rb"
end


2. In <RAILS_ROOT>/vendor/plugins/__NAME_OF_PLUGIN__/
-- added a sub-directory ../autotest/
-- added a ../autotest/discover.rb 'pointer' file that looks like this:
# concept taken from the 'RSpec' Plugin
require File.dirname(__FILE__) + "/../lib/autotest/discover.rb"

-- added a ../autotest/rspec.rb 'pointer' file that looks like this:
require File.dirname(__FILE__) + "/../lib/autotest/rspec.rb"

3. In <RAILS_ROOT>/vendor/plugins/__NAME_OF_PLUGIN__/lib/
-- added another sub-directory ../autotest/
-- added a ../lib/autotest/discover.rb file that looks like this:
require 'spec'
Autotest.add_discovery do
  ["rails", "rspec"]
end

-- added a ../lib/autotest/rspec.rb file that looks like this:
require 'autotest'
require 'active_support'
require 'autotest/rspec'

# for some reason this needs to be here, or it won't work. Why === ??
class Autotest::Rspec < Autotest
end
class Autotest::RailsRspec < Autotest::Rspec
end


-- the rest of the files in ../lib/ are as usual.


4. In <RAILS_ROOT>/vendor/plugins/__NAME_OF_PLUGIN__/spec/

-- added a ../spec_helper.rb file that looks like this:

# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] = "test"
if __FILE__ !~ /rails_2_0/ ## => __ProjectName__
  # setting the full path so that TextMate's RSpec still works on individual files.
  require "#{ENV['HOME']}/Code/Rails/Projects/rails_2_0/config/environment"
else
  # the path back out to the RAILS_ROOT
  require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
end

require 'spec'
require 'spec/rails'

Spec::Runner.configure do |config|
  config.use_transactional_fixtures = true
  config.use_instantiated_fixtures  = false
  config.fixture_path = RAILS_ROOT + '/spec/fixtures/'

  # You can declare fixtures for each example_group like this:
  #   describe "...." do
  #     fixtures :table_a, :table_b
  #
  # Alternatively, if you prefer to declare them only once, you can
  # do so here, like so ...
  #
  #   config.global_fixtures = :table_a, :table_b
  #
  # If you declare global fixtures, be aware that they will be declared
  # for all of your examples, even those that don't use them.
end

# Custom setups over here


-- added sub-directories to correspond with the main __NAME_OF_PLUGIN__/lib/ directory


The above gives me a fairly OK working autotest solution. However, I still have these problems, that someone might know the answers to:

Q1: In Terminal, the output from autotest is colour free, even though <RAILS_ROOT>/spec/spec.opts has --colour declared. When running rake spec I do get colour output. Any ideas why this is the case ??


Q2: Why does autotest NOT pick up changes to files in /vendor/plugins/__NAME_OF_PLUGIN__/ directories ??

Q3: I have a ~/.autotest file (see below) and this provides me with the Growl notifications. However, it is somewhat temperamental, it sometimes doesn't show when you make changes and saves, although the CLI output in Terminal changes.  Any ideas why ??

#!/usr/bin/env ruby -vw
##  Rails Test::Unit AutoTest script
#   Info taken from: http://software.pmade.com/blogs/ramblin … sting-toys
#   2007-03-12


# NOTE Copy this to your home folder as .autotest
#
# Originally from http://wincent.com/knowledge-base/Setti … _use_Growl
#
# Modifications:
#   * Minor refactoring to use .autotest_images directory
#     [Geoffrey Grosenbach http://peepcode.com]
#   * Test::Unit compatibility [Pat Nakajima]
#
module Autotest::Growl

AUTOTEST_IMAGE_ROOT = "~/.autotest_images/rails"

def self.growl title, msg, img, pri=0, sticky=""
   system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}"
end

def self.growl_fail(output)
   growl "FAIL", "#{output}", "#{AUTOTEST_IMAGE_ROOT}/fail.png", 2
end

def self.growl_pending(output)
   growl "PENDING", "#{output}", "#{AUTOTEST_IMAGE_ROOT}/pending.png", 2
end

def self.growl_pass(output)
   growl "PASS", "#{output}", "#{AUTOTEST_IMAGE_ROOT}/pass.png"
end

Autotest.add_hook :ran_command do |at|

   results = [at.results].flatten.join("\n")

   if results.include? 'tests'
     output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures?(,\s*(\d+)\s+errors)?/)
     if output
       $~[3].to_i + $~[5].to_i > 0 ? growl_fail(output) : growl_pass(output)
     end
   else
     # output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/)
     output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/)
     if output  =~ /[1-9]\sfailures?/
       growl_fail(output)
     elsif output  =~ /[1-9]\spending?/
       growl_pending(output)
     else
       growl_pass(output)
     end
     # if output
     #   $~[2].to_i > 0 ? growl_fail(output) : growl_pass(output)
     # end
   end
end

end


Q4: I cannot get autotest to work in the free-standing project. (Just the plugin on it's own) as I get this error message. (see below). Any ideas why ? and how to fix this ?

MacBookPro:__NAME_OF_PLUGIN__ kematzy$ autotest
### NB! debug output of which files are loaded
loaded autotest/discover [./autotest/discover.rb]
loaded lib/autotest/discover [./autotest/../lib/autotest/discover.rb]
### end debug output
loading autotest/rails_rspec
Autotest style autotest/rails_rspec doesn't seem to exist. Aborting.

OK, I hope the above will be of help to someone else out there, and IF you know the answers, or even ideas/hints to why the above problems are still there, please share that knowledge.

My next post will be a lot shorter, I promise ;-)

Re: Autotest with RSpec on Leopard & autotests on vendor/plugins/my_plugin

This works for growl + rspec

http://www.danielfischer.com/2007/05/14 … owl-rspec/

http://danielfischer.com - Personal Web-Technology-Blog, Los Angeles.

Re: Autotest with RSpec on Leopard & autotests on vendor/plugins/my_plugin

DFischer wrote:

This works for growl + rspec

http://www.danielfischer.com/2007/05/14 … owl-rspec/

Daniel,

That's all rather basic and I already have that and more working (like pending examples notifications, see .autotest code above). 

How does your autotest work with Leopard, Rails 2.0  and developing your own plugins within a rails app ?

Re: Autotest with RSpec on Leopard & autotests on vendor/plugins/my_plugin

Q4: I cannot get autotest to work in the free-standing project. (Just the plugin on it's own) as I get this error message. (see below). Any ideas why ? and how to fix this ?

MacBookPro:__NAME_OF_PLUGIN__ kematzy$ autotest
### NB! debug output of which files are loaded
loaded autotest/discover [./autotest/discover.rb]
loaded lib/autotest/discover [./autotest/../lib/autotest/discover.rb]
### end debug output
loading autotest/rails_rspec
Autotest style autotest/rails_rspec doesn't seem to exist. Aborting.

Hey, i am using autotest on a standard rails project.  I just upgraded my ZenTest and now I get this error:
"Autotest style autotest/rails_rspec doesn't seem to exist"
like you did.  that file is in my tree under vender/plugins/rspec_on_rails/lib/autotest, where it has always been.  You are apparently the only person with this error ever according to Google smile.  Any insights as to how you resolved it?

-Austin

Re: Autotest with RSpec on Leopard & autotests on vendor/plugins/my_plugin

austinfromboston wrote:

Hey, i am using autotest on a standard rails project.  I just upgraded my ZenTest and now I get this error:
"Autotest style autotest/rails_rspec doesn't seem to exist"
like you did.  that file is in my tree under vender/plugins/rspec_on_rails/lib/autotest, where it has always been.  You are apparently the only person with this error ever according to Google smile.  Any insights as to how you resolved it?

-Austin

Hi Austin,

I wish I could help you, but I essentially gave up on Autotest in the end for rails plugin development. It was too moody, sometimes it worked fine, sometimes it did not, sometimes it went on overdrive (= continuously failing the same test a gazillion times until I quit Autotest), and so on.  The lack of clear effective documentation is also a factor in me abandoning it.

How do I work now?  I use Rails Generators (/Users/kematzy/.generators/name_of_generator/) and then have a dev version of  a Rails app that I do the actual code in (NB! not in /vendor/plugins/*, but the actual Rails app), and then copy the final working code into a generator instead. 

Yes, it's not the same as a rails plugin, but then it works, and I don't have to get frustrated and p***ed off every few minutes.

CAVEAT:  I have not tested my stuff with the latest versions of RSpec & ZenTest, so maybe things have improved.  IF it has, please let me know ;-)

Re: Autotest with RSpec on Leopard & autotests on vendor/plugins/my_plugin

austinfromboston wrote:

Q4: I cannot get autotest to work in the free-standing project. (Just the plugin on it's own) as I get this error message. (see below). Any ideas why ? and how to fix this ?

-Austin

I was getting the same thing after an update, I reinstalled the RSpec and RSpec_for_Rails plugins and all is up and running again.

Re: Autotest with RSpec on Leopard & autotests on vendor/plugins/my_plugin

Yes, I updated to the edge versions of both plugins and now all is well.