Thanks Aaron,

I tried your config, but am still having problems, it seems for some reason 
that as soon as the Bundler.require is executed in application.rb and it 
hits a gem that needs a Mongoid Class, that it errors out for example I am 
using mongoid_slug and I get the following messages.

/Users/dbk/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/mongoid_slug-3.1.1/lib/mongoid/slug/criteria.rb:5:in
 
`<module:Slug>': uninitialized constant Mongoid::Criteria (NameError)
from 
/Users/dbk/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/mongoid_slug-3.1.1/lib/mongoid/slug/criteria.rb:4:in
 
`<module:Mongoid>'
from 
/Users/dbk/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/mongoid_slug-3.1.1/lib/mongoid/slug/criteria.rb:3:in
 
`<top (required)>'
from 
/Users/dbk/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/mongoid_slug-3.1.1/lib/mongoid_slug.rb:4:in
 
`require'
from 
/Users/dbk/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/mongoid_slug-3.1.1/lib/mongoid_slug.rb:4:in
 
`<top (required)>'
from 
/Users/dbk/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in
 
`require'
from 
/Users/dbk/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in
 
`block (2 levels) in require'
from 
/Users/dbk/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in
 
`each'
from 
/Users/dbk/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in
 
`block in require'
from 
/Users/dbk/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in
 
`each'
from 
/Users/dbk/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in
 
`require'
from 
/Users/dbk/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler.rb:132:in
 
`require'
from /Users/dbk/Development/w2d/config/application.rb:10:in `<top 
(required)>'
from /Users/dbk/Development/w2d/config/environment.rb:3:in `require'
from /Users/dbk/Development/w2d/config/environment.rb:3:in `<top 
(required)>'
from /Users/dbk/Development/w2d/spec/spec_helper.rb:4:in `require'
from /Users/dbk/Development/w2d/spec/spec_helper.rb:4:in `<top (required)>'
from /Users/dbk/Development/w2d/spec/request/home_spec.rb:1:in `require'

So for some reason my configuration is not loading Mongoid in the test 
environment. The strange thing is that I do not have this problem with 
minitest.

Again thanks for sharing.





On Tuesday, June 11, 2013 11:12:37 AM UTC+8, dbkbali wrote:
>
> I have a working app with Mongoid 4 (Master Branch) and Rails 4 and was 
> trying to switch my app over from using minitest to rspec. Using minitest I 
> am having no problems getting my tests running and passing with my Test 
> Helper file. However when setting up a spec_helper file for RSPEC it 
> appears that my that Mongoid is not getting loaded at the right time as my 
> ./bin/rspec craps out in application.rb file when the 
> "Bundler.require(*Rails.groups(assets: %w(development test)))" is executed, 
> and it encounters the first gem in my gem file that uses mongoid.
>
> require File.expand_path('../boot', __FILE__)
>
> # Pick the frameworks you want:
> # require "active_record/railtie"
> require "action_controller/railtie"
> require "action_mailer/railtie"
> #require "active_resource/railtie"
> require "sprockets/railtie"
> require "rails/test_unit/railtie"
> Bundler.require(*Rails.groups(assets: %w(development test)))
> #if defined?(Bundler)
>   # If you precompile assets before deploying to production, use this line
>   #Bundler.require(*Rails.groups(assets: %w(development test)))
>   # If you want your assets lazily compiled in production, use this line
>   #Bundler.require(:default, :assets, Rails.env)
> #end
>
>
> module MyApp
> ......
>
>
> #app/spec/spec_helper.rb
>
> # This file is copied to spec/ when you run 'rails generate rspec:install'
> ENV["RAILS_ENV"] ||= 'test'
> require File.expand_path("../../config/environment", __FILE__)
> require 'rspec/rails'
> require 'rspec/autorun'
> require 'capybara/rspec'
> require 'database_cleaner'
>
> # Requires supporting ruby files with custom matchers and macros, etc,
> # in spec/support/ and its subdirectories.
> Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
>
> # Checks for pending migrations before tests are run.
> # If you are not using ActiveRecord, you can remove this line.
> #ActiveRecord::Migration.check_pending! if 
> defined?(ActiveRecord::Migration)
>
> RSpec.configure do |config|
>   # ## Mock Framework
>   #
>   # If you prefer to use mocha, flexmock or RR, uncomment the appropriate 
> line:
>   #
>   # config.mock_with :mocha
>   # config.mock_with :flexmock
>   # config.mock_with :rr
>
>   # Remove this line if you're not using ActiveRecord or ActiveRecord 
> fixtures
>   #config.fixture_path = "#{::Rails.root}/spec/fixtures"
>
>   # If you're not using ActiveRecord, or you'd prefer not to run each of 
> your
>   # examples within a transaction, remove the following line or assign 
> false
>   # instead of true.
>   #config.use_transactional_fixtures = true
>
>   # If true, the base class of anonymous controllers will be inferred
>   # automatically. This will be the default behavior in future versions of
>   # rspec-rails.
>   config.infer_base_class_for_anonymous_controllers = false
>
>   # Run specs in random order to surface order dependencies. If you find an
>   # order dependency and want to debug it, you can fix the order by 
> providing
>   # the seed, which is printed after each run.
>   #     --seed 1234
>   config.order = "random"
>
>
>   config.before(:each) do
>     db = Mongoid::Config::master
>     # ignore stuff like system.indexes
>     db.collection_names.reject {|c| c =~ /^system/}.each {|c| 
> db.drop_collection c}
>   end
>
>
>   config.include Capybara::DSL
> end
>
>
> Have searched the docs and tried various permutations of requiring 
>  "mongoid" and Mongoid.load! but am not having any luck getting this 
> working so that rspec has access to the Mongoid database in the test 
> environment.
>
> If anyone has a working config for  Rspec 2/Rails 4/Mongoid 4 it would be 
> much appreciated if you can help me out or point me in the right direction 
> to get this working.
>
> Many Thanks,
>
> David Krett
>

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/e3dfdb72-4ced-4379-a389-411a9a3bd455%40googlegroups.com?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to