Forum: RSpec Setup for autospec for non-rails project

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rick D. (Guest)
on 2008-12-02 19:03
(Received via mailing list)
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/
Mark W. (Guest)
on 2008-12-02 19:14
(Received via mailing list)
On Tue, Dec 2, 2008 at 9:01 AM, Rick DeNatale
<removed_email_address@domain.invalid>wrote:


> main:Object (NoMethodError)
>

Are you requiring 'spec' anywhere?

///ark
Rick D. (Guest)
on 2008-12-02 20:08
(Received via mailing list)
On Tue, Dec 2, 2008 at 12:12 PM, Mark W. <removed_email_address@domain.invalid> 
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/
Rick D. (Guest)
on 2008-12-02 20:21
(Received via mailing list)
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/
Rick D. (Guest)
on 2008-12-02 20:30
(Received via mailing list)
On Tue, Dec 2, 2008 at 1:18 PM, Rick DeNatale
<removed_email_address@domain.invalid>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.
http://github.com/dchelimsky/rspec/commit/d6029bd9...

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/
This topic is locked and can not be replied to.