thank_you
thank_you

Reputation: 11107

Tests won't work with MongoMapper in Sinatra

I hooked up MongoMapper with Sinatra and everything works fine except for the testing. I have Autotest with Rack Testing and Rspec installed. Whenever I run autotest, it tells me

/home/jason/ror/sbmongo/main.rb:11:in `<top (required)>': uninitialized constant 
MongoMapper (NameError)

Here is the line of code it refers to in my main.rb file.

MongoMapper.database = 'testdb'

What is the problem and how could I fix this?

Upvotes: 0

Views: 109

Answers (1)

ian
ian

Reputation: 12251

The order that things are called via require in Ruby does make a difference, as a constant declared in a library will only be visible after a the library has been required.

When running RSpec, it's best to put general set up code in one place - the spec_helper.rb file - and then in the individual specs, (for example, when specing main.rb) require 'spec_helper and then require main.rb. If each code file requires the libraries it needs in the right order, then your specs will run without a problem too. If not, it's a sign that the order of requires isn't quite right.

Upvotes: 1

Related Questions