Forum: RSpec RSpec 2 / Rails 3 autoload

Posted by Ashley Moran (Guest)
on 2010-03-06 17:45
(Received via mailing list)
Hi

For the last 18 months I've been used to writing specs like this, which 
was written with Merb 1.1.0.pre and RSpec 1.3:

  module LanguageRepository
    describe DataMapperAdapter do
      it_should_behave_like "Contract: LanguageRepository"

      def language_repository
        DataMapperAdapter.new
      end
    end
  end

This will happily find and instantiate 
::LanguageRepository::DataMapperAdapter from the 
models/language_repository folder.

However, using Rails 3.0.0.beta from master and Rspec 2.0.0.beta.2, I 
get the following error:

  1) LanguageRepository::DataMapperAdapter storage and retrieval can 
store
     a Language and retrieve it by code
      Failure/Error: DataMapperAdapter.new
      uninitialized constant 
Rspec::Core::ExampleGroup::NestedLevel_8::DataMapperAdapter

I have to change it to this to make it work:

      def language_repository
        LanguageRepository::DataMapperAdapter.new
      end

Now, having just changed two moving parts (RSpec and web framework) I'm 
not sure what correct behaviour is on anything.  I don't know how Rails 
code auto-loading works, or how RSpec interacts with it.

Is the above behaviour a bug or a misunderstanding on my part?

Cheers
Ashley

--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.