Writing a good spec.

C

Ch Ba

So I have a piece of code that I didn't write a spec for, and now rcov
is yelling at me about it. The problem is that I'm not really sure how I
should do it.

def build_structure(paths)
unless File::exists?('specdoc')
Dir.mkdir('specdoc')
end
paths.each do |path|
FileUtils.makedirs("specdoc/#{strip_file(path)}")
end
end

I want to make sure I have good coverage, but should I just come up with
some random paths, make it make them and then delete them? I just don't
know how to come at this one to get a good spec. Any ideas?
 
A

ara.t.howard

So I have a piece of code that I didn't write a spec for, and now rcov
is yelling at me about it. The problem is that I'm not really sure
how I
should do it.

def build_structure(paths)
unless File::exists?('specdoc')
Dir.mkdir('specdoc')
end
paths.each do |path|
FileUtils.makedirs("specdoc/#{strip_file(path)}")
end
end

I want to make sure I have good coverage, but should I just come up
with
some random paths, make it make them and then delete them? I just
don't
know how to come at this one to get a good spec. Any ideas?
--


first off, specdoc needs to be parameterizable - for instance

def build_structure *args

options = args.pop if args.last.is_a?(Hash)
paths = args.flatten.compact

root = Namespace.root

end

which sets you up to be able to do

Namespace.root = 'test/specdoc'

also, the method could return the directories created, which helps
testing a good deal.

some ideas...

a @ http://codeforpeople.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top