Setup for autospec for non-rails project

I brought this up some time ago.

I’m trying to use autotest to run specs in a non-rails project.

FWIW the project is structured using the bones gem.

$ spec -v
rspec 1.1.11
k$ gem list zentest

*** LOCAL GEMS ***

ZenTest (3.11.0, 3.9.1, 3.9.0, 3.8.0, 3.7.1, 3.7.0, 3.6.1)

$ cat .autotest
Autotest.add_hook :initialize do |at|
%w{.svn .hg .git .bzr}.each { |exception| at.add_exception(exception)
}
at.clear_mappings

at.add_mapping(%r%^(spec/(spec_helper|shared/.)|config/(boot|environment(s/test)?)).rb$%)
{
at.files_matching
%r%^spec/(models|controllers|views|helpers)/.
spec.rb$%
}
at.add_mapping(%r%^lib/(.*).rb$%) { |
, m|
[“spec/lib/#{m[1]}_spec.rb”]
}

end

Autotest.add_discovery do
“rspec” if File.directory?(‘spec’) && ENV[‘RSPEC’]
end

$ autospec
loading autotest/rspec
/opt/local/bin/ruby -S spec/lib/v_date_time_property_spec.rb
spec/lib/v_date_property_spec.rb spec/lib/v_property_spec.rb
spec/lib/parser_spec.rb spec/lib/t_z_info_vtimezone_spec.rb
spec/lib/v_date_time_property_spec.rb:8: warning: parenthesize
argument(s)
for future version
spec/lib/v_date_time_property_spec.rb:12: warning: parenthesize
argument(s)
for future version
spec/lib/v_date_time_property_spec.rb:4: undefined method `describe’ for
main:Object (NoMethodError)

For some reason, it’s running the specs as plain old ruby files and the
RSpec framework doesn’t seem to be being intialized.

I’ve done lots of googling about this, and everything about running
autotest
for RSpec for non-rails projects seems to be quite old. I did find one
old
post which recommended making a .autotest file in the project with
mappings
based on the rspec-rails mappings, which is what I tried above, but no
joy.

Any insight?


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

On Tue, Dec 2, 2008 at 9:01 AM, Rick DeNatale
[email protected]wrote:

main:Object (NoMethodError)

Are you requiring ‘spec’ anywhere?

///ark

On Tue, Dec 2, 2008 at 12:12 PM, Mark W. [email protected] wrote:

spec/lib/v_date_time_property_spec.rb:12: warning: parenthesize
argument(s) for future version
spec/lib/v_date_time_property_spec.rb:4: undefined method `describe’ for
main:Object (NoMethodError)

Are you requiring ‘spec’ anywhere?

Adding require ‘spec’ at the top of the .autospec file doesn’t change
anything.

I didn’t mention (this time) that the specs run fine if I use:

  • cmd-R in Textmate to run them via the RSpec bundle.
  • using rake spec
  • individually using the spec command.

The problem seems to lie in something missing in the autotest/autospec
setup.

Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

Okay,

If I add this to my .autospec file

class Autotest::Rspec

def make_test_cmd(files_to_test)
return ‘’ if files_to_test.empty?
return “spec #{files_to_test.keys.flatten.join(’ ')}
#{add_options_if_present}”
end
end

It works.

This replaces a method defined in the rspec gem in lib/autotest/rspec.rb

def make_test_cmd(files_to_test)
return ‘’ if files_to_test.empty?
return “#{ruby} -S #{files_to_test.keys.flatten.join(’ ')}
#{add_options_if_present}”
end

I guess I need to file a bug report?!?


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

On Tue, Dec 2, 2008 at 1:18 PM, Rick DeNatale
[email protected]wrote:

end
end

I guess I need to file a bug report?!?

After investigating github, it looks like a slightly different
fix for this is already in the works.

although it will only work if it’s in the gem code rather than in
.autotest
(it finds the spec command file path relative to the source file).

So for the time being, I’ll just use my .autotest patch


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/