spec updates

This commit is contained in:
Jon Rowe 2010-05-16 21:45:46 +01:00
parent 6ce2df9373
commit 201343af63
6 changed files with 20 additions and 26 deletions

View File

@ -1,4 +1,5 @@
require 'spec_helper' require 'spec_helper'
require 'active_record'
require 'database_cleaner/active_record/base' require 'database_cleaner/active_record/base'
require 'database_cleaner/shared_strategy_spec' require 'database_cleaner/shared_strategy_spec'
@ -13,7 +14,7 @@ module DatabaseCleaner
end end
describe ExampleStrategy do describe ExampleStrategy do
it_should_behave_like "database cleaner strategy" it_should_behave_like "a generic strategy"
it { expect{ subject.connection_klass }.to_not raise_error } it { expect{ subject.connection_klass }.to_not raise_error }
end end
end end

View File

@ -1,23 +1,14 @@
require File.dirname(__FILE__) + '/../../spec_helper' require File.dirname(__FILE__) + '/../../spec_helper'
require 'database_cleaner/couch_potato/truncation' require 'database_cleaner/couch_potato/truncation'
require 'couch_potato'
module DatabaseCleaner module DatabaseCleaner
module CouchPotato module CouchPotato
describe Truncation do describe Truncation do
#doing the require in the file root breaks autospec, doing it before(:all) just fails the specs
before(:all) do
#pend the specs if CouchPotato is missing
if defined?(::CouchPotato)
require 'couch_potato'
end
end
let (:database) { mock('database') } let (:database) { mock('database') }
before(:each) do before(:each) do
#pend the specs if CouchPotato is missing
pending "Please install couchdb and couch_potato before running these specs" unless defined?(::CouchPotato)
::CouchPotato.stub!(:couchrest_database).and_return(database) ::CouchPotato.stub!(:couchrest_database).and_return(database)
end end

View File

@ -13,9 +13,7 @@ module ::DatabaseCleaner
its (:available_strategies) { should be_empty } its (:available_strategies) { should be_empty }
end end
it { should respond_to :db } it_should_behave_like "a generic strategy"
it { should respond_to :db= }
it { should respond_to :connection_klass }
its (:db) { should == :default } its (:db) { should == :default }

View File

@ -1,5 +1,7 @@
require File.dirname(__FILE__) + '/../../spec_helper' require File.dirname(__FILE__) + '/../../spec_helper'
require 'database_cleaner/mongo_mapper/truncation' require 'database_cleaner/mongo_mapper/truncation'
require 'mongo_mapper'
require File.dirname(__FILE__) + '/mongo_examples'
module DatabaseCleaner module DatabaseCleaner
module MongoMapper module MongoMapper
@ -8,20 +10,12 @@ module DatabaseCleaner
#doing this in the file root breaks autospec, doing it before(:all) just fails the specs #doing this in the file root breaks autospec, doing it before(:all) just fails the specs
before(:all) do before(:all) do
#pend the specs if MongoMapper is missing
if defined?(::MongoMapper) && defined?(::Mongo)
require 'mongo_mapper'
require File.dirname(__FILE__) + '/mongo_examples'
::MongoMapper.connection = ::Mongo::Connection.new('127.0.0.1') ::MongoMapper.connection = ::Mongo::Connection.new('127.0.0.1')
@test_db = 'database_cleaner_specs' @test_db = 'database_cleaner_specs'
::MongoMapper.database = @test_db ::MongoMapper.database = @test_db
end
end end
before(:each) do before(:each) do
#make these specs pend if orm not installed
pending "Please install MongoMapper + Mongo to run these specs" unless defined?(::MongoMapper) && defined?(::Mongo)
::MongoMapper.connection.drop_database(@test_db) ::MongoMapper.connection.drop_database(@test_db)
end end

View File

@ -1,5 +1,15 @@
shared_examples_for "database cleaner strategy" do shared_examples_for "a generic strategy" do
it { should respond_to :db } it { should respond_to :db }
it { should respond_to :db= } it { should respond_to :db= }
it { should respond_to :connection_klass } it { should respond_to :connection_klass }
end
shared_examples_for "a generic truncation strategy" do
it { should respond_to :start }
it { should respond_to :clean }
end
shared_examples_for "a generic transaction strategy" do
it { should respond_to :start }
it { should respond_to :clean }
end end

View File

@ -1,12 +1,12 @@
require 'rubygems' require 'rubygems'
require 'spec' require 'spec'
require 'active_record' #require 'active_record'
#require 'mongo_mapper' #require 'mongo_mapper'
$:.unshift(File.dirname(__FILE__) + '/../lib') $:.unshift(File.dirname(__FILE__) + '/../lib')
require 'database_cleaner' require 'database_cleaner'
Spec::Runner.configure do |config| Spec::Runner.configure do |config|
end end
alias running lambda alias running lambda