non-auto spec

October 8th, 2008 by ymendel 4 comments »

I've been resisting updating a few gems because I either don't want the changes or simply don't know what to think about them. Today, however, I decided to get up-to-date on almost everything, and so I went for RSpec 1.1.8. Before this, I was running 1.1.4, and the change I was unsure about involved the autospec command. From the changelog:

IMPORTANT: use ‘script/autospec’ (or just ‘autospec’ if you have the rspec gem installed) instead of ‘autotest’. We changed the way autotest discovers rspec so the autotest executable won‘t automatically load rspec anymore. This allows rspec to live side by side other spec frameworks without always co-opting autotest through autotest‘s discovery mechanism.

I ignore this at first because that's just the way I am, and no tests are run. So I try autospec, and still no tests are run. I managed to track it down to an addition from Rick that's pretty helpful with large projects. Simply add this to your .autotest file

Autotest.send(:alias_method, :real_find_files, :find_files)
Autotest.send(:define_method, :find_files) do |*args|
  pattern = ENV['AUTOTEST']
  files = real_find_files
  if pattern and !pattern.empty?
    files = files.reject { |k, v|  !Regexp.new(pattern).match(k) }
  end
  files
end
(note the use of Hash#reject because Hash#select is stupid)


and then, to make things even easier, define an alias (or function)

ta() {
  AUTOTEST=${1:-.} autotest
}

It turns out that for some reason, autospec sets ENV['AUTOTEST'] to true. So I changed it to use a different name, and still no tests were running, but this time I see files in the command line.

Then I take a closer look.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S spec/spec_helper.rb spec/playlist_spec.rb spec/pj_spec.rb spec/track_spec.rb -O spec/spec.opts

spec/spec_helper.rb, you say? That's interesting. Before the upgrade, it was different.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S /Library/Ruby/Gems/1.8/gems/rspec-1.1.4/bin/spec -O spec/spec.opts spec/playlist_spec.rb

Right now I'm looking at upgrading to a working version of RSpec, like 1.1.4.


Update (22 Oct 2008): RSpec 1.1.9 fixes the problem (by trying to run the specs and not spec/spec_helper.rb). Happy times.

4 Responses to “non-auto spec”

  1. Marcus Derencius Says:

    I’d recommend you to use rspactor to replace autotest for rspec. it uses less resources when pooling for file changes.

    http://rubyphunk.com/projects/rspactor

  2. Dennis Sutch Says:

    Good info—you confirmed my suspicion about what autospec was executing.

    I came up with a temporary solution, which I sent to the rspec-users mail list: http://rubyforge.org/pipermail/rspec-users/2008-October/009361.html

    Maybe it will result in a fix.

  3. Yossef Says:

    Marcus,

    I’ve heard of rspactor before. While I’m not as opinionated as Ryan Davis about platform-specific tools, I’m not sure how much I care to have something OSX-only running my tests, especially if there’s some difficulty in customizing it as easily as autotest. I’ll have to look into it again.

    Dennis,

    Thanks. I’m not using Windows, so it can’t just be that. For the time being, I’m back on 1.1.4 because it works for me.

  4. David Chelimsky Says:

    This is fixed in RSpec 1.1.9

Leave a Reply