Showing posts with label rspec. Show all posts
Showing posts with label rspec. Show all posts

Thursday, April 3, 2014

Dropping a database after running rspec tests with MongoMapper or Mongoid

The mongodb folder on my development computer was using 11 gb, and I needed to free up some space on /var, since that was on the / partition. (Yes, it is recommended to have it on separate partition, but that is another discussion).

In your rspec add this:

RSpec.configure do |config|
  config.after(:suite) do
    # for MongoMapper
    db = MongoMapper.database
    # for Mongoid
    # db = Mongoid.master
    # drop the database
    db.command({dropDatabase:1})
  end
end


For using mongo directly, you need to access the db object and trigger the command as above.

Thursday, February 28, 2013

Rake task for rspec:features

I'm using Capybara, rspec and poltergeist to test features/requests in Ruby on Rails

I wanted a simple raketask to check the features without typing:
$ rake spec SPEC=spec/features/**/*_spec.rb

I wanted to type:

$ rake spec:features

Creating the new raketask is quite simple:

desc "Run the code examples in spec/features"
task "spec:features" do
  Rails.env = ENV['RAILS_ENV'] = 'test'
  ENV['SPEC'] = "spec/features/**/*_spec.rb"
  Rake::Task['spec'].invoke
end
Note that the spec is set as an ENV variable and not passed as an argument to the invoke command.