I have a working setup which looks very similar to yours. I've highlighted
the main differences below:
Gemfile
ruby '2.0.0'
gem 'rails', '4.0.0.rc1'
gem "mongoid", github: 'mongoid'
group :development, :test do
gem 'rspec', '~> 2.14.0.rc1'
gem 'rspec-rails', github: 'rspec/rspec-rails'
gem 'mongoid-rspec'
end
config/application.rb
Bundler.require(:default, Rails.env)
spec/spec_helper.rb
RSpec.configure do |config|
config.before do
Mongoid.purge!
endend
On Mon, Jun 10, 2013 at 11:12 PM, dbkbali <[email protected]> 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/78443e65-0336-4bd5-aafa-2188885f28ef%40googlegroups.com?hl=en
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
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/CAKCESdh8R2Kzjo5bioXakjV3Vx_V2-cZO%2BY4%2Be4bYUQJA2SJJg%40mail.gmail.com?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.