# Writing a good spec

**URL:** <https://www.ruby-forum.com/t/writing-a-good-spec/155909>\
**Category:** Ruby\
**Created:** [December 18, 2008, 4:47am UTC](https://www.ruby-forum.com/t/writing-a-good-spec/155909 "2008-12-18T04:47:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![navouri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@navouri](https://www.ruby-forum.com/u/navouri)\
**Post date:** [December 18, 2008, 4:47am UTC](https://www.ruby-forum.com/t/writing-a-good-spec/155909/1 "2008-12-18T04:47:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![navouri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@navouri](https://www.ruby-forum.com/u/navouri)\
**Post date:** [December 18, 2008, 5:49am UTC](https://www.ruby-forum.com/t/writing-a-good-spec/155909/2 "2008-12-18T05:49:09Z")

</div>

On Dec 17, 2008, at 8:40 PM, Ch Ba wrote:

> 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/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![navouri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@navouri](https://www.ruby-forum.com/u/navouri)\
**Post date:** [December 18, 2008, 6:08am UTC](https://www.ruby-forum.com/t/writing-a-good-spec/155909/3 "2008-12-18T06:08:04Z")

</div>

> first off, specdoc needs to be parameterizable - for instance

> also, the method could return the directories created, which helps  
> testing a good deal.
> 
> some ideas…
> 
> a @ [http://codeforpeople.com/](http://codeforpeople.com/)

Thanks, I’ll swing that in there!
