Forum: RSpec autospec: non-standard filenames & redirecting output

Posted by DeNigris Sean (Guest)
on 2010-01-15 05:12
(Received via mailing list)
Rspec gurus,

I have 2 questions about autospec.  I've played around quite a bit, but 
can't figure it out...

1.  I got autospec to work with my directory structure 
("examples/*_example.rb"), but it only works if I have an empty spec/ 
directory.  Otherwise it reverts to running tests instead of examples...
Current ./.autotest:
Autotest.add_discovery do
  "rspec" if File.directory?('examples')
end

Autotest.add_hook(:initialize) {|at|
  ##at.add_exception %r{^\.git}  # ignore Version Control System
  at.clear_mappings         # take out the default (test/test*rb)

  at.add_mapping(%r%^examples/.*_example.rb$%) { |filename, _|
    filename
  }
  at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
    ["examples/#{m[1]}_example.rb"]
  }
  at.add_mapping(%r%^examples/(example_helper|shared/.*)\.rb$%) {
    at.files_matching %r%^examples/.*_example\.rb$%
  }
  nil
}

2.  Does anyone have a technique for redirecting the output (in my case 
to MacVim)?  I really only want it to happen if there are errors.  If 
everything went smoothly, probably a growl notification would be easier.

Thanks!

Sean DeNigris
sean@clipperadams.com

Mac OS X 10.6.2
rspec 1.2.9
ZenTest 4.2.1
Posted by David Chelimsky (Guest)
on 2010-01-15 15:11
(Received via mailing list)
On Thu, Jan 14, 2010 at 10:10 PM, DeNigris Sean 
<sean@clipperadams.com>wrote:

>  "rspec" if File.directory?('examples')
> end
>

If you crack open ZenTest and look at these files:

bin/autotest
lib/autotest.rb

you'll see (eventually) that ./.autotest is loaded too late in the 
process.
It's actually loaded during the initialization of an Autotest object (or
subclass), so the class must already be determined.

Per the docs for autodiscover, all autotest/discover.rb files on your 
path
are loaded in order to determine what file to load. Try adding an 
autotest
directory in your project with a discover.rb file in it with:

Autotest.add_discovery { "rpspec" }


>  at.add_mapping(%r%^examples/(example_helper|shared/.*)\.rb$%) {
>    at.files_matching %r%^examples/.*_example\.rb$%
>  }
>        nil
> }
>
> 2.  Does anyone have a technique for redirecting the output (in my case to
> MacVim)?  I really only want it to happen if there are errors.  If
> everything went smoothly, probably a growl notification would be easier.
>

I'm not sure about redirecting to MacVim, but I do use growl 
notifications
for success and failure. If there's a failure, I go look at the shell
output. FWIW.

HTH,
David
Posted by Sean DeNigris (Guest)
on 2010-01-16 17:52
(Received via mailing list)
> Per the docs for autodiscover, all autotest/discover.rb files on your path
> are loaded in order to determine what file to load. Try adding an autotest
> directory in your project with a discover.rb file in it with:
>
> Autotest.add_discovery { "rpspec" }
Beautiful, worked like a charm, thanks!

Still experimenting with getting the results to MacVim...  I'll post
anything I figure out.

Sean
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.