Forum: Ruby Writing a good spec.

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.
F3be80254c63fb37ccb1bfc5a3794d1b?d=identicon&s=25 Ch Ba (navouri)
on 2008-12-18 04:47
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?
1bac2e65d64faf472cf2ebc94f0f5ee0?d=identicon&s=25 Ara Howard (ahoward)
on 2008-12-18 05:49
(Received via mailing list)
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/
F3be80254c63fb37ccb1bfc5a3794d1b?d=identicon&s=25 Ch Ba (navouri)
on 2008-12-18 06:08
> 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/

Thanks, I'll swing that in there!
This topic is locked and can not be replied to.