Test class not finding main class

I'm very new to ruby and intellij so this may well be something trivial. Whenever I attempt to run unit tests I get the following error every time I try to use the class I'm trying to test:

NameError: uninitialized constant FooTest::Foo
    C:/projects/UnitTestingExample/foo_test.rb:6:in `test_somestuff'

My test file looks like this:

require 'minitest/unit'
require 'minitest/autorun'

class FooTest < MiniTest::Unit::TestCase

  def test_somestuff
    a = Foo.new 'bar'
  end
end


and my file structure looks like this:

<project root>
  foo.rb
  test_foo.rb

Any idea what could be the cause of the problem?  Literally all I've done is create a project, create a ruby class, and create a test class, then make it use minitest.

6 comments
Comment actions Permalink

Hi,

perhaps you need to require foo?

Regards, Oleg.

0
Comment actions Permalink

That gives this error:

C:/projects/UnitTestingExample/foo_test.rb:3:in `<top (required)>': undefined local variable or method `foo' for main:Object (NameError)
 from -e:1:in `load'
 from -e:1:in `<main>'

0
Comment actions Permalink

I meant "require 'foo'" not "require foo"

Regards, Oleg.

0
Comment actions Permalink

New error:

C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- foo (LoadError)
 from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
 from C:/projects/UnitTestingExample/foo_test.rb:3:in `<top (required)>'
 from -e:1:in `load'
 from -e:1:in `<main>'

0
Comment actions Permalink

Is the test works correctly when you run it in command line (ruby foo_test.rb)?
If not please provide the output, if yes could you please provide screenshot of settings of the run configuration RubyMine created for you.

Regards, Oleg.

0
Comment actions Permalink

I figured it out.  For normal ruby stuff (as opposed to rails) you need to set the path in your requires.  It would be a nice feature to be able to generate the test classes automagically via a right click menu or something so that they automatically handle the path stuff for you.

0

Please sign in to leave a comment.