Forum: Ruby Re: how to test a ruby class

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.
397f61cc4458e13157b4facf72325e5f?d=identicon&s=25 Gennady Bystritsky (Guest)
on 2006-02-10 20:15
(Received via mailing list)
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.
This topic is locked and can not be replied to.