tags:

views:

950

answers:

2

I wonder if this has its place on StackOverflow, but since it IS programming-related, I will shoot it away.

Here's my problem. I am new to TDD and I love Ruby, so the obvious path I'm taking is testing stuff with rspec. Why obvious? I saw it in diverse screencasts and thought it was really neat. Then I saw "autospec" somewhere, and tried to use it.

So I install the gem, using sudo gem install ZenTest (according to the instructions here)

Next, I go into my folder, containing "digit.rb" and "digit_spec.rb", and fire up autospec without any parameter. Nothing happens. Worthy of note that I have two tests in my spec file and that I can test it fine just using the spec command, but I'd be delighted to use autotest...

Any help/pointers/documentation link available? Please? :P

A: 

Maybe you can give spork + autospec a try. The spork instructions on the rspec wiki is probably the most current way to go: http://wiki.github.com/dchelimsky/rspec/spork-autospec-pure-bdd-joy

hgimenez
I was just looking at the possibility of testing non-rails code, in fact. Just learning Ruby and TDD at the same time, both of which I love alot.
MrZombie
Why is this modded down?
Stephen Eilert
+5  A: 

You need to create .autotest file containing this code:

Autotest.add_hook :reset do |at|
  at.clear_mappings
  at.add_mapping(/^(.*?)(_spec)?\.rb$/) { |filename, m|
    if m[2]
      filename
    else
      "#{m[1]}_spec.rb"
    end
  }
end

it changes the default mapping of file to spec

tig
Just adding to the answer: The default behavior of autospec is to search for any file in ./lib, and look for the corresponding test file in ./spec. So, to "try it out", as I just did, you need to put your code file in a lib subdirectory, and your test file in a spec subdirectory.
MrZombie