# Re: how to test a ruby class

**URL:** <https://www.ruby-forum.com/t/re-how-to-test-a-ruby-class/65521>\
**Category:** Ruby\
**Created:** [February 10, 2006, 8:15pm UTC](https://www.ruby-forum.com/t/re-how-to-test-a-ruby-class/65521 "2006-02-10T20:15:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gennady\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c57346/32.png) [@Gennady\_B](https://www.ruby-forum.com/u/Gennady_B)\
**Post date:** [February 10, 2006, 8:15pm UTC](https://www.ruby-forum.com/t/re-how-to-test-a-ruby-class/65521/1 "2006-02-10T20:15:25Z")

</div>

You can do

=== some-class.rb  
class SomeClass  
…  
end

if $0 == **FILE**  
c = SomeClass.new  
c.whatever\_method\_you\_want\_to\_test  
end

This way the code in the ‘if’ block will be executed only when you do  
$ ruby some-class.rb

It will not be executed when you require some-class.rb from some other  
ruby file.

Gennady.
