adbarads
adbarads

Reputation: 1303

Rspec test NameError: uninitialized constant trying to tie a class into a rspec test

So I"m not too familiar with ruby or rspec, and I have an rspect test, and here is a code snippet from it:

describe 'thingMagic' do 
    let(:tester) { testClass.testing }
    it { expect(tester).to be whatever doesn't matter at this point

So I wrote a class called testClass with a method called testing in it. Here's what it looks like:

class testClass
  def testing
    return pass_test
  end
end

I'm trying to figure out when I run rspec it is failing with this error in the console:

 Failure/Error: let(:tester) { testClass.testing }
     NameError:
       uninitialized constant testClass

I can't seem to figure out how to initialize this class. Is there a file I have to modify in rspec giving it a relative path to this file?

Upvotes: 1

Views: 3114

Answers (1)

adbarads
adbarads

Reputation: 1303

After lots of Googling and sheer luck. I learned: I needed:

require_relative '<path_to_file>'

after I added that into the spec.rb file. I re-ran the rspec test and it started working.

Here was good documentation and basically made me realized what I missed: http://ruby.about.com/od/faqs/qt/Nameerror-Uninitialized-Constant-Object-Something.htm

Upvotes: 1

Related Questions