mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
update to rspec 3 syntax.
This commit is contained in:
parent
ae234c4e1a
commit
2fff7ab3f4
28 changed files with 408 additions and 416 deletions
|
@ -12,15 +12,15 @@ end
|
|||
|
||||
module DatabaseCleaner
|
||||
describe ActiveRecord do
|
||||
it { should respond_to(:available_strategies) }
|
||||
it { is_expected.to respond_to(:available_strategies) }
|
||||
|
||||
describe "config_file_location" do
|
||||
subject { ActiveRecord.config_file_location }
|
||||
|
||||
it "should default to DatabaseCleaner.root / config / database.yml" do
|
||||
ActiveRecord.config_file_location=nil
|
||||
DatabaseCleaner.should_receive(:app_root).and_return("/path/to")
|
||||
subject.should eq '/path/to/config/database.yml'
|
||||
expect(DatabaseCleaner).to receive(:app_root).and_return("/path/to")
|
||||
expect(subject).to eq '/path/to/config/database.yml'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -36,25 +36,25 @@ module DatabaseCleaner
|
|||
'/path/to/config/database.yml'
|
||||
end
|
||||
|
||||
before { ::DatabaseCleaner::ActiveRecord.stub(:config_file_location).and_return(config_location) }
|
||||
before { allow(::DatabaseCleaner::ActiveRecord).to receive(:config_file_location).and_return(config_location) }
|
||||
|
||||
it_should_behave_like "a generic strategy"
|
||||
|
||||
describe "db" do
|
||||
|
||||
it "should store my desired db" do
|
||||
subject.stub(:load_config)
|
||||
allow(subject).to receive(:load_config)
|
||||
|
||||
subject.db = :my_db
|
||||
subject.db.should eq :my_db
|
||||
expect(subject.db).to eq :my_db
|
||||
end
|
||||
|
||||
it "should default to :default" do
|
||||
subject.db.should eq :default
|
||||
expect(subject.db).to eq :default
|
||||
end
|
||||
|
||||
it "should load_config when I set db" do
|
||||
subject.should_receive(:load_config)
|
||||
expect(subject).to receive(:load_config)
|
||||
subject.db = :my_db
|
||||
end
|
||||
end
|
||||
|
@ -67,12 +67,12 @@ module DatabaseCleaner
|
|||
my_db:
|
||||
database: <%= "ONE".downcase %>
|
||||
Y
|
||||
File.stub(:file?).with(config_location).and_return(true)
|
||||
IO.stub(:read).with(config_location).and_return(yaml)
|
||||
allow(File).to receive(:file?).with(config_location).and_return(true)
|
||||
allow(IO).to receive(:read).with(config_location).and_return(yaml)
|
||||
end
|
||||
|
||||
it "should parse the config" do
|
||||
YAML.should_receive(:load).and_return({ :nil => nil })
|
||||
expect(YAML).to receive(:load).and_return({ :nil => nil })
|
||||
subject.load_config
|
||||
end
|
||||
|
||||
|
@ -81,62 +81,62 @@ my_db:
|
|||
my_db:
|
||||
database: one
|
||||
Y
|
||||
YAML.should_receive(:load).with(transformed).and_return({ "my_db" => { "database" => "one" } })
|
||||
expect(YAML).to receive(:load).with(transformed).and_return({ "my_db" => { "database" => "one" } })
|
||||
subject.load_config
|
||||
end
|
||||
|
||||
context 'use ActiveRecord::Base.configuration' do
|
||||
it 'when config file different with it' do
|
||||
::ActiveRecord::Base.stub(:configurations).and_return({ "my_db" =>{ "database" => "two"} })
|
||||
allow(::ActiveRecord::Base).to receive(:configurations).and_return({ "my_db" =>{ "database" => "two"} })
|
||||
subject.load_config
|
||||
subject.connection_hash.should eq({ "database" => "two"})
|
||||
expect(subject.connection_hash).to eq({ "database" => "two"})
|
||||
end
|
||||
end
|
||||
|
||||
context 'use config file' do
|
||||
it 'when config file same with it' do
|
||||
::ActiveRecord::Base.stub(:configurations).and_return({ "my_db" =>{ "database" => "one"} })
|
||||
allow(::ActiveRecord::Base).to receive(:configurations).and_return({ "my_db" =>{ "database" => "one"} })
|
||||
subject.load_config
|
||||
subject.connection_hash.should eq({ "database" => "one"})
|
||||
expect(subject.connection_hash).to eq({ "database" => "one"})
|
||||
end
|
||||
|
||||
it 'when ::ActiveRecord::Base.configurations nil' do
|
||||
::ActiveRecord::Base.stub(:configurations).and_return(nil)
|
||||
allow(::ActiveRecord::Base).to receive(:configurations).and_return(nil)
|
||||
subject.load_config
|
||||
subject.connection_hash.should eq({ "database" => "one"})
|
||||
expect(subject.connection_hash).to eq({ "database" => "one"})
|
||||
end
|
||||
|
||||
it 'when ::ActiveRecord::Base.configurations empty' do
|
||||
::ActiveRecord::Base.stub(:configurations).and_return({})
|
||||
allow(::ActiveRecord::Base).to receive(:configurations).and_return({})
|
||||
subject.load_config
|
||||
subject.connection_hash.should eq({ "database" => "one"})
|
||||
expect(subject.connection_hash).to eq({ "database" => "one"})
|
||||
end
|
||||
end
|
||||
|
||||
it "should store the relevant config in connection_hash" do
|
||||
subject.load_config
|
||||
subject.connection_hash.should eq( "database" => "one" )
|
||||
expect(subject.connection_hash).to eq( "database" => "one" )
|
||||
end
|
||||
|
||||
it "should skip config if config file is not available" do
|
||||
File.should_receive(:file?).with(config_location).and_return(false)
|
||||
expect(File).to receive(:file?).with(config_location).and_return(false)
|
||||
subject.load_config
|
||||
subject.connection_hash.should_not be
|
||||
expect(subject.connection_hash).not_to be
|
||||
end
|
||||
|
||||
it "skips the file when the model is set" do
|
||||
subject.db = FakeModel
|
||||
YAML.should_not_receive(:load)
|
||||
expect(YAML).not_to receive(:load)
|
||||
subject.load_config
|
||||
subject.connection_hash.should_not be
|
||||
expect(subject.connection_hash).not_to be
|
||||
end
|
||||
|
||||
it "skips the file when the db is set to :default" do
|
||||
# to avoid https://github.com/bmabey/database_cleaner/issues/72
|
||||
subject.db = :default
|
||||
YAML.should_not_receive(:load)
|
||||
expect(YAML).not_to receive(:load)
|
||||
subject.load_config
|
||||
subject.connection_hash.should_not be
|
||||
expect(subject.connection_hash).not_to be
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -144,14 +144,14 @@ my_db:
|
|||
describe "connection_hash" do
|
||||
it "should store connection_hash" do
|
||||
subject.connection_hash = { :key => "value" }
|
||||
subject.connection_hash.should eq( :key => "value" )
|
||||
expect(subject.connection_hash).to eq( :key => "value" )
|
||||
end
|
||||
end
|
||||
|
||||
describe "connection_class" do
|
||||
it { expect { subject.connection_class }.to_not raise_error }
|
||||
it "should default to ActiveRecord::Base" do
|
||||
subject.connection_class.should eq ::ActiveRecord::Base
|
||||
expect(subject.connection_class).to eq ::ActiveRecord::Base
|
||||
end
|
||||
|
||||
context "with database models" do
|
||||
|
@ -160,24 +160,24 @@ my_db:
|
|||
subject.db = FakeModel
|
||||
subject.connection_hash = { }
|
||||
subject.load_config
|
||||
subject.connection_class.should eq FakeModel
|
||||
expect(subject.connection_class).to eq FakeModel
|
||||
end
|
||||
end
|
||||
|
||||
context "connection_hash is not set" do
|
||||
it "allows for database models to be passed in" do
|
||||
subject.db = FakeModel
|
||||
subject.connection_class.should eq FakeModel
|
||||
expect(subject.connection_class).to eq FakeModel
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when connection_hash is set" do
|
||||
let(:hash) { {} }
|
||||
before { subject.stub(:connection_hash).and_return(hash) }
|
||||
before { allow(subject).to receive(:connection_hash).and_return(hash) }
|
||||
|
||||
it "establish a connection using ActiveRecord::Base" do
|
||||
::ActiveRecord::Base.should_receive(:establish_connection).with(hash)
|
||||
expect(::ActiveRecord::Base).to receive(:establish_connection).with(hash)
|
||||
|
||||
expect(subject.connection_class).to eq ::ActiveRecord::Base
|
||||
end
|
||||
|
|
|
@ -10,33 +10,33 @@ module DatabaseCleaner
|
|||
let (:connection_2) { double("connection") }
|
||||
let (:connection_pool) { double("connection_pool")}
|
||||
before(:each) do
|
||||
::ActiveRecord::Base.stub(:connection_pool).and_return(connection_pool)
|
||||
connection_pool.stub(:connections).and_return([connection])
|
||||
::ActiveRecord::Base.stub(:connection).and_return(connection)
|
||||
allow(::ActiveRecord::Base).to receive(:connection_pool).and_return(connection_pool)
|
||||
allow(connection_pool).to receive(:connections).and_return([connection])
|
||||
allow(::ActiveRecord::Base).to receive(:connection).and_return(connection)
|
||||
end
|
||||
|
||||
describe "#start" do
|
||||
[:begin_transaction, :begin_db_transaction].each do |begin_transaction_method|
|
||||
context "using #{begin_transaction_method}" do
|
||||
before do
|
||||
connection.stub(:transaction)
|
||||
connection.stub(begin_transaction_method)
|
||||
allow(connection).to receive(:transaction)
|
||||
allow(connection).to receive(begin_transaction_method)
|
||||
end
|
||||
|
||||
it "should increment open transactions if possible" do
|
||||
connection.should_receive(:increment_open_transactions)
|
||||
expect(connection).to receive(:increment_open_transactions)
|
||||
Transaction.new.start
|
||||
end
|
||||
|
||||
it "should tell ActiveRecord to increment connection if its not possible to increment current connection" do
|
||||
::ActiveRecord::Base.should_receive(:increment_open_transactions)
|
||||
expect(::ActiveRecord::Base).to receive(:increment_open_transactions)
|
||||
Transaction.new.start
|
||||
end
|
||||
|
||||
it "should start a transaction" do
|
||||
connection.stub(:increment_open_transactions)
|
||||
connection.should_receive(begin_transaction_method)
|
||||
connection.should_receive(:transaction)
|
||||
allow(connection).to receive(:increment_open_transactions)
|
||||
expect(connection).to receive(begin_transaction_method)
|
||||
expect(connection).to receive(:transaction)
|
||||
Transaction.new.start
|
||||
end
|
||||
end
|
||||
|
@ -46,59 +46,59 @@ module DatabaseCleaner
|
|||
describe "#clean" do
|
||||
context "manual accounting of transaction count" do
|
||||
it "should start a transaction" do
|
||||
connection.should_receive(:open_transactions).and_return(1)
|
||||
expect(connection).to receive(:open_transactions).and_return(1)
|
||||
|
||||
connection.stub(:decrement_open_transactions)
|
||||
allow(connection).to receive(:decrement_open_transactions)
|
||||
|
||||
connection.should_receive(:rollback_db_transaction)
|
||||
expect(connection).to receive(:rollback_db_transaction)
|
||||
Transaction.new.clean
|
||||
end
|
||||
|
||||
it "should decrement open transactions if possible" do
|
||||
connection.should_receive(:open_transactions).and_return(1)
|
||||
expect(connection).to receive(:open_transactions).and_return(1)
|
||||
|
||||
connection.stub(:rollback_db_transaction)
|
||||
allow(connection).to receive(:rollback_db_transaction)
|
||||
|
||||
connection.should_receive(:decrement_open_transactions)
|
||||
expect(connection).to receive(:decrement_open_transactions)
|
||||
Transaction.new.clean
|
||||
end
|
||||
|
||||
it "should not try to decrement or rollback if open_transactions is 0 for whatever reason" do
|
||||
connection.should_receive(:open_transactions).and_return(0)
|
||||
expect(connection).to receive(:open_transactions).and_return(0)
|
||||
|
||||
Transaction.new.clean
|
||||
end
|
||||
|
||||
it "should decrement connection via ActiveRecord::Base if connection won't" do
|
||||
connection.should_receive(:open_transactions).and_return(1)
|
||||
connection.stub(:rollback_db_transaction)
|
||||
expect(connection).to receive(:open_transactions).and_return(1)
|
||||
allow(connection).to receive(:rollback_db_transaction)
|
||||
|
||||
::ActiveRecord::Base.should_receive(:decrement_open_transactions)
|
||||
expect(::ActiveRecord::Base).to receive(:decrement_open_transactions)
|
||||
Transaction.new.clean
|
||||
end
|
||||
|
||||
it "should rollback open transactions in all connections" do
|
||||
connection_pool.stub(:connections).and_return([connection, connection_2])
|
||||
allow(connection_pool).to receive(:connections).and_return([connection, connection_2])
|
||||
|
||||
connection.should_receive(:open_transactions).and_return(1)
|
||||
connection.stub(:rollback_db_transaction)
|
||||
expect(connection).to receive(:open_transactions).and_return(1)
|
||||
allow(connection).to receive(:rollback_db_transaction)
|
||||
|
||||
connection_2.should_receive(:open_transactions).and_return(1)
|
||||
connection_2.stub(:rollback_db_transaction)
|
||||
expect(connection_2).to receive(:open_transactions).and_return(1)
|
||||
allow(connection_2).to receive(:rollback_db_transaction)
|
||||
|
||||
::ActiveRecord::Base.should_receive(:decrement_open_transactions).twice
|
||||
expect(::ActiveRecord::Base).to receive(:decrement_open_transactions).twice
|
||||
Transaction.new.clean
|
||||
end
|
||||
|
||||
it "should rollback open transactions in all connections with an open transaction" do
|
||||
connection_pool.stub(:connections).and_return([connection, connection_2])
|
||||
allow(connection_pool).to receive(:connections).and_return([connection, connection_2])
|
||||
|
||||
connection.should_receive(:open_transactions).and_return(1)
|
||||
connection.stub(:rollback_db_transaction)
|
||||
expect(connection).to receive(:open_transactions).and_return(1)
|
||||
allow(connection).to receive(:rollback_db_transaction)
|
||||
|
||||
connection_2.should_receive(:open_transactions).and_return(0)
|
||||
expect(connection_2).to receive(:open_transactions).and_return(0)
|
||||
|
||||
::ActiveRecord::Base.should_receive(:decrement_open_transactions).exactly(1).times
|
||||
expect(::ActiveRecord::Base).to receive(:decrement_open_transactions).exactly(1).times
|
||||
Transaction.new.clean
|
||||
end
|
||||
end
|
||||
|
@ -107,33 +107,33 @@ module DatabaseCleaner
|
|||
before {stub_const("ActiveRecord::VERSION::MAJOR", 4) }
|
||||
|
||||
it "should start a transaction" do
|
||||
connection.stub(:rollback_db_transaction)
|
||||
connection.should_receive(:open_transactions).and_return(1)
|
||||
allow(connection).to receive(:rollback_db_transaction)
|
||||
expect(connection).to receive(:open_transactions).and_return(1)
|
||||
|
||||
connection.should_not_receive(:decrement_open_transactions)
|
||||
connection.should_receive(:rollback_transaction)
|
||||
expect(connection).not_to receive(:decrement_open_transactions)
|
||||
expect(connection).to receive(:rollback_transaction)
|
||||
Transaction.new.clean
|
||||
end
|
||||
|
||||
it "should decrement open transactions if possible" do
|
||||
connection.stub(:rollback_transaction)
|
||||
connection.should_receive(:open_transactions).and_return(1)
|
||||
allow(connection).to receive(:rollback_transaction)
|
||||
expect(connection).to receive(:open_transactions).and_return(1)
|
||||
|
||||
connection.should_not_receive(:decrement_open_transactions)
|
||||
expect(connection).not_to receive(:decrement_open_transactions)
|
||||
Transaction.new.clean
|
||||
end
|
||||
|
||||
it "should not try to decrement or rollback if open_transactions is 0 for whatever reason" do
|
||||
connection.should_receive(:open_transactions).and_return(0)
|
||||
expect(connection).to receive(:open_transactions).and_return(0)
|
||||
|
||||
Transaction.new.clean
|
||||
end
|
||||
|
||||
it "should decrement connection via ActiveRecord::Base if connection won't" do
|
||||
connection.should_receive(:open_transactions).and_return(1)
|
||||
connection.stub(:rollback_transaction)
|
||||
expect(connection).to receive(:open_transactions).and_return(1)
|
||||
allow(connection).to receive(:rollback_transaction)
|
||||
|
||||
::ActiveRecord::Base.should_not_receive(:decrement_open_transactions)
|
||||
expect(::ActiveRecord::Base).not_to receive(:decrement_open_transactions)
|
||||
Transaction.new.clean
|
||||
end
|
||||
end
|
||||
|
@ -142,11 +142,11 @@ module DatabaseCleaner
|
|||
describe "#connection_maintains_transaction_count?" do
|
||||
it "should return true if the major active record version is < 4" do
|
||||
stub_const("ActiveRecord::VERSION::MAJOR", 3)
|
||||
Transaction.new.connection_maintains_transaction_count?.should be_truthy
|
||||
expect(Transaction.new.connection_maintains_transaction_count?).to be_truthy
|
||||
end
|
||||
it "should return false if the major active record version is > 3" do
|
||||
stub_const("ActiveRecord::VERSION::MAJOR", 4)
|
||||
Transaction.new.connection_maintains_transaction_count?.should be_falsey
|
||||
expect(Transaction.new.connection_maintains_transaction_count?).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ module ActiveRecord
|
|||
2.times { User.create }
|
||||
|
||||
connection.truncate_table('users')
|
||||
User.count.should eq 0
|
||||
expect(User.count).to eq 0
|
||||
end
|
||||
|
||||
it "should reset AUTO_INCREMENT index of table" do
|
||||
|
@ -25,7 +25,7 @@ module ActiveRecord
|
|||
|
||||
connection.truncate_table('users')
|
||||
|
||||
User.create.id.should eq 1
|
||||
expect(User.create.id).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ module ActiveRecord
|
|||
2.times { User.create }
|
||||
|
||||
connection.truncate_table('users')
|
||||
User.count.should eq 0
|
||||
expect(User.count).to eq 0
|
||||
end
|
||||
|
||||
it "should reset AUTO_INCREMENT index of table" do
|
||||
|
@ -25,7 +25,7 @@ module ActiveRecord
|
|||
|
||||
connection.truncate_table('users')
|
||||
|
||||
User.create.id.should eq 1
|
||||
expect(User.create.id).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ module ActiveRecord
|
|||
PostgreSQLHelper.active_record_pg_migrate
|
||||
DatabaseCleaner::ActiveRecord::Truncation.new.clean
|
||||
result = PostgreSQLHelper.active_record_pg_connection.execute("select count(*) from schema_migrations;")
|
||||
result.values.first.should eq ["2"]
|
||||
expect(result.values.first).to eq ["2"]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -31,14 +31,14 @@ module ActiveRecord
|
|||
2.times { User.create }
|
||||
|
||||
connection.truncate_table('users')
|
||||
User.count.should eq 0
|
||||
expect(User.count).to eq 0
|
||||
end
|
||||
|
||||
it "truncates the table without id sequence" do
|
||||
2.times { Agent.create }
|
||||
|
||||
connection.truncate_table('agents')
|
||||
Agent.count.should eq 0
|
||||
expect(Agent.count).to eq 0
|
||||
end
|
||||
|
||||
it "resets AUTO_INCREMENT index of table" do
|
||||
|
@ -47,7 +47,7 @@ module ActiveRecord
|
|||
|
||||
connection.truncate_table('users')
|
||||
|
||||
User.create.id.should eq 1
|
||||
expect(User.create.id).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -62,7 +62,7 @@ module ActiveRecord
|
|||
|
||||
describe '#database_cleaner_table_cache' do
|
||||
it 'should default to the list of tables with their schema' do
|
||||
connection.database_cleaner_table_cache.first.should match(/^public\./)
|
||||
expect(connection.database_cleaner_table_cache.first).to match(/^public\./)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ shared_examples_for "an adapter with pre-count truncation" do
|
|||
2.times { User.create }
|
||||
|
||||
connection.pre_count_truncate_tables(%w[users], :reset_ids => true)
|
||||
User.count.should be_zero
|
||||
expect(User.count).to be_zero
|
||||
end
|
||||
|
||||
it "resets AUTO_INCREMENT index of table" do
|
||||
|
@ -14,7 +14,7 @@ shared_examples_for "an adapter with pre-count truncation" do
|
|||
User.delete_all
|
||||
|
||||
connection.pre_count_truncate_tables(%w[users]) # true is also the default
|
||||
User.create.id.should eq 1
|
||||
expect(User.create.id).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -24,7 +24,7 @@ shared_examples_for "an adapter with pre-count truncation" do
|
|||
2.times { User.create }
|
||||
|
||||
connection.pre_count_truncate_tables(%w[users], :reset_ids => false)
|
||||
User.count.should be_zero
|
||||
expect(User.count).to be_zero
|
||||
end
|
||||
|
||||
it "does not reset AUTO_INCREMENT index of table" do
|
||||
|
@ -33,7 +33,7 @@ shared_examples_for "an adapter with pre-count truncation" do
|
|||
|
||||
connection.pre_count_truncate_tables(%w[users], :reset_ids => false)
|
||||
|
||||
User.create.id.should eq 3
|
||||
expect(User.create.id).to eq 3
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,7 +21,7 @@ module ActiveRecord
|
|||
2.times { User.create }
|
||||
|
||||
connection.truncate_table('users')
|
||||
User.count.should eq 0
|
||||
expect(User.count).to eq 0
|
||||
end
|
||||
|
||||
it "resets AUTO_INCREMENT index of table" do
|
||||
|
@ -30,7 +30,7 @@ module ActiveRecord
|
|||
|
||||
connection.truncate_table('users')
|
||||
|
||||
User.create.id.should eq 1
|
||||
expect(User.create.id).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ module ActiveRecord
|
|||
[ MysqlAdapter, Mysql2Adapter, SQLite3Adapter, PostgreSQLAdapter ].each do |adapter|
|
||||
describe adapter, "#truncate_table" do
|
||||
it "responds" do
|
||||
adapter.instance_methods.should include(:truncate_table)
|
||||
expect(adapter.instance_methods).to include(:truncate_table)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -27,60 +27,60 @@ module DatabaseCleaner
|
|||
let(:connection) { double('connection') }
|
||||
|
||||
before(:each) do
|
||||
connection.stub(:disable_referential_integrity).and_yield
|
||||
connection.stub(:database_cleaner_view_cache).and_return([])
|
||||
::ActiveRecord::Base.stub(:connection).and_return(connection)
|
||||
allow(connection).to receive(:disable_referential_integrity).and_yield
|
||||
allow(connection).to receive(:database_cleaner_view_cache).and_return([])
|
||||
allow(::ActiveRecord::Base).to receive(:connection).and_return(connection)
|
||||
end
|
||||
|
||||
describe '#clean' do
|
||||
it "should truncate all tables except for schema_migrations" do
|
||||
connection.stub(:database_cleaner_table_cache).and_return(%w[schema_migrations widgets dogs])
|
||||
allow(connection).to receive(:database_cleaner_table_cache).and_return(%w[schema_migrations widgets dogs])
|
||||
|
||||
connection.should_receive(:truncate_tables).with(['widgets', 'dogs'])
|
||||
expect(connection).to receive(:truncate_tables).with(['widgets', 'dogs'])
|
||||
Truncation.new.clean
|
||||
end
|
||||
|
||||
it "should use ActiveRecord's SchemaMigration.table_name" do
|
||||
connection.stub(:database_cleaner_table_cache).and_return(%w[pre_schema_migrations_suf widgets dogs])
|
||||
::ActiveRecord::Base.stub(:table_name_prefix).and_return('pre_')
|
||||
::ActiveRecord::Base.stub(:table_name_suffix).and_return('_suf')
|
||||
allow(connection).to receive(:database_cleaner_table_cache).and_return(%w[pre_schema_migrations_suf widgets dogs])
|
||||
allow(::ActiveRecord::Base).to receive(:table_name_prefix).and_return('pre_')
|
||||
allow(::ActiveRecord::Base).to receive(:table_name_suffix).and_return('_suf')
|
||||
|
||||
connection.should_receive(:truncate_tables).with(['widgets', 'dogs'])
|
||||
expect(connection).to receive(:truncate_tables).with(['widgets', 'dogs'])
|
||||
|
||||
Truncation.new.clean
|
||||
end
|
||||
|
||||
it "should only truncate the tables specified in the :only option when provided" do
|
||||
connection.stub(:database_cleaner_table_cache).and_return(%w[schema_migrations widgets dogs])
|
||||
allow(connection).to receive(:database_cleaner_table_cache).and_return(%w[schema_migrations widgets dogs])
|
||||
|
||||
connection.should_receive(:truncate_tables).with(['widgets'])
|
||||
expect(connection).to receive(:truncate_tables).with(['widgets'])
|
||||
|
||||
Truncation.new(:only => ['widgets']).clean
|
||||
end
|
||||
|
||||
it "should not truncate the tables specified in the :except option" do
|
||||
connection.stub(:database_cleaner_table_cache).and_return(%w[schema_migrations widgets dogs])
|
||||
allow(connection).to receive(:database_cleaner_table_cache).and_return(%w[schema_migrations widgets dogs])
|
||||
|
||||
connection.should_receive(:truncate_tables).with(['dogs'])
|
||||
expect(connection).to receive(:truncate_tables).with(['dogs'])
|
||||
|
||||
Truncation.new(:except => ['widgets']).clean
|
||||
end
|
||||
|
||||
it "should raise an error when :only and :except options are used" do
|
||||
running {
|
||||
expect(running {
|
||||
Truncation.new(:except => ['widgets'], :only => ['widgets'])
|
||||
}.should raise_error(ArgumentError)
|
||||
}).to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "should raise an error when invalid options are provided" do
|
||||
running { Truncation.new(:foo => 'bar') }.should raise_error(ArgumentError)
|
||||
expect(running { Truncation.new(:foo => 'bar') }).to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "should not truncate views" do
|
||||
connection.stub(:database_cleaner_table_cache).and_return(%w[widgets dogs])
|
||||
connection.stub(:database_cleaner_view_cache).and_return(["widgets"])
|
||||
allow(connection).to receive(:database_cleaner_table_cache).and_return(%w[widgets dogs])
|
||||
allow(connection).to receive(:database_cleaner_view_cache).and_return(["widgets"])
|
||||
|
||||
connection.should_receive(:truncate_tables).with(['dogs'])
|
||||
expect(connection).to receive(:truncate_tables).with(['dogs'])
|
||||
|
||||
Truncation.new.clean
|
||||
end
|
||||
|
@ -89,25 +89,25 @@ module DatabaseCleaner
|
|||
subject { Truncation.new }
|
||||
|
||||
it "should rely on #pre_count_truncate_tables if #pre_count? returns true" do
|
||||
connection.stub(:database_cleaner_table_cache).and_return(%w[widgets dogs])
|
||||
connection.stub(:database_cleaner_view_cache).and_return(["widgets"])
|
||||
allow(connection).to receive(:database_cleaner_table_cache).and_return(%w[widgets dogs])
|
||||
allow(connection).to receive(:database_cleaner_view_cache).and_return(["widgets"])
|
||||
|
||||
subject.instance_variable_set(:"@pre_count", true)
|
||||
|
||||
connection.should_not_receive(:truncate_tables).with(['dogs'])
|
||||
connection.should_receive(:pre_count_truncate_tables).with(['dogs'], :reset_ids => true)
|
||||
expect(connection).not_to receive(:truncate_tables).with(['dogs'])
|
||||
expect(connection).to receive(:pre_count_truncate_tables).with(['dogs'], :reset_ids => true)
|
||||
|
||||
subject.clean
|
||||
end
|
||||
|
||||
it "should not rely on #pre_count_truncate_tables if #pre_count? return false" do
|
||||
connection.stub(:database_cleaner_table_cache).and_return(%w[widgets dogs])
|
||||
connection.stub(:database_cleaner_view_cache).and_return(["widgets"])
|
||||
allow(connection).to receive(:database_cleaner_table_cache).and_return(%w[widgets dogs])
|
||||
allow(connection).to receive(:database_cleaner_view_cache).and_return(["widgets"])
|
||||
|
||||
subject.instance_variable_set(:"@pre_count", false)
|
||||
|
||||
connection.should_not_receive(:pre_count_truncate_tables).with(['dogs'], :reset_ids => true)
|
||||
connection.should_receive(:truncate_tables).with(['dogs'])
|
||||
expect(connection).not_to receive(:pre_count_truncate_tables).with(['dogs'], :reset_ids => true)
|
||||
expect(connection).to receive(:truncate_tables).with(['dogs'])
|
||||
|
||||
subject.clean
|
||||
end
|
||||
|
@ -115,20 +115,20 @@ module DatabaseCleaner
|
|||
|
||||
context 'when :cache_tables is set to true' do
|
||||
it 'caches the list of tables to be truncated' do
|
||||
connection.should_receive(:database_cleaner_table_cache).and_return([])
|
||||
connection.should_not_receive(:tables)
|
||||
expect(connection).to receive(:database_cleaner_table_cache).and_return([])
|
||||
expect(connection).not_to receive(:tables)
|
||||
|
||||
connection.stub(:truncate_tables)
|
||||
allow(connection).to receive(:truncate_tables)
|
||||
Truncation.new({ :cache_tables => true }).clean
|
||||
end
|
||||
end
|
||||
|
||||
context 'when :cache_tables is set to false' do
|
||||
it 'does not cache the list of tables to be truncated' do
|
||||
connection.should_not_receive(:database_cleaner_table_cache)
|
||||
connection.should_receive(:tables).and_return([])
|
||||
expect(connection).not_to receive(:database_cleaner_table_cache)
|
||||
expect(connection).to receive(:tables).and_return([])
|
||||
|
||||
connection.stub(:truncate_tables)
|
||||
allow(connection).to receive(:truncate_tables)
|
||||
Truncation.new({ :cache_tables => false }).clean
|
||||
end
|
||||
end
|
||||
|
@ -136,49 +136,49 @@ module DatabaseCleaner
|
|||
|
||||
describe '#pre_count?' do
|
||||
before(:each) do
|
||||
connection.stub(:disable_referential_integrity).and_yield
|
||||
connection.stub(:database_cleaner_view_cache).and_return([])
|
||||
::ActiveRecord::Base.stub(:connection).and_return(connection)
|
||||
allow(connection).to receive(:disable_referential_integrity).and_yield
|
||||
allow(connection).to receive(:database_cleaner_view_cache).and_return([])
|
||||
allow(::ActiveRecord::Base).to receive(:connection).and_return(connection)
|
||||
end
|
||||
|
||||
subject { Truncation.new }
|
||||
|
||||
it 'should return false initially' do
|
||||
subject.send(:pre_count?).should eq false
|
||||
expect(subject.send(:pre_count?)).to eq false
|
||||
end
|
||||
|
||||
it 'should return true if @reset_id is set and non false or nil' do
|
||||
subject.instance_variable_set(:"@pre_count", true)
|
||||
subject.send(:pre_count?).should eq true
|
||||
expect(subject.send(:pre_count?)).to eq true
|
||||
end
|
||||
|
||||
it 'should return false if @reset_id is set to false' do
|
||||
subject.instance_variable_set(:"@pre_count", false)
|
||||
subject.send(:pre_count?).should eq false
|
||||
expect(subject.send(:pre_count?)).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#reset_ids?' do
|
||||
before(:each) do
|
||||
connection.stub(:disable_referential_integrity).and_yield
|
||||
connection.stub(:database_cleaner_view_cache).and_return([])
|
||||
::ActiveRecord::Base.stub(:connection).and_return(connection)
|
||||
allow(connection).to receive(:disable_referential_integrity).and_yield
|
||||
allow(connection).to receive(:database_cleaner_view_cache).and_return([])
|
||||
allow(::ActiveRecord::Base).to receive(:connection).and_return(connection)
|
||||
end
|
||||
|
||||
subject { Truncation.new }
|
||||
|
||||
it 'should return true initially' do
|
||||
subject.send(:reset_ids?).should eq true
|
||||
expect(subject.send(:reset_ids?)).to eq true
|
||||
end
|
||||
|
||||
it 'should return true if @reset_id is set and non falsey' do
|
||||
subject.instance_variable_set(:"@reset_ids", 'Something')
|
||||
subject.send(:reset_ids?).should eq true
|
||||
expect(subject.send(:reset_ids?)).to eq true
|
||||
end
|
||||
|
||||
it 'should return false if @reset_id is set to false' do
|
||||
subject.instance_variable_set(:"@reset_ids", false)
|
||||
subject.send(:reset_ids?).should eq false
|
||||
expect(subject.send(:reset_ids?)).to eq false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module DatabaseCleaner
|
|||
|
||||
let(:mock_strategy) {
|
||||
double("strategy").tap{|strategy|
|
||||
strategy.stub(:to_ary => [strategy])
|
||||
allow(strategy).to receive_messages(:to_ary => [strategy])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ module DatabaseCleaner
|
|||
let(:cleaner) { DatabaseCleaner::Base.new :autodetect }
|
||||
|
||||
it "should raise an error when no ORM is detected" do
|
||||
running { cleaner }.should raise_error(DatabaseCleaner::NoORMDetected)
|
||||
expect(running { cleaner }).to raise_error(DatabaseCleaner::NoORMDetected)
|
||||
end
|
||||
|
||||
it "should detect ActiveRecord first" do
|
||||
|
@ -90,8 +90,8 @@ module DatabaseCleaner
|
|||
Object.const_set('Redis', 'Redis mock')
|
||||
Object.const_set('Neo4j', 'Neo4j mock')
|
||||
|
||||
cleaner.orm.should eq :active_record
|
||||
cleaner.should be_auto_detected
|
||||
expect(cleaner.orm).to eq :active_record
|
||||
expect(cleaner).to be_auto_detected
|
||||
end
|
||||
|
||||
it "should detect DataMapper second" do
|
||||
|
@ -105,8 +105,8 @@ module DatabaseCleaner
|
|||
Object.const_set('Redis', 'Redis mock')
|
||||
Object.const_set('Neo4j', 'Neo4j mock')
|
||||
|
||||
cleaner.orm.should eq :data_mapper
|
||||
cleaner.should be_auto_detected
|
||||
expect(cleaner.orm).to eq :data_mapper
|
||||
expect(cleaner).to be_auto_detected
|
||||
end
|
||||
|
||||
it "should detect MongoMapper third" do
|
||||
|
@ -119,8 +119,8 @@ module DatabaseCleaner
|
|||
Object.const_set('Redis', 'Redis mock')
|
||||
Object.const_set('Neo4j', 'Neo4j mock')
|
||||
|
||||
cleaner.orm.should eq :mongo_mapper
|
||||
cleaner.should be_auto_detected
|
||||
expect(cleaner.orm).to eq :mongo_mapper
|
||||
expect(cleaner).to be_auto_detected
|
||||
end
|
||||
|
||||
it "should detect Mongoid fourth" do
|
||||
|
@ -132,8 +132,8 @@ module DatabaseCleaner
|
|||
Object.const_set('Redis', 'Redis mock')
|
||||
Object.const_set('Neo4j', 'Neo4j mock')
|
||||
|
||||
cleaner.orm.should eq :mongoid
|
||||
cleaner.should be_auto_detected
|
||||
expect(cleaner.orm).to eq :mongoid
|
||||
expect(cleaner).to be_auto_detected
|
||||
end
|
||||
|
||||
it "should detect CouchPotato fifth" do
|
||||
|
@ -144,8 +144,8 @@ module DatabaseCleaner
|
|||
Object.const_set('Redis', 'Redis mock')
|
||||
Object.const_set('Neo4j', 'Neo4j mock')
|
||||
|
||||
cleaner.orm.should eq :couch_potato
|
||||
cleaner.should be_auto_detected
|
||||
expect(cleaner.orm).to eq :couch_potato
|
||||
expect(cleaner).to be_auto_detected
|
||||
end
|
||||
|
||||
it "should detect Sequel sixth" do
|
||||
|
@ -155,15 +155,15 @@ module DatabaseCleaner
|
|||
Object.const_set('Redis', 'Redis mock')
|
||||
Object.const_set('Neo4j', 'Neo4j mock')
|
||||
|
||||
cleaner.orm.should eq :sequel
|
||||
cleaner.should be_auto_detected
|
||||
expect(cleaner.orm).to eq :sequel
|
||||
expect(cleaner).to be_auto_detected
|
||||
end
|
||||
|
||||
it 'detects Moped seventh' do
|
||||
Object.const_set('Moped', 'Moped mock')
|
||||
|
||||
cleaner.orm.should eq :moped
|
||||
cleaner.should be_auto_detected
|
||||
expect(cleaner.orm).to eq :moped
|
||||
expect(cleaner).to be_auto_detected
|
||||
end
|
||||
|
||||
it 'detects Ohm eighth' do
|
||||
|
@ -171,23 +171,23 @@ module DatabaseCleaner
|
|||
Object.const_set('Redis', 'Redis mock')
|
||||
Object.const_set('Neo4j', 'Neo4j mock')
|
||||
|
||||
cleaner.orm.should eq :ohm
|
||||
cleaner.should be_auto_detected
|
||||
expect(cleaner.orm).to eq :ohm
|
||||
expect(cleaner).to be_auto_detected
|
||||
end
|
||||
|
||||
it 'detects Redis ninth' do
|
||||
Object.const_set('Redis', 'Redis mock')
|
||||
Object.const_set('Neo4j', 'Neo4j mock')
|
||||
|
||||
cleaner.orm.should eq :redis
|
||||
cleaner.should be_auto_detected
|
||||
expect(cleaner.orm).to eq :redis
|
||||
expect(cleaner).to be_auto_detected
|
||||
end
|
||||
|
||||
it 'detects Neo4j tenth' do
|
||||
Object.const_set('Neo4j', 'Neo4j mock')
|
||||
|
||||
cleaner.orm.should eq :neo4j
|
||||
cleaner.should be_auto_detected
|
||||
expect(cleaner.orm).to eq :neo4j
|
||||
expect(cleaner).to be_auto_detected
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -197,11 +197,11 @@ module DatabaseCleaner
|
|||
mockule = double("module")
|
||||
|
||||
cleaner = ::DatabaseCleaner::Base.new
|
||||
cleaner.should_receive(:orm).and_return(orm)
|
||||
expect(cleaner).to receive(:orm).and_return(orm)
|
||||
|
||||
::DatabaseCleaner.should_receive(:orm_module).with(orm).and_return(mockule)
|
||||
expect(::DatabaseCleaner).to receive(:orm_module).with(orm).and_return(mockule)
|
||||
|
||||
cleaner.send(:orm_module).should eq mockule
|
||||
expect(cleaner.send(:orm_module)).to eq mockule
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -213,8 +213,8 @@ module DatabaseCleaner
|
|||
two = DatabaseCleaner::Base.new(:active_record,:connection => :default)
|
||||
two.strategy = mock_strategy
|
||||
|
||||
one.should eq two
|
||||
two.should eq one
|
||||
expect(one).to eq two
|
||||
expect(two).to eq one
|
||||
end
|
||||
|
||||
it "should not be equal if orm are not the same" do
|
||||
|
@ -224,8 +224,8 @@ module DatabaseCleaner
|
|||
two = DatabaseCleaner::Base.new(:active_record, :connection => :default)
|
||||
two.strategy = mock_strategy
|
||||
|
||||
one.should_not eq two
|
||||
two.should_not eq one
|
||||
expect(one).not_to eq two
|
||||
expect(two).not_to eq one
|
||||
end
|
||||
|
||||
it "should not be equal if connection are not the same" do
|
||||
|
@ -236,8 +236,8 @@ module DatabaseCleaner
|
|||
two = DatabaseCleaner::Base.new(:active_record, :connection => :other)
|
||||
two.strategy = :truncation
|
||||
|
||||
one.should_not eq two
|
||||
two.should_not eq one
|
||||
expect(one).not_to eq two
|
||||
expect(two).not_to eq one
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -246,50 +246,50 @@ module DatabaseCleaner
|
|||
subject { ::DatabaseCleaner::Base.new(:active_record,:connection => :my_db) }
|
||||
|
||||
it "should store db from :connection in params hash" do
|
||||
subject.db.should eq :my_db
|
||||
expect(subject.db).to eq :my_db
|
||||
end
|
||||
end
|
||||
|
||||
describe "orm" do
|
||||
it "should store orm" do
|
||||
cleaner = ::DatabaseCleaner::Base.new :a_orm
|
||||
cleaner.orm.should eq :a_orm
|
||||
expect(cleaner.orm).to eq :a_orm
|
||||
end
|
||||
|
||||
it "converts string to symbols" do
|
||||
cleaner = ::DatabaseCleaner::Base.new "mongoid"
|
||||
cleaner.orm.should eq :mongoid
|
||||
expect(cleaner.orm).to eq :mongoid
|
||||
end
|
||||
|
||||
it "is autodetected if orm is not provided" do
|
||||
cleaner = ::DatabaseCleaner::Base.new
|
||||
cleaner.should be_auto_detected
|
||||
expect(cleaner).to be_auto_detected
|
||||
end
|
||||
|
||||
it "is autodetected if you specify :autodetect" do
|
||||
cleaner = ::DatabaseCleaner::Base.new "autodetect"
|
||||
cleaner.should be_auto_detected
|
||||
expect(cleaner).to be_auto_detected
|
||||
end
|
||||
|
||||
it "should default to autodetect upon initalisation" do
|
||||
subject.should be_auto_detected
|
||||
expect(subject).to be_auto_detected
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "db" do
|
||||
it "should default to :default" do
|
||||
subject.db.should eq :default
|
||||
expect(subject.db).to eq :default
|
||||
end
|
||||
|
||||
it "should return any stored db value" do
|
||||
subject.stub(:strategy_db=)
|
||||
allow(subject).to receive(:strategy_db=)
|
||||
subject.db = :test_db
|
||||
subject.db.should eq :test_db
|
||||
expect(subject.db).to eq :test_db
|
||||
end
|
||||
|
||||
it "should pass db to any specified strategy" do
|
||||
subject.should_receive(:strategy_db=).with(:a_new_db)
|
||||
expect(subject).to receive(:strategy_db=).with(:a_new_db)
|
||||
subject.db = :a_new_db
|
||||
end
|
||||
end
|
||||
|
@ -302,13 +302,13 @@ module DatabaseCleaner
|
|||
end
|
||||
|
||||
it "should check that strategy supports db specification" do
|
||||
strategy.stub(:db=)
|
||||
allow(strategy).to receive(:db=)
|
||||
subject.strategy_db = :a_db
|
||||
end
|
||||
|
||||
context "when strategy supports db specification" do
|
||||
it "should pass db to the strategy" do
|
||||
strategy.should_receive(:db=).with(:a_db)
|
||||
expect(strategy).to receive(:db=).with(:a_db)
|
||||
subject.strategy_db = :a_db
|
||||
end
|
||||
end
|
||||
|
@ -316,7 +316,7 @@ module DatabaseCleaner
|
|||
context "when strategy doesn't supports db specification" do
|
||||
it "should check to see if db is :default" do
|
||||
db = double("default")
|
||||
db.should_receive(:==).with(:default).and_return(true)
|
||||
expect(db).to receive(:==).with(:default).and_return(true)
|
||||
|
||||
subject.strategy_db = db
|
||||
end
|
||||
|
@ -331,40 +331,40 @@ module DatabaseCleaner
|
|||
describe "clean_with" do
|
||||
let (:strategy) { double("strategy",:clean => true) }
|
||||
|
||||
before(:each) { subject.stub(:create_strategy).with(anything).and_return(strategy) }
|
||||
before(:each) { allow(subject).to receive(:create_strategy).with(anything).and_return(strategy) }
|
||||
|
||||
it "should pass all arguments to create_strategy" do
|
||||
subject.should_receive(:create_strategy).with(:lorum, :dollar, :amet, :ipsum => "random").and_return(strategy)
|
||||
expect(subject).to receive(:create_strategy).with(:lorum, :dollar, :amet, :ipsum => "random").and_return(strategy)
|
||||
subject.clean_with :lorum, :dollar, :amet, { :ipsum => "random" }
|
||||
end
|
||||
|
||||
it "should invoke clean on the created strategy" do
|
||||
strategy.should_receive(:clean)
|
||||
expect(strategy).to receive(:clean)
|
||||
subject.clean_with :strategy
|
||||
end
|
||||
|
||||
it "should return the strategy" do
|
||||
subject.clean_with( :strategy ).should eq strategy
|
||||
expect(subject.clean_with( :strategy )).to eq strategy
|
||||
end
|
||||
end
|
||||
|
||||
describe "clean_with!" do
|
||||
let (:strategy) { double("strategy",:clean => true) }
|
||||
|
||||
before(:each) { subject.stub(:create_strategy).with(anything).and_return(strategy) }
|
||||
before(:each) { allow(subject).to receive(:create_strategy).with(anything).and_return(strategy) }
|
||||
|
||||
it "should pass all arguments to create_strategy" do
|
||||
subject.should_receive(:create_strategy).with(:lorum, :dollar, :amet, :ipsum => "random").and_return(strategy)
|
||||
expect(subject).to receive(:create_strategy).with(:lorum, :dollar, :amet, :ipsum => "random").and_return(strategy)
|
||||
subject.clean_with! :lorum, :dollar, :amet, { :ipsum => "random" }
|
||||
end
|
||||
|
||||
it "should invoke clean on the created strategy" do
|
||||
strategy.should_receive(:clean)
|
||||
expect(strategy).to receive(:clean)
|
||||
subject.clean_with! :strategy
|
||||
end
|
||||
|
||||
it "should return the strategy" do
|
||||
subject.clean_with!( :strategy ).should eq strategy
|
||||
expect(subject.clean_with!( :strategy )).to eq strategy
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -372,31 +372,31 @@ module DatabaseCleaner
|
|||
let(:strategy_class) { double("strategy_class",:new => double("instance")) }
|
||||
|
||||
before :each do
|
||||
subject.stub(:orm_strategy).and_return(strategy_class)
|
||||
allow(subject).to receive(:orm_strategy).and_return(strategy_class)
|
||||
end
|
||||
|
||||
it "should pass the first argument to orm_strategy" do
|
||||
subject.should_receive(:orm_strategy).with(:strategy).and_return(Object)
|
||||
expect(subject).to receive(:orm_strategy).with(:strategy).and_return(Object)
|
||||
subject.create_strategy :strategy
|
||||
end
|
||||
it "should pass the remainding argument to orm_strategy.new" do
|
||||
strategy_class.should_receive(:new).with(:params => {:lorum => "ipsum"})
|
||||
expect(strategy_class).to receive(:new).with(:params => {:lorum => "ipsum"})
|
||||
|
||||
subject.create_strategy :strategy, {:params => {:lorum => "ipsum"}}
|
||||
end
|
||||
it "should return the resulting strategy" do
|
||||
subject.create_strategy( :strategy ).should eq strategy_class.new
|
||||
expect(subject.create_strategy( :strategy )).to eq strategy_class.new
|
||||
end
|
||||
end
|
||||
|
||||
describe "strategy=" do
|
||||
it "should proxy symbolised strategies to create_strategy" do
|
||||
subject.should_receive(:create_strategy).with(:symbol)
|
||||
expect(subject).to receive(:create_strategy).with(:symbol)
|
||||
subject.strategy = :symbol
|
||||
end
|
||||
|
||||
it "should proxy params with symbolised strategies" do
|
||||
subject.should_receive(:create_strategy).with(:symbol,:param => "one")
|
||||
expect(subject).to receive(:create_strategy).with(:symbol,:param => "one")
|
||||
subject.strategy= :symbol, {:param => "one"}
|
||||
end
|
||||
|
||||
|
@ -409,14 +409,14 @@ module DatabaseCleaner
|
|||
end
|
||||
|
||||
it "should attempt to set strategy db" do
|
||||
subject.stub(:db).and_return(:my_db)
|
||||
subject.should_receive(:set_strategy_db).with(mock_strategy, :my_db)
|
||||
allow(subject).to receive(:db).and_return(:my_db)
|
||||
expect(subject).to receive(:set_strategy_db).with(mock_strategy, :my_db)
|
||||
subject.strategy = mock_strategy
|
||||
end
|
||||
|
||||
it "should return the stored strategy" do
|
||||
result = subject.strategy = mock_strategy
|
||||
result.should eq mock_strategy
|
||||
expect(result).to eq mock_strategy
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -424,20 +424,20 @@ module DatabaseCleaner
|
|||
subject { ::DatabaseCleaner::Base.new :a_orm }
|
||||
|
||||
it "returns a null strategy when strategy is not set and undetectable" do
|
||||
subject.strategy.should eq DatabaseCleaner::NullStrategy
|
||||
expect(subject.strategy).to eq DatabaseCleaner::NullStrategy
|
||||
end
|
||||
|
||||
it "returns the set strategy" do
|
||||
subject.strategy = mock_strategy
|
||||
subject.strategy.should eq mock_strategy
|
||||
expect(subject.strategy).to eq mock_strategy
|
||||
end
|
||||
end
|
||||
|
||||
describe "orm=" do
|
||||
it "should stored the desired orm" do
|
||||
subject.orm.should_not eq :desired_orm
|
||||
expect(subject.orm).not_to eq :desired_orm
|
||||
subject.orm = :desired_orm
|
||||
subject.orm.should eq :desired_orm
|
||||
expect(subject.orm).to eq :desired_orm
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -446,20 +446,20 @@ module DatabaseCleaner
|
|||
|
||||
it "should return orm if orm set" do
|
||||
subject.instance_variable_set "@orm", mock_orm
|
||||
subject.orm.should eq mock_orm
|
||||
expect(subject.orm).to eq mock_orm
|
||||
end
|
||||
|
||||
context "orm isn't set" do
|
||||
before(:each) { subject.instance_variable_set "@orm", nil }
|
||||
|
||||
it "should run autodetect if orm isn't set" do
|
||||
subject.should_receive(:autodetect)
|
||||
expect(subject).to receive(:autodetect)
|
||||
subject.orm
|
||||
end
|
||||
|
||||
it "should return the result of autodetect if orm isn't set" do
|
||||
subject.stub(:autodetect).and_return(mock_orm)
|
||||
subject.orm.should eq mock_orm
|
||||
allow(subject).to receive(:autodetect).and_return(mock_orm)
|
||||
expect(subject.orm).to eq mock_orm
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -468,33 +468,33 @@ module DatabaseCleaner
|
|||
let (:strategy) { double("strategy") }
|
||||
|
||||
before(:each) do
|
||||
subject.stub(:strategy).and_return(strategy)
|
||||
allow(subject).to receive(:strategy).and_return(strategy)
|
||||
end
|
||||
|
||||
describe "start" do
|
||||
it "should proxy start to the strategy" do
|
||||
strategy.should_receive(:start)
|
||||
expect(strategy).to receive(:start)
|
||||
subject.start
|
||||
end
|
||||
end
|
||||
|
||||
describe "clean" do
|
||||
it "should proxy clean to the strategy" do
|
||||
strategy.should_receive(:clean)
|
||||
expect(strategy).to receive(:clean)
|
||||
subject.clean
|
||||
end
|
||||
end
|
||||
|
||||
describe "clean!" do
|
||||
it "should proxy clean! to the strategy clean" do
|
||||
strategy.should_receive(:clean)
|
||||
expect(strategy).to receive(:clean)
|
||||
subject.clean!
|
||||
end
|
||||
end
|
||||
|
||||
describe "cleaning" do
|
||||
it "should proxy cleaning to the strategy" do
|
||||
strategy.should_receive(:cleaning)
|
||||
expect(strategy).to receive(:cleaning)
|
||||
subject.cleaning { }
|
||||
end
|
||||
end
|
||||
|
@ -503,12 +503,12 @@ module DatabaseCleaner
|
|||
describe "auto_detected?" do
|
||||
it "should return true unless @autodetected is nil" do
|
||||
subject.instance_variable_set("@autodetected","not nil")
|
||||
subject.auto_detected?.should be_truthy
|
||||
expect(subject.auto_detected?).to be_truthy
|
||||
end
|
||||
|
||||
it "should return false if @autodetect is nil" do
|
||||
subject.instance_variable_set("@autodetected",nil)
|
||||
subject.auto_detected?.should be_falsey
|
||||
expect(subject.auto_detected?).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -516,28 +516,28 @@ module DatabaseCleaner
|
|||
let (:strategy_class) { double("strategy_class") }
|
||||
|
||||
before(:each) do
|
||||
subject.stub(:orm_module).and_return(strategy_class)
|
||||
allow(subject).to receive(:orm_module).and_return(strategy_class)
|
||||
end
|
||||
|
||||
context "in response to a LoadError" do
|
||||
before(:each) { subject.should_receive(:require).with(anything).and_raise(LoadError) }
|
||||
before(:each) { expect(subject).to receive(:require).with(anything).and_raise(LoadError) }
|
||||
|
||||
it "should raise UnknownStrategySpecified" do
|
||||
expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified
|
||||
end
|
||||
|
||||
it "should ask orm_module if it will list available_strategies" do
|
||||
strategy_class.should_receive(:respond_to?).with(:available_strategies)
|
||||
expect(strategy_class).to receive(:respond_to?).with(:available_strategies)
|
||||
|
||||
subject.stub(:orm_module).and_return(strategy_class)
|
||||
allow(subject).to receive(:orm_module).and_return(strategy_class)
|
||||
|
||||
expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified
|
||||
end
|
||||
|
||||
it "should use available_strategies (for the error message) if its available" do
|
||||
strategy_class.should_receive(:available_strategies).and_return([])
|
||||
expect(strategy_class).to receive(:available_strategies).and_return([])
|
||||
|
||||
subject.stub(:orm_module).and_return(strategy_class)
|
||||
allow(subject).to receive(:orm_module).and_return(strategy_class)
|
||||
|
||||
expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified
|
||||
end
|
||||
|
@ -546,11 +546,11 @@ module DatabaseCleaner
|
|||
it "should return the constant of the Strategy class requested" do
|
||||
strategy_strategy_class = double("strategy strategy_class")
|
||||
|
||||
subject.stub(:require).with(anything).and_return(true)
|
||||
allow(subject).to receive(:require).with(anything).and_return(true)
|
||||
|
||||
strategy_class.should_receive(:const_get).with("Cunningplan").and_return(strategy_strategy_class)
|
||||
expect(strategy_class).to receive(:const_get).with("Cunningplan").and_return(strategy_strategy_class)
|
||||
|
||||
subject.send(:orm_strategy, :cunningplan).should eq strategy_strategy_class
|
||||
expect(subject.send(:orm_strategy, :cunningplan)).to eq strategy_strategy_class
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -558,52 +558,52 @@ module DatabaseCleaner
|
|||
describe 'set_default_orm_strategy' do
|
||||
it 'sets strategy to :transaction for ActiveRecord' do
|
||||
cleaner = DatabaseCleaner::Base.new(:active_record)
|
||||
cleaner.strategy.should be_instance_of DatabaseCleaner::ActiveRecord::Transaction
|
||||
expect(cleaner.strategy).to be_instance_of DatabaseCleaner::ActiveRecord::Transaction
|
||||
end
|
||||
|
||||
it 'sets strategy to :transaction for DataMapper' do
|
||||
cleaner = DatabaseCleaner::Base.new(:data_mapper)
|
||||
cleaner.strategy.should be_instance_of DatabaseCleaner::DataMapper::Transaction
|
||||
expect(cleaner.strategy).to be_instance_of DatabaseCleaner::DataMapper::Transaction
|
||||
end
|
||||
|
||||
it 'sets strategy to :truncation for MongoMapper' do
|
||||
cleaner = DatabaseCleaner::Base.new(:mongo_mapper)
|
||||
cleaner.strategy.should be_instance_of DatabaseCleaner::MongoMapper::Truncation
|
||||
expect(cleaner.strategy).to be_instance_of DatabaseCleaner::MongoMapper::Truncation
|
||||
end
|
||||
|
||||
it 'sets strategy to :truncation for Mongoid' do
|
||||
cleaner = DatabaseCleaner::Base.new(:mongoid)
|
||||
cleaner.strategy.should be_instance_of DatabaseCleaner::Mongoid::Truncation
|
||||
expect(cleaner.strategy).to be_instance_of DatabaseCleaner::Mongoid::Truncation
|
||||
end
|
||||
|
||||
it 'sets strategy to :truncation for CouchPotato' do
|
||||
cleaner = DatabaseCleaner::Base.new(:couch_potato)
|
||||
cleaner.strategy.should be_instance_of DatabaseCleaner::CouchPotato::Truncation
|
||||
expect(cleaner.strategy).to be_instance_of DatabaseCleaner::CouchPotato::Truncation
|
||||
end
|
||||
|
||||
it 'sets strategy to :transaction for Sequel' do
|
||||
cleaner = DatabaseCleaner::Base.new(:sequel)
|
||||
cleaner.strategy.should be_instance_of DatabaseCleaner::Sequel::Transaction
|
||||
expect(cleaner.strategy).to be_instance_of DatabaseCleaner::Sequel::Transaction
|
||||
end
|
||||
|
||||
it 'sets strategy to :truncation for Moped' do
|
||||
cleaner = DatabaseCleaner::Base.new(:moped)
|
||||
cleaner.strategy.should be_instance_of DatabaseCleaner::Moped::Truncation
|
||||
expect(cleaner.strategy).to be_instance_of DatabaseCleaner::Moped::Truncation
|
||||
end
|
||||
|
||||
it 'sets strategy to :truncation for Ohm' do
|
||||
cleaner = DatabaseCleaner::Base.new(:ohm)
|
||||
cleaner.strategy.should be_instance_of DatabaseCleaner::Ohm::Truncation
|
||||
expect(cleaner.strategy).to be_instance_of DatabaseCleaner::Ohm::Truncation
|
||||
end
|
||||
|
||||
it 'sets strategy to :truncation for Redis' do
|
||||
cleaner = DatabaseCleaner::Base.new(:redis)
|
||||
cleaner.strategy.should be_instance_of DatabaseCleaner::Redis::Truncation
|
||||
expect(cleaner.strategy).to be_instance_of DatabaseCleaner::Redis::Truncation
|
||||
end
|
||||
|
||||
it 'sets strategy to :transaction for Neo4j' do
|
||||
cleaner = DatabaseCleaner::Base.new(:neo4j)
|
||||
cleaner.strategy.should be_instance_of DatabaseCleaner::Neo4j::Transaction
|
||||
expect(cleaner.strategy).to be_instance_of DatabaseCleaner::Neo4j::Transaction
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -30,71 +30,71 @@ describe ::DatabaseCleaner do
|
|||
|
||||
it "should accept :active_record" do
|
||||
cleaner = ::DatabaseCleaner[:active_record]
|
||||
cleaner.should be_a(::DatabaseCleaner::Base)
|
||||
cleaner.orm.should eq :active_record
|
||||
::DatabaseCleaner.connections.size.should eq 1
|
||||
expect(cleaner).to be_a(::DatabaseCleaner::Base)
|
||||
expect(cleaner.orm).to eq :active_record
|
||||
expect(::DatabaseCleaner.connections.size).to eq 1
|
||||
end
|
||||
|
||||
it "should accept :data_mapper" do
|
||||
cleaner = ::DatabaseCleaner[:data_mapper]
|
||||
cleaner.should be_a(::DatabaseCleaner::Base)
|
||||
cleaner.orm.should eq :data_mapper
|
||||
::DatabaseCleaner.connections.size.should eq 1
|
||||
expect(cleaner).to be_a(::DatabaseCleaner::Base)
|
||||
expect(cleaner.orm).to eq :data_mapper
|
||||
expect(::DatabaseCleaner.connections.size).to eq 1
|
||||
end
|
||||
|
||||
it "should accept :mongo_mapper" do
|
||||
cleaner = ::DatabaseCleaner[:mongo_mapper]
|
||||
cleaner.should be_a(::DatabaseCleaner::Base)
|
||||
cleaner.orm.should eq :mongo_mapper
|
||||
::DatabaseCleaner.connections.size.should eq 1
|
||||
expect(cleaner).to be_a(::DatabaseCleaner::Base)
|
||||
expect(cleaner.orm).to eq :mongo_mapper
|
||||
expect(::DatabaseCleaner.connections.size).to eq 1
|
||||
end
|
||||
|
||||
it "should accept :couch_potato" do
|
||||
cleaner = ::DatabaseCleaner[:couch_potato]
|
||||
cleaner.should be_a(::DatabaseCleaner::Base)
|
||||
cleaner.orm.should eq :couch_potato
|
||||
::DatabaseCleaner.connections.size.should eq 1
|
||||
expect(cleaner).to be_a(::DatabaseCleaner::Base)
|
||||
expect(cleaner.orm).to eq :couch_potato
|
||||
expect(::DatabaseCleaner.connections.size).to eq 1
|
||||
end
|
||||
|
||||
it "should accept :moped" do
|
||||
cleaner = ::DatabaseCleaner[:moped]
|
||||
cleaner.should be_a(::DatabaseCleaner::Base)
|
||||
cleaner.orm.should eq :moped
|
||||
::DatabaseCleaner.connections.size.should eq 1
|
||||
expect(cleaner).to be_a(::DatabaseCleaner::Base)
|
||||
expect(cleaner.orm).to eq :moped
|
||||
expect(::DatabaseCleaner.connections.size).to eq 1
|
||||
end
|
||||
|
||||
it 'accepts :ohm' do
|
||||
cleaner = ::DatabaseCleaner[:ohm]
|
||||
cleaner.should be_a(::DatabaseCleaner::Base)
|
||||
cleaner.orm.should eq :ohm
|
||||
::DatabaseCleaner.connections.size.should eq 1
|
||||
expect(cleaner).to be_a(::DatabaseCleaner::Base)
|
||||
expect(cleaner.orm).to eq :ohm
|
||||
expect(::DatabaseCleaner.connections.size).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
it "should accept multiple orm's" do
|
||||
::DatabaseCleaner[:couch_potato]
|
||||
::DatabaseCleaner[:data_mapper]
|
||||
::DatabaseCleaner.connections.size.should eq 2
|
||||
::DatabaseCleaner.connections[0].orm.should eq :couch_potato
|
||||
::DatabaseCleaner.connections[1].orm.should eq :data_mapper
|
||||
expect(::DatabaseCleaner.connections.size).to eq 2
|
||||
expect(::DatabaseCleaner.connections[0].orm).to eq :couch_potato
|
||||
expect(::DatabaseCleaner.connections[1].orm).to eq :data_mapper
|
||||
end
|
||||
|
||||
context "connection/db specification" do
|
||||
it "should accept a connection parameter and store it" do
|
||||
cleaner = ::DatabaseCleaner[:active_record, {:connection => :first_connection}]
|
||||
cleaner.should be_a(::DatabaseCleaner::Base)
|
||||
cleaner.orm.should eq :active_record
|
||||
cleaner.db.should eq :first_connection
|
||||
expect(cleaner).to be_a(::DatabaseCleaner::Base)
|
||||
expect(cleaner.orm).to eq :active_record
|
||||
expect(cleaner.db).to eq :first_connection
|
||||
end
|
||||
|
||||
it "should accept multiple connections for a single orm" do
|
||||
::DatabaseCleaner[:data_mapper,{:connection => :first_db}]
|
||||
::DatabaseCleaner[:data_mapper,{:connection => :second_db}]
|
||||
::DatabaseCleaner.connections.size.should eq 2
|
||||
::DatabaseCleaner.connections[0].orm.should eq :data_mapper
|
||||
::DatabaseCleaner.connections[0].db.should eq :first_db
|
||||
::DatabaseCleaner.connections[1].orm.should eq :data_mapper
|
||||
::DatabaseCleaner.connections[1].db.should eq :second_db
|
||||
expect(::DatabaseCleaner.connections.size).to eq 2
|
||||
expect(::DatabaseCleaner.connections[0].orm).to eq :data_mapper
|
||||
expect(::DatabaseCleaner.connections[0].db).to eq :first_db
|
||||
expect(::DatabaseCleaner.connections[1].orm).to eq :data_mapper
|
||||
expect(::DatabaseCleaner.connections[1].db).to eq :second_db
|
||||
end
|
||||
|
||||
it "should accept multiple connections and multiple orms" do
|
||||
|
@ -103,19 +103,19 @@ describe ::DatabaseCleaner do
|
|||
::DatabaseCleaner[:active_record,{:connection => :first_db} ]
|
||||
::DatabaseCleaner[:data_mapper, {:connection => :second_db}]
|
||||
|
||||
::DatabaseCleaner.connections.size.should eq 4
|
||||
expect(::DatabaseCleaner.connections.size).to eq 4
|
||||
|
||||
::DatabaseCleaner.connections[0].orm.should eq :data_mapper
|
||||
::DatabaseCleaner.connections[0].db.should eq :first_db
|
||||
expect(::DatabaseCleaner.connections[0].orm).to eq :data_mapper
|
||||
expect(::DatabaseCleaner.connections[0].db).to eq :first_db
|
||||
|
||||
::DatabaseCleaner.connections[1].orm.should eq :active_record
|
||||
::DatabaseCleaner.connections[1].db.should eq :second_db
|
||||
expect(::DatabaseCleaner.connections[1].orm).to eq :active_record
|
||||
expect(::DatabaseCleaner.connections[1].db).to eq :second_db
|
||||
|
||||
::DatabaseCleaner.connections[2].orm.should eq :active_record
|
||||
::DatabaseCleaner.connections[2].db.should eq :first_db
|
||||
expect(::DatabaseCleaner.connections[2].orm).to eq :active_record
|
||||
expect(::DatabaseCleaner.connections[2].db).to eq :first_db
|
||||
|
||||
::DatabaseCleaner.connections[3].orm.should eq :data_mapper
|
||||
::DatabaseCleaner.connections[3].db.should eq :second_db
|
||||
expect(::DatabaseCleaner.connections[3].orm).to eq :data_mapper
|
||||
expect(::DatabaseCleaner.connections[3].db).to eq :second_db
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -123,7 +123,7 @@ describe ::DatabaseCleaner do
|
|||
it "should retrieve a db rather than create a new one" do
|
||||
pending
|
||||
connection = ::DatabaseCleaner[:active_record].strategy = :truncation
|
||||
::DatabaseCleaner[:active_record].should eq connection
|
||||
expect(::DatabaseCleaner[:active_record]).to eq connection
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -132,9 +132,9 @@ describe ::DatabaseCleaner do
|
|||
|
||||
it "should give me a default (autodetection) databasecleaner by default" do
|
||||
cleaner = double("cleaner").as_null_object
|
||||
::DatabaseCleaner::Base.stub(:new).and_return(cleaner)
|
||||
allow(::DatabaseCleaner::Base).to receive(:new).and_return(cleaner)
|
||||
|
||||
::DatabaseCleaner.connections.should eq [cleaner]
|
||||
expect(::DatabaseCleaner.connections).to eq [cleaner]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -143,34 +143,34 @@ describe ::DatabaseCleaner do
|
|||
|
||||
it "should proxy strategy=" do
|
||||
stratagum = double("stratagum")
|
||||
connection.should_receive(:strategy=).with(stratagum)
|
||||
expect(connection).to receive(:strategy=).with(stratagum)
|
||||
::DatabaseCleaner.strategy = stratagum
|
||||
end
|
||||
|
||||
it "should proxy orm=" do
|
||||
orm = double("orm")
|
||||
connection.should_receive(:orm=).with(orm)
|
||||
expect(connection).to receive(:orm=).with(orm)
|
||||
::DatabaseCleaner.orm = orm
|
||||
end
|
||||
|
||||
it "should proxy start" do
|
||||
connection.should_receive(:start)
|
||||
expect(connection).to receive(:start)
|
||||
::DatabaseCleaner.start
|
||||
end
|
||||
|
||||
it "should proxy clean" do
|
||||
connection.should_receive(:clean)
|
||||
expect(connection).to receive(:clean)
|
||||
::DatabaseCleaner.clean
|
||||
end
|
||||
|
||||
it 'should proxy cleaning' do
|
||||
connection.should_receive(:cleaning)
|
||||
expect(connection).to receive(:cleaning)
|
||||
::DatabaseCleaner.cleaning { }
|
||||
end
|
||||
|
||||
it "should proxy clean_with" do
|
||||
stratagem = double("stratgem")
|
||||
connection.should_receive(:clean_with).with(stratagem, {})
|
||||
expect(connection).to receive(:clean_with).with(stratagem, {})
|
||||
::DatabaseCleaner.clean_with stratagem, {}
|
||||
end
|
||||
end
|
||||
|
@ -184,26 +184,26 @@ describe ::DatabaseCleaner do
|
|||
let(:data_mapper) { double("data_mock") }
|
||||
|
||||
before(:each) do
|
||||
::DatabaseCleaner.stub(:connections).and_return([active_record,data_mapper])
|
||||
allow(::DatabaseCleaner).to receive(:connections).and_return([active_record,data_mapper])
|
||||
end
|
||||
|
||||
it "should proxy orm to all connections" do
|
||||
active_record.should_receive(:orm=)
|
||||
data_mapper.should_receive(:orm=)
|
||||
expect(active_record).to receive(:orm=)
|
||||
expect(data_mapper).to receive(:orm=)
|
||||
|
||||
::DatabaseCleaner.orm = double("orm")
|
||||
end
|
||||
|
||||
it "should proxy start to all connections" do
|
||||
active_record.should_receive(:start)
|
||||
data_mapper.should_receive(:start)
|
||||
expect(active_record).to receive(:start)
|
||||
expect(data_mapper).to receive(:start)
|
||||
|
||||
::DatabaseCleaner.start
|
||||
end
|
||||
|
||||
it "should proxy clean to all connections" do
|
||||
active_record.should_receive(:clean)
|
||||
data_mapper.should_receive(:clean)
|
||||
expect(active_record).to receive(:clean)
|
||||
expect(data_mapper).to receive(:clean)
|
||||
|
||||
::DatabaseCleaner.clean
|
||||
end
|
||||
|
@ -220,20 +220,20 @@ describe ::DatabaseCleaner do
|
|||
end
|
||||
|
||||
::DatabaseCleaner.cleaning do
|
||||
active_record.started.should == true
|
||||
data_mapper.started.should == true
|
||||
active_record.cleaned.should == nil
|
||||
data_mapper.cleaned.should == nil
|
||||
expect(active_record.started).to eq(true)
|
||||
expect(data_mapper.started).to eq(true)
|
||||
expect(active_record.cleaned).to eq(nil)
|
||||
expect(data_mapper.cleaned).to eq(nil)
|
||||
@yielded = true
|
||||
end
|
||||
active_record.cleaned.should == true
|
||||
data_mapper.cleaned.should == true
|
||||
expect(active_record.cleaned).to eq(true)
|
||||
expect(data_mapper.cleaned).to eq(true)
|
||||
end
|
||||
|
||||
it "should proxy clean_with to all connections" do
|
||||
stratagem = double("stratgem")
|
||||
active_record.should_receive(:clean_with).with(stratagem)
|
||||
data_mapper.should_receive(:clean_with).with(stratagem)
|
||||
expect(active_record).to receive(:clean_with).with(stratagem)
|
||||
expect(data_mapper).to receive(:clean_with).with(stratagem)
|
||||
|
||||
::DatabaseCleaner.clean_with stratagem
|
||||
end
|
||||
|
@ -250,15 +250,15 @@ describe ::DatabaseCleaner do
|
|||
|
||||
::DatabaseCleaner.connections_stub [active_record_1,active_record_2,data_mapper_1]
|
||||
|
||||
active_record_1.should_receive(:orm=).with(:data_mapper)
|
||||
active_record_2.should_receive(:orm=).with(:data_mapper)
|
||||
data_mapper_1.should_receive(:orm=).with(:data_mapper)
|
||||
expect(active_record_1).to receive(:orm=).with(:data_mapper)
|
||||
expect(active_record_2).to receive(:orm=).with(:data_mapper)
|
||||
expect(data_mapper_1).to receive(:orm=).with(:data_mapper)
|
||||
|
||||
active_record_1.should_receive(:==).with(data_mapper_1).and_return(true)
|
||||
expect(active_record_1).to receive(:==).with(data_mapper_1).and_return(true)
|
||||
|
||||
::DatabaseCleaner.connections.size.should eq 3
|
||||
expect(::DatabaseCleaner.connections.size).to eq 3
|
||||
::DatabaseCleaner.orm = :data_mapper
|
||||
::DatabaseCleaner.connections.size.should eq 2
|
||||
expect(::DatabaseCleaner.connections.size).to eq 2
|
||||
end
|
||||
|
||||
it "should proxy strategy to all connections and remove duplicate connections" do
|
||||
|
@ -268,14 +268,14 @@ describe ::DatabaseCleaner do
|
|||
|
||||
::DatabaseCleaner.connections_stub [active_record_1,active_record_2]
|
||||
|
||||
active_record_1.should_receive(:strategy=).with(strategy)
|
||||
active_record_2.should_receive(:strategy=).with(strategy)
|
||||
expect(active_record_1).to receive(:strategy=).with(strategy)
|
||||
expect(active_record_2).to receive(:strategy=).with(strategy)
|
||||
|
||||
active_record_1.should_receive(:==).with(active_record_2).and_return(true)
|
||||
expect(active_record_1).to receive(:==).with(active_record_2).and_return(true)
|
||||
|
||||
::DatabaseCleaner.connections.size.should eq 2
|
||||
expect(::DatabaseCleaner.connections.size).to eq 2
|
||||
::DatabaseCleaner.strategy = strategy
|
||||
::DatabaseCleaner.connections.size.should eq 1
|
||||
expect(::DatabaseCleaner.connections.size).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -288,18 +288,18 @@ describe ::DatabaseCleaner do
|
|||
::DatabaseCleaner.connections_stub [connection,connection,connection]
|
||||
|
||||
::DatabaseCleaner.remove_duplicates
|
||||
::DatabaseCleaner.connections.size.should eq 1
|
||||
expect(::DatabaseCleaner.connections.size).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "app_root" do
|
||||
it "should default to Dir.pwd" do
|
||||
DatabaseCleaner.app_root.should eq Dir.pwd
|
||||
expect(DatabaseCleaner.app_root).to eq Dir.pwd
|
||||
end
|
||||
|
||||
it "should store specific paths" do
|
||||
DatabaseCleaner.app_root = '/path/to'
|
||||
DatabaseCleaner.app_root.should eq '/path/to'
|
||||
expect(DatabaseCleaner.app_root).to eq '/path/to'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -308,37 +308,37 @@ describe ::DatabaseCleaner do
|
|||
|
||||
it "should return DatabaseCleaner::ActiveRecord for :active_record" do
|
||||
::DatabaseCleaner::ActiveRecord = double("ar module") unless defined? ::DatabaseCleaner::ActiveRecord
|
||||
subject.orm_module(:active_record).should eq DatabaseCleaner::ActiveRecord
|
||||
expect(subject.orm_module(:active_record)).to eq DatabaseCleaner::ActiveRecord
|
||||
end
|
||||
|
||||
it "should return DatabaseCleaner::DataMapper for :data_mapper" do
|
||||
::DatabaseCleaner::DataMapper = double("dm module") unless defined? ::DatabaseCleaner::DataMapper
|
||||
subject.orm_module(:data_mapper).should eq DatabaseCleaner::DataMapper
|
||||
expect(subject.orm_module(:data_mapper)).to eq DatabaseCleaner::DataMapper
|
||||
end
|
||||
|
||||
it "should return DatabaseCleaner::MongoMapper for :mongo_mapper" do
|
||||
::DatabaseCleaner::MongoMapper = double("mm module") unless defined? ::DatabaseCleaner::MongoMapper
|
||||
subject.orm_module(:mongo_mapper).should eq DatabaseCleaner::MongoMapper
|
||||
expect(subject.orm_module(:mongo_mapper)).to eq DatabaseCleaner::MongoMapper
|
||||
end
|
||||
|
||||
it "should return DatabaseCleaner::Mongoid for :mongoid" do
|
||||
::DatabaseCleaner::Mongoid = double("mongoid module") unless defined? ::DatabaseCleaner::Mongoid
|
||||
subject.orm_module(:mongoid).should eq DatabaseCleaner::Mongoid
|
||||
expect(subject.orm_module(:mongoid)).to eq DatabaseCleaner::Mongoid
|
||||
end
|
||||
|
||||
it "should return DatabaseCleaner::Mongo for :mongo" do
|
||||
::DatabaseCleaner::Mongo = double("mongo module") unless defined? ::DatabaseCleaner::Mongo
|
||||
subject.orm_module(:mongo).should eq DatabaseCleaner::Mongo
|
||||
expect(subject.orm_module(:mongo)).to eq DatabaseCleaner::Mongo
|
||||
end
|
||||
|
||||
it "should return DatabaseCleaner::CouchPotato for :couch_potato" do
|
||||
::DatabaseCleaner::CouchPotato = double("cp module") unless defined? ::DatabaseCleaner::CouchPotato
|
||||
subject.orm_module(:couch_potato).should eq DatabaseCleaner::CouchPotato
|
||||
expect(subject.orm_module(:couch_potato)).to eq DatabaseCleaner::CouchPotato
|
||||
end
|
||||
|
||||
it "should return DatabaseCleaner::Neo4j for :neo4j" do
|
||||
::DatabaseCleaner::Neo4j = double("nj module") unless defined? ::DatabaseCleaner::Neo4j
|
||||
subject.orm_module(:neo4j).should eq DatabaseCleaner::Neo4j
|
||||
expect(subject.orm_module(:neo4j)).to eq DatabaseCleaner::Neo4j
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -9,31 +9,31 @@ module DatabaseCleaner
|
|||
let(:database) { double('database') }
|
||||
|
||||
before(:each) do
|
||||
::CouchPotato.stub(:couchrest_database).and_return(database)
|
||||
allow(::CouchPotato).to receive(:couchrest_database).and_return(database)
|
||||
end
|
||||
|
||||
it "should re-create the database" do
|
||||
database.should_receive(:recreate!)
|
||||
expect(database).to receive(:recreate!)
|
||||
|
||||
Truncation.new.clean
|
||||
end
|
||||
|
||||
it "should raise an error when the :only option is used" do
|
||||
running {
|
||||
expect(running {
|
||||
Truncation.new(:only => ['document-type'])
|
||||
}.should raise_error(ArgumentError)
|
||||
}).to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "should raise an error when the :except option is used" do
|
||||
running {
|
||||
expect(running {
|
||||
Truncation.new(:except => ['document-type'])
|
||||
}.should raise_error(ArgumentError)
|
||||
}).to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "should raise an error when invalid options are provided" do
|
||||
running {
|
||||
expect(running {
|
||||
Truncation.new(:foo => 'bar')
|
||||
}.should raise_error(ArgumentError)
|
||||
}).to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'database_cleaner/shared_strategy'
|
|||
|
||||
module DatabaseCleaner
|
||||
describe DataMapper do
|
||||
it { should respond_to(:available_strategies) }
|
||||
it { is_expected.to respond_to(:available_strategies) }
|
||||
end
|
||||
|
||||
module DataMapper
|
||||
|
@ -14,16 +14,16 @@ module DatabaseCleaner
|
|||
|
||||
describe ExampleStrategy do
|
||||
it_should_behave_like "a generic strategy"
|
||||
it { should respond_to(:db) }
|
||||
it { should respond_to(:db=) }
|
||||
it { is_expected.to respond_to(:db) }
|
||||
it { is_expected.to respond_to(:db=) }
|
||||
|
||||
it "should store my desired db" do
|
||||
subject.db = :my_db
|
||||
subject.db.should eq :my_db
|
||||
expect(subject.db).to eq :my_db
|
||||
end
|
||||
|
||||
it "should default to :default" do
|
||||
subject.db.should eq :default
|
||||
expect(subject.db).to eq :default
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ module DataMapper
|
|||
2.times { DmUser.create }
|
||||
|
||||
connection.truncate_table(DmUser.storage_names[:default])
|
||||
DmUser.count.should eq 0
|
||||
expect(DmUser.count).to eq 0
|
||||
end
|
||||
|
||||
it "resets AUTO_INCREMENT index of table" do
|
||||
|
@ -33,7 +33,7 @@ module DataMapper
|
|||
|
||||
connection.truncate_table(DmUser.storage_names[:default])
|
||||
|
||||
DmUser.create.id.should eq 1
|
||||
expect(DmUser.create.id).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,14 +35,14 @@ module ::DatabaseCleaner
|
|||
let (:strategy) { ExampleStrategy.new }
|
||||
before do
|
||||
# DatabaseCleaner.strategy = :truncation
|
||||
connection.stub(:disable_referential_integrity).and_yield
|
||||
connection.stub(:database_cleaner_view_cache).and_return([])
|
||||
connection.stub(:database_cleaner_table_cache).and_return([])
|
||||
::ActiveRecord::Base.stub(:connection).and_return(connection)
|
||||
allow(connection).to receive(:disable_referential_integrity).and_yield
|
||||
allow(connection).to receive(:database_cleaner_view_cache).and_return([])
|
||||
allow(connection).to receive(:database_cleaner_table_cache).and_return([])
|
||||
allow(::ActiveRecord::Base).to receive(:connection).and_return(connection)
|
||||
end
|
||||
|
||||
it "calls #clean even if there is an exception" do
|
||||
strategy.should_receive :clean
|
||||
expect(strategy).to receive :clean
|
||||
expect do
|
||||
strategy.cleaning do
|
||||
raise NoMethodError
|
||||
|
@ -51,7 +51,7 @@ module ::DatabaseCleaner
|
|||
end
|
||||
|
||||
it "calls #clean after processing the block" do
|
||||
strategy.should_receive :clean
|
||||
expect(strategy).to receive :clean
|
||||
strategy.cleaning do
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,13 +41,13 @@ module ::DatabaseCleaner
|
|||
end
|
||||
|
||||
context "private methods" do
|
||||
it { should_not respond_to(:tables_to_truncate) }
|
||||
it { is_expected.not_to respond_to(:tables_to_truncate) }
|
||||
|
||||
it 'expects #tables_to_truncate to be implemented later' do
|
||||
expect{ truncation_example.send :tables_to_truncate }.to raise_error(NotImplementedError)
|
||||
end
|
||||
|
||||
it { should_not respond_to(:migration_storage_names) }
|
||||
it { is_expected.not_to respond_to(:migration_storage_names) }
|
||||
end
|
||||
|
||||
describe "initialize" do
|
||||
|
@ -66,40 +66,40 @@ module ::DatabaseCleaner
|
|||
|
||||
context "" do
|
||||
subject { TruncationExample.new( { :only => ["something"] } ) }
|
||||
it { subject.only.should eq ["something"] }
|
||||
it { subject.except.should eq [] }
|
||||
it { expect(subject.only).to eq ["something"] }
|
||||
it { expect(subject.except).to eq [] }
|
||||
end
|
||||
|
||||
context "" do
|
||||
subject { TruncationExample.new( { :except => ["something"] } ) }
|
||||
it { subject.only.should eq nil }
|
||||
it { subject.except.should include("something") }
|
||||
it { expect(subject.only).to eq nil }
|
||||
it { expect(subject.except).to include("something") }
|
||||
end
|
||||
|
||||
context "" do
|
||||
subject { TruncationExample.new( { :reset_ids => ["something"] } ) }
|
||||
it { subject.reset_ids?.should eq true }
|
||||
it { expect(subject.reset_ids?).to eq true }
|
||||
end
|
||||
|
||||
context "" do
|
||||
subject { TruncationExample.new( { :reset_ids => nil } ) }
|
||||
it { subject.reset_ids?.should eq false }
|
||||
it { expect(subject.reset_ids?).to eq false }
|
||||
end
|
||||
|
||||
context "" do
|
||||
subject { TruncationExample.new( { :pre_count => ["something"] } ) }
|
||||
it { subject.pre_count?.should eq true }
|
||||
it { expect(subject.pre_count?).to eq true }
|
||||
end
|
||||
|
||||
context "" do
|
||||
subject { TruncationExample.new( { :pre_count => nil } ) }
|
||||
it { subject.pre_count?.should eq false }
|
||||
it { expect(subject.pre_count?).to eq false }
|
||||
end
|
||||
|
||||
context "" do
|
||||
subject { MigrationExample.new }
|
||||
it { subject.only.should eq nil }
|
||||
it { subject.except.should eq %w[migration_storage_name] }
|
||||
it { expect(subject.only).to eq nil }
|
||||
it { expect(subject.except).to eq %w[migration_storage_name] }
|
||||
end
|
||||
|
||||
context "" do
|
||||
|
@ -107,8 +107,8 @@ module ::DatabaseCleaner
|
|||
subject { MigrationExample.new( { :except => EXCEPT_TABLES } ) }
|
||||
|
||||
it "should not modify the array of excepted tables" do
|
||||
subject.except.should include("migration_storage_name")
|
||||
EXCEPT_TABLES.should_not include("migration_storage_name")
|
||||
expect(subject.except).to include("migration_storage_name")
|
||||
expect(EXCEPT_TABLES).not_to include("migration_storage_name")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,7 +25,7 @@ module DatabaseCleaner
|
|||
# very odd and disconcerting...
|
||||
expected_counts.each do |model_class, expected_count|
|
||||
actual_count = model_class.count
|
||||
actual_count.should eq(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{actual_count}"
|
||||
expect(actual_count).to eq(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{actual_count}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'database_cleaner/shared_strategy'
|
|||
|
||||
module DatabaseCleaner
|
||||
describe MongoMapper do
|
||||
it { should respond_to(:available_strategies) }
|
||||
it { is_expected.to respond_to(:available_strategies) }
|
||||
end
|
||||
|
||||
module MongoMapper
|
||||
|
@ -17,15 +17,15 @@ module DatabaseCleaner
|
|||
it_should_behave_like "a generic strategy"
|
||||
|
||||
describe "db" do
|
||||
it { should respond_to(:db=) }
|
||||
it { is_expected.to respond_to(:db=) }
|
||||
|
||||
it "should store my desired db" do
|
||||
subject.db = :my_db
|
||||
subject.db.should eq :my_db
|
||||
expect(subject.db).to eq :my_db
|
||||
end
|
||||
|
||||
it "should default to :default" do
|
||||
subject.db.should eq :default
|
||||
expect(subject.db).to eq :default
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ module DatabaseCleaner
|
|||
begin
|
||||
expected_counts.each do |model_class, expected_count|
|
||||
actual_count = model_class.count
|
||||
actual_count.should eq(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{actual_count}"
|
||||
expect(actual_count).to eq(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{actual_count}"
|
||||
end
|
||||
rescue RSpec::Expectations::ExpectationNotMetError => e
|
||||
raise !sanity_check ? e : RSpec::ExpectationNotMetError::ExpectationNotMetError.new("SANITY CHECK FAILURE! This should never happen here: #{e.message}")
|
||||
|
|
|
@ -29,7 +29,7 @@ module DatabaseCleaner
|
|||
# very odd and disconcerting...
|
||||
expected_counts.each do |model_class, expected_count|
|
||||
actual_count = model_class.count
|
||||
actual_count.should eq(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{actual_count}"
|
||||
expect(actual_count).to eq(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{actual_count}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'database_cleaner/shared_strategy'
|
|||
|
||||
module DatabaseCleaner
|
||||
describe Neo4j do
|
||||
it { should respond_to(:available_strategies) }
|
||||
it { is_expected.to respond_to(:available_strategies) }
|
||||
end
|
||||
|
||||
module Neo4j
|
||||
|
@ -15,28 +15,28 @@ module DatabaseCleaner
|
|||
describe ExampleStrategy do
|
||||
|
||||
it_should_behave_like "a generic strategy"
|
||||
it { should respond_to(:db) }
|
||||
it { should respond_to(:db=) }
|
||||
it { is_expected.to respond_to(:db) }
|
||||
it { is_expected.to respond_to(:db=) }
|
||||
|
||||
it "should store my describe db" do
|
||||
db_conf = {:connection => {:type => :server_db, :path => 'http://localhost:7474'}}
|
||||
subject.db = db_conf
|
||||
subject.db.should eq db_conf
|
||||
expect(subject.db).to eq db_conf
|
||||
end
|
||||
|
||||
it "should respect additional connection parameters" do
|
||||
db_conf = {:type => :server_db, :path => 'http://localhost:7474', basic_auth: {username: 'user', password: 'pass'}}
|
||||
subject.db = db_conf
|
||||
stub_const("Neo4j::Session", double()).should_receive(:open).with(:server_db, 'http://localhost:7474', {basic_auth: {username: 'user', password: 'pass'}}) { true }
|
||||
expect(stub_const("Neo4j::Session", double())).to receive(:open).with(:server_db, 'http://localhost:7474', {basic_auth: {username: 'user', password: 'pass'}}) { true }
|
||||
subject.start
|
||||
end
|
||||
|
||||
it "should default to nil" do
|
||||
subject.db.should be_nil
|
||||
expect(subject.db).to be_nil
|
||||
end
|
||||
|
||||
it "should return default configuration" do
|
||||
subject.database.should eq(:type => :server_db, :path => 'http://localhost:7475/')
|
||||
expect(subject.database).to eq(:type => :server_db, :path => 'http://localhost:7475/')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,11 +3,11 @@ require 'spec_helper'
|
|||
module DatabaseCleaner
|
||||
describe NullStrategy do
|
||||
it 'responds to .start' do
|
||||
expect { NullStrategy.start }.not_to raise_error(NoMethodError)
|
||||
expect { NullStrategy.start }.not_to raise_error
|
||||
end
|
||||
|
||||
it 'responds to .clean' do
|
||||
expect { NullStrategy.clean }.not_to raise_error(NoMethodError)
|
||||
expect { NullStrategy.clean }.not_to raise_error
|
||||
end
|
||||
|
||||
describe '.cleaning' do
|
||||
|
|
|
@ -39,19 +39,19 @@ module DatabaseCleaner
|
|||
it "truncates all keys by default" do
|
||||
create_widget
|
||||
create_gadget
|
||||
@redis.keys.size.should eq 6
|
||||
expect(@redis.keys.size).to eq 6
|
||||
Truncation.new.clean
|
||||
@redis.keys.size.should eq 0
|
||||
expect(@redis.keys.size).to eq 0
|
||||
end
|
||||
|
||||
context "when keys are provided to the :only option" do
|
||||
it "only truncates the specified keys" do
|
||||
create_widget
|
||||
create_gadget
|
||||
@redis.keys.size.should eq 6
|
||||
expect(@redis.keys.size).to eq 6
|
||||
Truncation.new(:only => ['*Widget*']).clean
|
||||
@redis.keys.size.should eq 3
|
||||
@redis.get('DatabaseCleaner::Ohm::Gadget:id').should eq '1'
|
||||
expect(@redis.keys.size).to eq 3
|
||||
expect(@redis.get('DatabaseCleaner::Ohm::Gadget:id')).to eq '1'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -59,10 +59,10 @@ module DatabaseCleaner
|
|||
it "truncates all but the specified keys" do
|
||||
create_widget
|
||||
create_gadget
|
||||
@redis.keys.size.should eq 6
|
||||
expect(@redis.keys.size).to eq 6
|
||||
Truncation.new(:except => ['*Widget*']).clean
|
||||
@redis.keys.size.should eq 3
|
||||
@redis.get('DatabaseCleaner::Ohm::Widget:id').should eq '1'
|
||||
expect(@redis.keys.size).to eq 3
|
||||
expect(@redis.get('DatabaseCleaner::Ohm::Widget:id')).to eq '1'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ require 'database_cleaner/shared_strategy'
|
|||
|
||||
module DatabaseCleaner
|
||||
describe Redis do
|
||||
it { should respond_to(:available_strategies) }
|
||||
it { is_expected.to respond_to(:available_strategies) }
|
||||
end
|
||||
|
||||
module Redis
|
||||
|
@ -16,14 +16,14 @@ module DatabaseCleaner
|
|||
describe ExampleStrategy do
|
||||
|
||||
it_should_behave_like "a generic strategy"
|
||||
it { should respond_to(:db) }
|
||||
it { should respond_to(:db=) }
|
||||
it { is_expected.to respond_to(:db) }
|
||||
it { is_expected.to respond_to(:db=) }
|
||||
|
||||
context "when passing url" do
|
||||
it "should store my describe db" do
|
||||
url = 'redis://localhost:6379/2'
|
||||
subject.db = 'redis://localhost:6379/2'
|
||||
subject.db.should eq url
|
||||
expect(subject.db).to eq url
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -31,12 +31,12 @@ module DatabaseCleaner
|
|||
it "should store my describe db" do
|
||||
connection = ::Redis.new :url => 'redis://localhost:6379/2'
|
||||
subject.db = connection
|
||||
subject.db.should eq connection
|
||||
expect(subject.db).to eq connection
|
||||
end
|
||||
end
|
||||
|
||||
it "should default to :default" do
|
||||
subject.db.should eq :default
|
||||
expect(subject.db).to eq :default
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,19 +31,19 @@ module DatabaseCleaner
|
|||
it "truncates all keys by default" do
|
||||
create_widget
|
||||
create_gadget
|
||||
@redis.keys.size.should eq 2
|
||||
expect(@redis.keys.size).to eq 2
|
||||
Truncation.new.clean
|
||||
@redis.keys.size.should eq 0
|
||||
expect(@redis.keys.size).to eq 0
|
||||
end
|
||||
|
||||
context "when keys are provided to the :only option" do
|
||||
it "only truncates the specified keys" do
|
||||
create_widget
|
||||
create_gadget
|
||||
@redis.keys.size.should eq 2
|
||||
expect(@redis.keys.size).to eq 2
|
||||
Truncation.new(:only => ['Widge*']).clean
|
||||
@redis.keys.size.should eq 1
|
||||
@redis.get('Gadget').should eq '1'
|
||||
expect(@redis.keys.size).to eq 1
|
||||
expect(@redis.get('Gadget')).to eq '1'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -51,10 +51,10 @@ module DatabaseCleaner
|
|||
it "truncates all but the specified keys" do
|
||||
create_widget
|
||||
create_gadget
|
||||
@redis.keys.size.should eq 2
|
||||
expect(@redis.keys.size).to eq 2
|
||||
Truncation.new(:except => ['Widg*']).clean
|
||||
@redis.keys.size.should eq 1
|
||||
@redis.get('Widget').should eq '1'
|
||||
expect(@redis.keys.size).to eq 1
|
||||
expect(@redis.get('Widget')).to eq '1'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ require 'sequel'
|
|||
|
||||
module DatabaseCleaner
|
||||
describe Sequel do
|
||||
it { should respond_to(:available_strategies) }
|
||||
it { is_expected.to respond_to(:available_strategies) }
|
||||
end
|
||||
|
||||
module Sequel
|
||||
|
@ -15,16 +15,16 @@ module DatabaseCleaner
|
|||
|
||||
describe ExampleStrategy do
|
||||
it_should_behave_like "a generic strategy"
|
||||
it { should respond_to(:db) }
|
||||
it { should respond_to(:db=) }
|
||||
it { is_expected.to respond_to(:db) }
|
||||
it { is_expected.to respond_to(:db=) }
|
||||
|
||||
it "should store my desired db" do
|
||||
subject.db = :my_db
|
||||
subject.db.should eq :my_db
|
||||
expect(subject.db).to eq :my_db
|
||||
end
|
||||
|
||||
it "should default to :default" do
|
||||
subject.db.should eq :default
|
||||
expect(subject.db).to eq :default
|
||||
end
|
||||
|
||||
pending "I figure out how to use Sequel and write some real tests for it..."
|
||||
|
|
|
@ -134,17 +134,17 @@ module DatabaseCleaner
|
|||
subject { Truncation.new.tap { |t| t.db = db } }
|
||||
|
||||
it 'should return false initially' do
|
||||
subject.send(:pre_count?).should eq false
|
||||
expect(subject.send(:pre_count?)).to eq false
|
||||
end
|
||||
|
||||
it 'should return true if @reset_id is set and non false or nil' do
|
||||
subject.instance_variable_set(:"@pre_count", true)
|
||||
subject.send(:pre_count?).should eq true
|
||||
expect(subject.send(:pre_count?)).to eq true
|
||||
end
|
||||
|
||||
it 'should return false if @reset_id is set to false' do
|
||||
subject.instance_variable_set(:"@pre_count", false)
|
||||
subject.send(:pre_count?).should eq false
|
||||
expect(subject.send(:pre_count?)).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -154,8 +154,8 @@ module DatabaseCleaner
|
|||
it "should rely on #pre_count_truncate_tables if #pre_count? returns true" do
|
||||
subject.instance_variable_set(:"@pre_count", true)
|
||||
|
||||
subject.should_not_receive(:truncate_tables)
|
||||
subject.should_receive(:pre_count_truncate_tables)
|
||||
expect(subject).not_to receive(:truncate_tables)
|
||||
expect(subject).to receive(:pre_count_truncate_tables)
|
||||
|
||||
subject.clean
|
||||
end
|
||||
|
@ -163,8 +163,8 @@ module DatabaseCleaner
|
|||
it "should not rely on #pre_count_truncate_tables if #pre_count? return false" do
|
||||
subject.instance_variable_set(:"@pre_count", false)
|
||||
|
||||
subject.should_not_receive(:pre_count_truncate_tables)
|
||||
subject.should_receive(:truncate_tables)
|
||||
expect(subject).not_to receive(:pre_count_truncate_tables)
|
||||
expect(subject).to receive(:truncate_tables)
|
||||
|
||||
subject.clean
|
||||
end
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
shared_examples_for "a generic strategy" do
|
||||
it { should respond_to(:db) }
|
||||
it { is_expected.to respond_to(:db) }
|
||||
end
|
||||
|
||||
shared_examples_for "a generic truncation strategy" do
|
||||
it { should respond_to(:start) }
|
||||
it { should respond_to(:clean) }
|
||||
it { should respond_to(:cleaning) }
|
||||
it { is_expected.to respond_to(:start) }
|
||||
it { is_expected.to respond_to(:clean) }
|
||||
it { is_expected.to respond_to(:cleaning) }
|
||||
end
|
||||
|
||||
shared_examples_for "a generic transaction strategy" do
|
||||
it { should respond_to(:start) }
|
||||
it { should respond_to(:clean) }
|
||||
it { should respond_to(:cleaning) }
|
||||
it { is_expected.to respond_to(:start) }
|
||||
it { is_expected.to respond_to(:clean) }
|
||||
it { is_expected.to respond_to(:cleaning) }
|
||||
end
|
||||
|
|
|
@ -21,14 +21,6 @@ RSpec.configure do |config|
|
|||
# get run.
|
||||
config.filter_run :focus
|
||||
config.run_all_when_everything_filtered = true
|
||||
|
||||
config.expect_with :rspec do |expectations|
|
||||
expectations.syntax = [:should, :expect]
|
||||
end
|
||||
|
||||
config.mock_with :rspec do |mocks|
|
||||
mocks.syntax = [:should, :expect]
|
||||
end
|
||||
end
|
||||
|
||||
alias running lambda
|
||||
|
|
Loading…
Reference in a new issue