update to rspec 3 syntax.

This commit is contained in:
Micah Geisel 2018-04-26 10:57:18 -07:00
parent ae234c4e1a
commit 2fff7ab3f4
28 changed files with 408 additions and 416 deletions

View file

@ -12,15 +12,15 @@ end
module DatabaseCleaner module DatabaseCleaner
describe ActiveRecord do describe ActiveRecord do
it { should respond_to(:available_strategies) } it { is_expected.to respond_to(:available_strategies) }
describe "config_file_location" do describe "config_file_location" do
subject { ActiveRecord.config_file_location } subject { ActiveRecord.config_file_location }
it "should default to DatabaseCleaner.root / config / database.yml" do it "should default to DatabaseCleaner.root / config / database.yml" do
ActiveRecord.config_file_location=nil ActiveRecord.config_file_location=nil
DatabaseCleaner.should_receive(:app_root).and_return("/path/to") expect(DatabaseCleaner).to receive(:app_root).and_return("/path/to")
subject.should eq '/path/to/config/database.yml' expect(subject).to eq '/path/to/config/database.yml'
end end
end end
@ -36,25 +36,25 @@ module DatabaseCleaner
'/path/to/config/database.yml' '/path/to/config/database.yml'
end 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" it_should_behave_like "a generic strategy"
describe "db" do describe "db" do
it "should store my desired 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 = :my_db
subject.db.should eq :my_db expect(subject.db).to eq :my_db
end end
it "should default to :default" do it "should default to :default" do
subject.db.should eq :default expect(subject.db).to eq :default
end end
it "should load_config when I set db" do it "should load_config when I set db" do
subject.should_receive(:load_config) expect(subject).to receive(:load_config)
subject.db = :my_db subject.db = :my_db
end end
end end
@ -67,12 +67,12 @@ module DatabaseCleaner
my_db: my_db:
database: <%= "ONE".downcase %> database: <%= "ONE".downcase %>
Y Y
File.stub(:file?).with(config_location).and_return(true) allow(File).to receive(:file?).with(config_location).and_return(true)
IO.stub(:read).with(config_location).and_return(yaml) allow(IO).to receive(:read).with(config_location).and_return(yaml)
end end
it "should parse the config" do 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 subject.load_config
end end
@ -81,62 +81,62 @@ my_db:
my_db: my_db:
database: one database: one
Y 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 subject.load_config
end end
context 'use ActiveRecord::Base.configuration' do context 'use ActiveRecord::Base.configuration' do
it 'when config file different with it' 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.load_config
subject.connection_hash.should eq({ "database" => "two"}) expect(subject.connection_hash).to eq({ "database" => "two"})
end end
end end
context 'use config file' do context 'use config file' do
it 'when config file same with it' 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.load_config
subject.connection_hash.should eq({ "database" => "one"}) expect(subject.connection_hash).to eq({ "database" => "one"})
end end
it 'when ::ActiveRecord::Base.configurations nil' do 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.load_config
subject.connection_hash.should eq({ "database" => "one"}) expect(subject.connection_hash).to eq({ "database" => "one"})
end end
it 'when ::ActiveRecord::Base.configurations empty' do 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.load_config
subject.connection_hash.should eq({ "database" => "one"}) expect(subject.connection_hash).to eq({ "database" => "one"})
end end
end end
it "should store the relevant config in connection_hash" do it "should store the relevant config in connection_hash" do
subject.load_config subject.load_config
subject.connection_hash.should eq( "database" => "one" ) expect(subject.connection_hash).to eq( "database" => "one" )
end end
it "should skip config if config file is not available" do 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.load_config
subject.connection_hash.should_not be expect(subject.connection_hash).not_to be
end end
it "skips the file when the model is set" do it "skips the file when the model is set" do
subject.db = FakeModel subject.db = FakeModel
YAML.should_not_receive(:load) expect(YAML).not_to receive(:load)
subject.load_config subject.load_config
subject.connection_hash.should_not be expect(subject.connection_hash).not_to be
end end
it "skips the file when the db is set to :default" do it "skips the file when the db is set to :default" do
# to avoid https://github.com/bmabey/database_cleaner/issues/72 # to avoid https://github.com/bmabey/database_cleaner/issues/72
subject.db = :default subject.db = :default
YAML.should_not_receive(:load) expect(YAML).not_to receive(:load)
subject.load_config subject.load_config
subject.connection_hash.should_not be expect(subject.connection_hash).not_to be
end end
end end
@ -144,14 +144,14 @@ my_db:
describe "connection_hash" do describe "connection_hash" do
it "should store connection_hash" do it "should store connection_hash" do
subject.connection_hash = { :key => "value" } subject.connection_hash = { :key => "value" }
subject.connection_hash.should eq( :key => "value" ) expect(subject.connection_hash).to eq( :key => "value" )
end end
end end
describe "connection_class" do describe "connection_class" do
it { expect { subject.connection_class }.to_not raise_error } it { expect { subject.connection_class }.to_not raise_error }
it "should default to ActiveRecord::Base" do it "should default to ActiveRecord::Base" do
subject.connection_class.should eq ::ActiveRecord::Base expect(subject.connection_class).to eq ::ActiveRecord::Base
end end
context "with database models" do context "with database models" do
@ -160,24 +160,24 @@ my_db:
subject.db = FakeModel subject.db = FakeModel
subject.connection_hash = { } subject.connection_hash = { }
subject.load_config subject.load_config
subject.connection_class.should eq FakeModel expect(subject.connection_class).to eq FakeModel
end end
end end
context "connection_hash is not set" do context "connection_hash is not set" do
it "allows for database models to be passed in" do it "allows for database models to be passed in" do
subject.db = FakeModel subject.db = FakeModel
subject.connection_class.should eq FakeModel expect(subject.connection_class).to eq FakeModel
end end
end end
end end
context "when connection_hash is set" do context "when connection_hash is set" do
let(:hash) { {} } 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 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 expect(subject.connection_class).to eq ::ActiveRecord::Base
end end

View file

@ -10,33 +10,33 @@ module DatabaseCleaner
let (:connection_2) { double("connection") } let (:connection_2) { double("connection") }
let (:connection_pool) { double("connection_pool")} let (:connection_pool) { double("connection_pool")}
before(:each) do before(:each) do
::ActiveRecord::Base.stub(:connection_pool).and_return(connection_pool) allow(::ActiveRecord::Base).to receive(:connection_pool).and_return(connection_pool)
connection_pool.stub(:connections).and_return([connection]) allow(connection_pool).to receive(:connections).and_return([connection])
::ActiveRecord::Base.stub(:connection).and_return(connection) allow(::ActiveRecord::Base).to receive(:connection).and_return(connection)
end end
describe "#start" do describe "#start" do
[:begin_transaction, :begin_db_transaction].each do |begin_transaction_method| [:begin_transaction, :begin_db_transaction].each do |begin_transaction_method|
context "using #{begin_transaction_method}" do context "using #{begin_transaction_method}" do
before do before do
connection.stub(:transaction) allow(connection).to receive(:transaction)
connection.stub(begin_transaction_method) allow(connection).to receive(begin_transaction_method)
end end
it "should increment open transactions if possible" do it "should increment open transactions if possible" do
connection.should_receive(:increment_open_transactions) expect(connection).to receive(:increment_open_transactions)
Transaction.new.start Transaction.new.start
end end
it "should tell ActiveRecord to increment connection if its not possible to increment current connection" do 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 Transaction.new.start
end end
it "should start a transaction" do it "should start a transaction" do
connection.stub(:increment_open_transactions) allow(connection).to receive(:increment_open_transactions)
connection.should_receive(begin_transaction_method) expect(connection).to receive(begin_transaction_method)
connection.should_receive(:transaction) expect(connection).to receive(:transaction)
Transaction.new.start Transaction.new.start
end end
end end
@ -46,59 +46,59 @@ module DatabaseCleaner
describe "#clean" do describe "#clean" do
context "manual accounting of transaction count" do context "manual accounting of transaction count" do
it "should start a transaction" 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 Transaction.new.clean
end end
it "should decrement open transactions if possible" do 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 Transaction.new.clean
end end
it "should not try to decrement or rollback if open_transactions is 0 for whatever reason" do 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 Transaction.new.clean
end end
it "should decrement connection via ActiveRecord::Base if connection won't" do it "should decrement connection via ActiveRecord::Base if connection won't" 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)
::ActiveRecord::Base.should_receive(:decrement_open_transactions) expect(::ActiveRecord::Base).to receive(:decrement_open_transactions)
Transaction.new.clean Transaction.new.clean
end end
it "should rollback open transactions in all connections" do 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) expect(connection).to receive(:open_transactions).and_return(1)
connection.stub(:rollback_db_transaction) allow(connection).to receive(:rollback_db_transaction)
connection_2.should_receive(:open_transactions).and_return(1) expect(connection_2).to receive(:open_transactions).and_return(1)
connection_2.stub(:rollback_db_transaction) 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 Transaction.new.clean
end end
it "should rollback open transactions in all connections with an open transaction" do 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) expect(connection).to receive(:open_transactions).and_return(1)
connection.stub(:rollback_db_transaction) 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 Transaction.new.clean
end end
end end
@ -107,33 +107,33 @@ module DatabaseCleaner
before {stub_const("ActiveRecord::VERSION::MAJOR", 4) } before {stub_const("ActiveRecord::VERSION::MAJOR", 4) }
it "should start a transaction" do it "should start a transaction" do
connection.stub(:rollback_db_transaction) allow(connection).to receive(:rollback_db_transaction)
connection.should_receive(:open_transactions).and_return(1) expect(connection).to receive(:open_transactions).and_return(1)
connection.should_not_receive(:decrement_open_transactions) expect(connection).not_to receive(:decrement_open_transactions)
connection.should_receive(:rollback_transaction) expect(connection).to receive(:rollback_transaction)
Transaction.new.clean Transaction.new.clean
end end
it "should decrement open transactions if possible" do it "should decrement open transactions if possible" do
connection.stub(:rollback_transaction) allow(connection).to receive(:rollback_transaction)
connection.should_receive(:open_transactions).and_return(1) 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 Transaction.new.clean
end end
it "should not try to decrement or rollback if open_transactions is 0 for whatever reason" do 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 Transaction.new.clean
end end
it "should decrement connection via ActiveRecord::Base if connection won't" do it "should decrement connection via ActiveRecord::Base if connection won't" do
connection.should_receive(:open_transactions).and_return(1) expect(connection).to receive(:open_transactions).and_return(1)
connection.stub(:rollback_transaction) 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 Transaction.new.clean
end end
end end
@ -142,11 +142,11 @@ module DatabaseCleaner
describe "#connection_maintains_transaction_count?" do describe "#connection_maintains_transaction_count?" do
it "should return true if the major active record version is < 4" do it "should return true if the major active record version is < 4" do
stub_const("ActiveRecord::VERSION::MAJOR", 3) 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 end
it "should return false if the major active record version is > 3" do it "should return false if the major active record version is > 3" do
stub_const("ActiveRecord::VERSION::MAJOR", 4) 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
end end

View file

@ -16,7 +16,7 @@ module ActiveRecord
2.times { User.create } 2.times { User.create }
connection.truncate_table('users') connection.truncate_table('users')
User.count.should eq 0 expect(User.count).to eq 0
end end
it "should reset AUTO_INCREMENT index of table" do it "should reset AUTO_INCREMENT index of table" do
@ -25,7 +25,7 @@ module ActiveRecord
connection.truncate_table('users') connection.truncate_table('users')
User.create.id.should eq 1 expect(User.create.id).to eq 1
end end
end end

View file

@ -16,7 +16,7 @@ module ActiveRecord
2.times { User.create } 2.times { User.create }
connection.truncate_table('users') connection.truncate_table('users')
User.count.should eq 0 expect(User.count).to eq 0
end end
it "should reset AUTO_INCREMENT index of table" do it "should reset AUTO_INCREMENT index of table" do
@ -25,7 +25,7 @@ module ActiveRecord
connection.truncate_table('users') connection.truncate_table('users')
User.create.id.should eq 1 expect(User.create.id).to eq 1
end end
end end

View file

@ -11,7 +11,7 @@ module ActiveRecord
PostgreSQLHelper.active_record_pg_migrate PostgreSQLHelper.active_record_pg_migrate
DatabaseCleaner::ActiveRecord::Truncation.new.clean DatabaseCleaner::ActiveRecord::Truncation.new.clean
result = PostgreSQLHelper.active_record_pg_connection.execute("select count(*) from schema_migrations;") 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
end end
@ -31,14 +31,14 @@ module ActiveRecord
2.times { User.create } 2.times { User.create }
connection.truncate_table('users') connection.truncate_table('users')
User.count.should eq 0 expect(User.count).to eq 0
end end
it "truncates the table without id sequence" do it "truncates the table without id sequence" do
2.times { Agent.create } 2.times { Agent.create }
connection.truncate_table('agents') connection.truncate_table('agents')
Agent.count.should eq 0 expect(Agent.count).to eq 0
end end
it "resets AUTO_INCREMENT index of table" do it "resets AUTO_INCREMENT index of table" do
@ -47,7 +47,7 @@ module ActiveRecord
connection.truncate_table('users') connection.truncate_table('users')
User.create.id.should eq 1 expect(User.create.id).to eq 1
end end
end end
@ -62,7 +62,7 @@ module ActiveRecord
describe '#database_cleaner_table_cache' do describe '#database_cleaner_table_cache' do
it 'should default to the list of tables with their schema' 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
end end

View file

@ -6,7 +6,7 @@ shared_examples_for "an adapter with pre-count truncation" do
2.times { User.create } 2.times { User.create }
connection.pre_count_truncate_tables(%w[users], :reset_ids => true) connection.pre_count_truncate_tables(%w[users], :reset_ids => true)
User.count.should be_zero expect(User.count).to be_zero
end end
it "resets AUTO_INCREMENT index of table" do 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 User.delete_all
connection.pre_count_truncate_tables(%w[users]) # true is also the default 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
end end
@ -24,7 +24,7 @@ shared_examples_for "an adapter with pre-count truncation" do
2.times { User.create } 2.times { User.create }
connection.pre_count_truncate_tables(%w[users], :reset_ids => false) connection.pre_count_truncate_tables(%w[users], :reset_ids => false)
User.count.should be_zero expect(User.count).to be_zero
end end
it "does not reset AUTO_INCREMENT index of table" do 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) 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 end
end end

View file

@ -21,7 +21,7 @@ module ActiveRecord
2.times { User.create } 2.times { User.create }
connection.truncate_table('users') connection.truncate_table('users')
User.count.should eq 0 expect(User.count).to eq 0
end end
it "resets AUTO_INCREMENT index of table" do it "resets AUTO_INCREMENT index of table" do
@ -30,7 +30,7 @@ module ActiveRecord
connection.truncate_table('users') connection.truncate_table('users')
User.create.id.should eq 1 expect(User.create.id).to eq 1
end end
end end

View file

@ -13,7 +13,7 @@ module ActiveRecord
[ MysqlAdapter, Mysql2Adapter, SQLite3Adapter, PostgreSQLAdapter ].each do |adapter| [ MysqlAdapter, Mysql2Adapter, SQLite3Adapter, PostgreSQLAdapter ].each do |adapter|
describe adapter, "#truncate_table" do describe adapter, "#truncate_table" do
it "responds" do it "responds" do
adapter.instance_methods.should include(:truncate_table) expect(adapter.instance_methods).to include(:truncate_table)
end end
end end
end end
@ -27,60 +27,60 @@ module DatabaseCleaner
let(:connection) { double('connection') } let(:connection) { double('connection') }
before(:each) do before(:each) do
connection.stub(:disable_referential_integrity).and_yield allow(connection).to receive(:disable_referential_integrity).and_yield
connection.stub(:database_cleaner_view_cache).and_return([]) allow(connection).to receive(:database_cleaner_view_cache).and_return([])
::ActiveRecord::Base.stub(:connection).and_return(connection) allow(::ActiveRecord::Base).to receive(:connection).and_return(connection)
end end
describe '#clean' do describe '#clean' do
it "should truncate all tables except for schema_migrations" 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 Truncation.new.clean
end end
it "should use ActiveRecord's SchemaMigration.table_name" do it "should use ActiveRecord's SchemaMigration.table_name" do
connection.stub(:database_cleaner_table_cache).and_return(%w[pre_schema_migrations_suf widgets dogs]) allow(connection).to receive(:database_cleaner_table_cache).and_return(%w[pre_schema_migrations_suf widgets dogs])
::ActiveRecord::Base.stub(:table_name_prefix).and_return('pre_') allow(::ActiveRecord::Base).to receive(:table_name_prefix).and_return('pre_')
::ActiveRecord::Base.stub(:table_name_suffix).and_return('_suf') 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 Truncation.new.clean
end end
it "should only truncate the tables specified in the :only option when provided" do 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 Truncation.new(:only => ['widgets']).clean
end end
it "should not truncate the tables specified in the :except option" do 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 Truncation.new(:except => ['widgets']).clean
end end
it "should raise an error when :only and :except options are used" do it "should raise an error when :only and :except options are used" do
running { expect(running {
Truncation.new(:except => ['widgets'], :only => ['widgets']) Truncation.new(:except => ['widgets'], :only => ['widgets'])
}.should raise_error(ArgumentError) }).to raise_error(ArgumentError)
end end
it "should raise an error when invalid options are provided" do 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 end
it "should not truncate views" do it "should not truncate views" do
connection.stub(:database_cleaner_table_cache).and_return(%w[widgets dogs]) allow(connection).to receive(:database_cleaner_table_cache).and_return(%w[widgets dogs])
connection.stub(:database_cleaner_view_cache).and_return(["widgets"]) 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 Truncation.new.clean
end end
@ -89,25 +89,25 @@ module DatabaseCleaner
subject { Truncation.new } subject { Truncation.new }
it "should rely on #pre_count_truncate_tables if #pre_count? returns true" do 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]) allow(connection).to receive(:database_cleaner_table_cache).and_return(%w[widgets dogs])
connection.stub(:database_cleaner_view_cache).and_return(["widgets"]) allow(connection).to receive(:database_cleaner_view_cache).and_return(["widgets"])
subject.instance_variable_set(:"@pre_count", true) subject.instance_variable_set(:"@pre_count", true)
connection.should_not_receive(:truncate_tables).with(['dogs']) expect(connection).not_to receive(:truncate_tables).with(['dogs'])
connection.should_receive(:pre_count_truncate_tables).with(['dogs'], :reset_ids => true) expect(connection).to receive(:pre_count_truncate_tables).with(['dogs'], :reset_ids => true)
subject.clean subject.clean
end end
it "should not rely on #pre_count_truncate_tables if #pre_count? return false" do 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]) allow(connection).to receive(:database_cleaner_table_cache).and_return(%w[widgets dogs])
connection.stub(:database_cleaner_view_cache).and_return(["widgets"]) allow(connection).to receive(:database_cleaner_view_cache).and_return(["widgets"])
subject.instance_variable_set(:"@pre_count", false) subject.instance_variable_set(:"@pre_count", false)
connection.should_not_receive(:pre_count_truncate_tables).with(['dogs'], :reset_ids => true) expect(connection).not_to receive(:pre_count_truncate_tables).with(['dogs'], :reset_ids => true)
connection.should_receive(:truncate_tables).with(['dogs']) expect(connection).to receive(:truncate_tables).with(['dogs'])
subject.clean subject.clean
end end
@ -115,20 +115,20 @@ module DatabaseCleaner
context 'when :cache_tables is set to true' do context 'when :cache_tables is set to true' do
it 'caches the list of tables to be truncated' do it 'caches the list of tables to be truncated' do
connection.should_receive(:database_cleaner_table_cache).and_return([]) expect(connection).to receive(:database_cleaner_table_cache).and_return([])
connection.should_not_receive(:tables) expect(connection).not_to receive(:tables)
connection.stub(:truncate_tables) allow(connection).to receive(:truncate_tables)
Truncation.new({ :cache_tables => true }).clean Truncation.new({ :cache_tables => true }).clean
end end
end end
context 'when :cache_tables is set to false' do context 'when :cache_tables is set to false' do
it 'does not cache the list of tables to be truncated' do it 'does not cache the list of tables to be truncated' do
connection.should_not_receive(:database_cleaner_table_cache) expect(connection).not_to receive(:database_cleaner_table_cache)
connection.should_receive(:tables).and_return([]) expect(connection).to receive(:tables).and_return([])
connection.stub(:truncate_tables) allow(connection).to receive(:truncate_tables)
Truncation.new({ :cache_tables => false }).clean Truncation.new({ :cache_tables => false }).clean
end end
end end
@ -136,49 +136,49 @@ module DatabaseCleaner
describe '#pre_count?' do describe '#pre_count?' do
before(:each) do before(:each) do
connection.stub(:disable_referential_integrity).and_yield allow(connection).to receive(:disable_referential_integrity).and_yield
connection.stub(:database_cleaner_view_cache).and_return([]) allow(connection).to receive(:database_cleaner_view_cache).and_return([])
::ActiveRecord::Base.stub(:connection).and_return(connection) allow(::ActiveRecord::Base).to receive(:connection).and_return(connection)
end end
subject { Truncation.new } subject { Truncation.new }
it 'should return false initially' do it 'should return false initially' do
subject.send(:pre_count?).should eq false expect(subject.send(:pre_count?)).to eq false
end end
it 'should return true if @reset_id is set and non false or nil' do it 'should return true if @reset_id is set and non false or nil' do
subject.instance_variable_set(:"@pre_count", true) subject.instance_variable_set(:"@pre_count", true)
subject.send(:pre_count?).should eq true expect(subject.send(:pre_count?)).to eq true
end end
it 'should return false if @reset_id is set to false' do it 'should return false if @reset_id is set to false' do
subject.instance_variable_set(:"@pre_count", false) subject.instance_variable_set(:"@pre_count", false)
subject.send(:pre_count?).should eq false expect(subject.send(:pre_count?)).to eq false
end end
end end
describe '#reset_ids?' do describe '#reset_ids?' do
before(:each) do before(:each) do
connection.stub(:disable_referential_integrity).and_yield allow(connection).to receive(:disable_referential_integrity).and_yield
connection.stub(:database_cleaner_view_cache).and_return([]) allow(connection).to receive(:database_cleaner_view_cache).and_return([])
::ActiveRecord::Base.stub(:connection).and_return(connection) allow(::ActiveRecord::Base).to receive(:connection).and_return(connection)
end end
subject { Truncation.new } subject { Truncation.new }
it 'should return true initially' do it 'should return true initially' do
subject.send(:reset_ids?).should eq true expect(subject.send(:reset_ids?)).to eq true
end end
it 'should return true if @reset_id is set and non falsey' do it 'should return true if @reset_id is set and non falsey' do
subject.instance_variable_set(:"@reset_ids", 'Something') subject.instance_variable_set(:"@reset_ids", 'Something')
subject.send(:reset_ids?).should eq true expect(subject.send(:reset_ids?)).to eq true
end end
it 'should return false if @reset_id is set to false' do it 'should return false if @reset_id is set to false' do
subject.instance_variable_set(:"@reset_ids", false) 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 end
end end

View file

@ -11,7 +11,7 @@ module DatabaseCleaner
let(:mock_strategy) { let(:mock_strategy) {
double("strategy").tap{|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 } let(:cleaner) { DatabaseCleaner::Base.new :autodetect }
it "should raise an error when no ORM is detected" do 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 end
it "should detect ActiveRecord first" do it "should detect ActiveRecord first" do
@ -90,8 +90,8 @@ module DatabaseCleaner
Object.const_set('Redis', 'Redis mock') Object.const_set('Redis', 'Redis mock')
Object.const_set('Neo4j', 'Neo4j mock') Object.const_set('Neo4j', 'Neo4j mock')
cleaner.orm.should eq :active_record expect(cleaner.orm).to eq :active_record
cleaner.should be_auto_detected expect(cleaner).to be_auto_detected
end end
it "should detect DataMapper second" do it "should detect DataMapper second" do
@ -105,8 +105,8 @@ module DatabaseCleaner
Object.const_set('Redis', 'Redis mock') Object.const_set('Redis', 'Redis mock')
Object.const_set('Neo4j', 'Neo4j mock') Object.const_set('Neo4j', 'Neo4j mock')
cleaner.orm.should eq :data_mapper expect(cleaner.orm).to eq :data_mapper
cleaner.should be_auto_detected expect(cleaner).to be_auto_detected
end end
it "should detect MongoMapper third" do it "should detect MongoMapper third" do
@ -119,8 +119,8 @@ module DatabaseCleaner
Object.const_set('Redis', 'Redis mock') Object.const_set('Redis', 'Redis mock')
Object.const_set('Neo4j', 'Neo4j mock') Object.const_set('Neo4j', 'Neo4j mock')
cleaner.orm.should eq :mongo_mapper expect(cleaner.orm).to eq :mongo_mapper
cleaner.should be_auto_detected expect(cleaner).to be_auto_detected
end end
it "should detect Mongoid fourth" do it "should detect Mongoid fourth" do
@ -132,8 +132,8 @@ module DatabaseCleaner
Object.const_set('Redis', 'Redis mock') Object.const_set('Redis', 'Redis mock')
Object.const_set('Neo4j', 'Neo4j mock') Object.const_set('Neo4j', 'Neo4j mock')
cleaner.orm.should eq :mongoid expect(cleaner.orm).to eq :mongoid
cleaner.should be_auto_detected expect(cleaner).to be_auto_detected
end end
it "should detect CouchPotato fifth" do it "should detect CouchPotato fifth" do
@ -144,8 +144,8 @@ module DatabaseCleaner
Object.const_set('Redis', 'Redis mock') Object.const_set('Redis', 'Redis mock')
Object.const_set('Neo4j', 'Neo4j mock') Object.const_set('Neo4j', 'Neo4j mock')
cleaner.orm.should eq :couch_potato expect(cleaner.orm).to eq :couch_potato
cleaner.should be_auto_detected expect(cleaner).to be_auto_detected
end end
it "should detect Sequel sixth" do it "should detect Sequel sixth" do
@ -155,15 +155,15 @@ module DatabaseCleaner
Object.const_set('Redis', 'Redis mock') Object.const_set('Redis', 'Redis mock')
Object.const_set('Neo4j', 'Neo4j mock') Object.const_set('Neo4j', 'Neo4j mock')
cleaner.orm.should eq :sequel expect(cleaner.orm).to eq :sequel
cleaner.should be_auto_detected expect(cleaner).to be_auto_detected
end end
it 'detects Moped seventh' do it 'detects Moped seventh' do
Object.const_set('Moped', 'Moped mock') Object.const_set('Moped', 'Moped mock')
cleaner.orm.should eq :moped expect(cleaner.orm).to eq :moped
cleaner.should be_auto_detected expect(cleaner).to be_auto_detected
end end
it 'detects Ohm eighth' do it 'detects Ohm eighth' do
@ -171,23 +171,23 @@ module DatabaseCleaner
Object.const_set('Redis', 'Redis mock') Object.const_set('Redis', 'Redis mock')
Object.const_set('Neo4j', 'Neo4j mock') Object.const_set('Neo4j', 'Neo4j mock')
cleaner.orm.should eq :ohm expect(cleaner.orm).to eq :ohm
cleaner.should be_auto_detected expect(cleaner).to be_auto_detected
end end
it 'detects Redis ninth' do it 'detects Redis ninth' do
Object.const_set('Redis', 'Redis mock') Object.const_set('Redis', 'Redis mock')
Object.const_set('Neo4j', 'Neo4j mock') Object.const_set('Neo4j', 'Neo4j mock')
cleaner.orm.should eq :redis expect(cleaner.orm).to eq :redis
cleaner.should be_auto_detected expect(cleaner).to be_auto_detected
end end
it 'detects Neo4j tenth' do it 'detects Neo4j tenth' do
Object.const_set('Neo4j', 'Neo4j mock') Object.const_set('Neo4j', 'Neo4j mock')
cleaner.orm.should eq :neo4j expect(cleaner.orm).to eq :neo4j
cleaner.should be_auto_detected expect(cleaner).to be_auto_detected
end end
end end
@ -197,11 +197,11 @@ module DatabaseCleaner
mockule = double("module") mockule = double("module")
cleaner = ::DatabaseCleaner::Base.new 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
end end
@ -213,8 +213,8 @@ module DatabaseCleaner
two = DatabaseCleaner::Base.new(:active_record,:connection => :default) two = DatabaseCleaner::Base.new(:active_record,:connection => :default)
two.strategy = mock_strategy two.strategy = mock_strategy
one.should eq two expect(one).to eq two
two.should eq one expect(two).to eq one
end end
it "should not be equal if orm are not the same" do 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 = DatabaseCleaner::Base.new(:active_record, :connection => :default)
two.strategy = mock_strategy two.strategy = mock_strategy
one.should_not eq two expect(one).not_to eq two
two.should_not eq one expect(two).not_to eq one
end end
it "should not be equal if connection are not the same" do 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 = DatabaseCleaner::Base.new(:active_record, :connection => :other)
two.strategy = :truncation two.strategy = :truncation
one.should_not eq two expect(one).not_to eq two
two.should_not eq one expect(two).not_to eq one
end end
end end
@ -246,50 +246,50 @@ module DatabaseCleaner
subject { ::DatabaseCleaner::Base.new(:active_record,:connection => :my_db) } subject { ::DatabaseCleaner::Base.new(:active_record,:connection => :my_db) }
it "should store db from :connection in params hash" do 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
end end
describe "orm" do describe "orm" do
it "should store orm" do it "should store orm" do
cleaner = ::DatabaseCleaner::Base.new :a_orm cleaner = ::DatabaseCleaner::Base.new :a_orm
cleaner.orm.should eq :a_orm expect(cleaner.orm).to eq :a_orm
end end
it "converts string to symbols" do it "converts string to symbols" do
cleaner = ::DatabaseCleaner::Base.new "mongoid" cleaner = ::DatabaseCleaner::Base.new "mongoid"
cleaner.orm.should eq :mongoid expect(cleaner.orm).to eq :mongoid
end end
it "is autodetected if orm is not provided" do it "is autodetected if orm is not provided" do
cleaner = ::DatabaseCleaner::Base.new cleaner = ::DatabaseCleaner::Base.new
cleaner.should be_auto_detected expect(cleaner).to be_auto_detected
end end
it "is autodetected if you specify :autodetect" do it "is autodetected if you specify :autodetect" do
cleaner = ::DatabaseCleaner::Base.new "autodetect" cleaner = ::DatabaseCleaner::Base.new "autodetect"
cleaner.should be_auto_detected expect(cleaner).to be_auto_detected
end end
it "should default to autodetect upon initalisation" do it "should default to autodetect upon initalisation" do
subject.should be_auto_detected expect(subject).to be_auto_detected
end end
end end
end end
describe "db" do describe "db" do
it "should default to :default" do it "should default to :default" do
subject.db.should eq :default expect(subject.db).to eq :default
end end
it "should return any stored db value" do it "should return any stored db value" do
subject.stub(:strategy_db=) allow(subject).to receive(:strategy_db=)
subject.db = :test_db subject.db = :test_db
subject.db.should eq :test_db expect(subject.db).to eq :test_db
end end
it "should pass db to any specified strategy" do 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 subject.db = :a_new_db
end end
end end
@ -302,13 +302,13 @@ module DatabaseCleaner
end end
it "should check that strategy supports db specification" do it "should check that strategy supports db specification" do
strategy.stub(:db=) allow(strategy).to receive(:db=)
subject.strategy_db = :a_db subject.strategy_db = :a_db
end end
context "when strategy supports db specification" do context "when strategy supports db specification" do
it "should pass db to the strategy" 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 subject.strategy_db = :a_db
end end
end end
@ -316,7 +316,7 @@ module DatabaseCleaner
context "when strategy doesn't supports db specification" do context "when strategy doesn't supports db specification" do
it "should check to see if db is :default" do it "should check to see if db is :default" do
db = double("default") db = double("default")
db.should_receive(:==).with(:default).and_return(true) expect(db).to receive(:==).with(:default).and_return(true)
subject.strategy_db = db subject.strategy_db = db
end end
@ -331,40 +331,40 @@ module DatabaseCleaner
describe "clean_with" do describe "clean_with" do
let (:strategy) { double("strategy",:clean => true) } 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 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" } subject.clean_with :lorum, :dollar, :amet, { :ipsum => "random" }
end end
it "should invoke clean on the created strategy" do it "should invoke clean on the created strategy" do
strategy.should_receive(:clean) expect(strategy).to receive(:clean)
subject.clean_with :strategy subject.clean_with :strategy
end end
it "should return the strategy" do it "should return the strategy" do
subject.clean_with( :strategy ).should eq strategy expect(subject.clean_with( :strategy )).to eq strategy
end end
end end
describe "clean_with!" do describe "clean_with!" do
let (:strategy) { double("strategy",:clean => true) } 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 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" } subject.clean_with! :lorum, :dollar, :amet, { :ipsum => "random" }
end end
it "should invoke clean on the created strategy" do it "should invoke clean on the created strategy" do
strategy.should_receive(:clean) expect(strategy).to receive(:clean)
subject.clean_with! :strategy subject.clean_with! :strategy
end end
it "should return the strategy" do it "should return the strategy" do
subject.clean_with!( :strategy ).should eq strategy expect(subject.clean_with!( :strategy )).to eq strategy
end end
end end
@ -372,31 +372,31 @@ module DatabaseCleaner
let(:strategy_class) { double("strategy_class",:new => double("instance")) } let(:strategy_class) { double("strategy_class",:new => double("instance")) }
before :each do before :each do
subject.stub(:orm_strategy).and_return(strategy_class) allow(subject).to receive(:orm_strategy).and_return(strategy_class)
end end
it "should pass the first argument to orm_strategy" do 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 subject.create_strategy :strategy
end end
it "should pass the remainding argument to orm_strategy.new" do 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"}} subject.create_strategy :strategy, {:params => {:lorum => "ipsum"}}
end end
it "should return the resulting strategy" do 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
end end
describe "strategy=" do describe "strategy=" do
it "should proxy symbolised strategies to create_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 subject.strategy = :symbol
end end
it "should proxy params with symbolised strategies" do 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"} subject.strategy= :symbol, {:param => "one"}
end end
@ -409,14 +409,14 @@ module DatabaseCleaner
end end
it "should attempt to set strategy db" do it "should attempt to set strategy db" do
subject.stub(:db).and_return(:my_db) allow(subject).to receive(:db).and_return(:my_db)
subject.should_receive(:set_strategy_db).with(mock_strategy, :my_db) expect(subject).to receive(:set_strategy_db).with(mock_strategy, :my_db)
subject.strategy = mock_strategy subject.strategy = mock_strategy
end end
it "should return the stored strategy" do it "should return the stored strategy" do
result = subject.strategy = mock_strategy result = subject.strategy = mock_strategy
result.should eq mock_strategy expect(result).to eq mock_strategy
end end
end end
@ -424,20 +424,20 @@ module DatabaseCleaner
subject { ::DatabaseCleaner::Base.new :a_orm } subject { ::DatabaseCleaner::Base.new :a_orm }
it "returns a null strategy when strategy is not set and undetectable" do 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 end
it "returns the set strategy" do it "returns the set strategy" do
subject.strategy = mock_strategy subject.strategy = mock_strategy
subject.strategy.should eq mock_strategy expect(subject.strategy).to eq mock_strategy
end end
end end
describe "orm=" do describe "orm=" do
it "should stored the desired 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 = :desired_orm
subject.orm.should eq :desired_orm expect(subject.orm).to eq :desired_orm
end end
end end
@ -446,20 +446,20 @@ module DatabaseCleaner
it "should return orm if orm set" do it "should return orm if orm set" do
subject.instance_variable_set "@orm", mock_orm subject.instance_variable_set "@orm", mock_orm
subject.orm.should eq mock_orm expect(subject.orm).to eq mock_orm
end end
context "orm isn't set" do context "orm isn't set" do
before(:each) { subject.instance_variable_set "@orm", nil } before(:each) { subject.instance_variable_set "@orm", nil }
it "should run autodetect if orm isn't set" do it "should run autodetect if orm isn't set" do
subject.should_receive(:autodetect) expect(subject).to receive(:autodetect)
subject.orm subject.orm
end end
it "should return the result of autodetect if orm isn't set" do it "should return the result of autodetect if orm isn't set" do
subject.stub(:autodetect).and_return(mock_orm) allow(subject).to receive(:autodetect).and_return(mock_orm)
subject.orm.should eq mock_orm expect(subject.orm).to eq mock_orm
end end
end end
end end
@ -468,33 +468,33 @@ module DatabaseCleaner
let (:strategy) { double("strategy") } let (:strategy) { double("strategy") }
before(:each) do before(:each) do
subject.stub(:strategy).and_return(strategy) allow(subject).to receive(:strategy).and_return(strategy)
end end
describe "start" do describe "start" do
it "should proxy start to the strategy" do it "should proxy start to the strategy" do
strategy.should_receive(:start) expect(strategy).to receive(:start)
subject.start subject.start
end end
end end
describe "clean" do describe "clean" do
it "should proxy clean to the strategy" do it "should proxy clean to the strategy" do
strategy.should_receive(:clean) expect(strategy).to receive(:clean)
subject.clean subject.clean
end end
end end
describe "clean!" do describe "clean!" do
it "should proxy clean! to the strategy clean" do it "should proxy clean! to the strategy clean" do
strategy.should_receive(:clean) expect(strategy).to receive(:clean)
subject.clean! subject.clean!
end end
end end
describe "cleaning" do describe "cleaning" do
it "should proxy cleaning to the strategy" do it "should proxy cleaning to the strategy" do
strategy.should_receive(:cleaning) expect(strategy).to receive(:cleaning)
subject.cleaning { } subject.cleaning { }
end end
end end
@ -503,12 +503,12 @@ module DatabaseCleaner
describe "auto_detected?" do describe "auto_detected?" do
it "should return true unless @autodetected is nil" do it "should return true unless @autodetected is nil" do
subject.instance_variable_set("@autodetected","not nil") subject.instance_variable_set("@autodetected","not nil")
subject.auto_detected?.should be_truthy expect(subject.auto_detected?).to be_truthy
end end
it "should return false if @autodetect is nil" do it "should return false if @autodetect is nil" do
subject.instance_variable_set("@autodetected",nil) subject.instance_variable_set("@autodetected",nil)
subject.auto_detected?.should be_falsey expect(subject.auto_detected?).to be_falsey
end end
end end
@ -516,28 +516,28 @@ module DatabaseCleaner
let (:strategy_class) { double("strategy_class") } let (:strategy_class) { double("strategy_class") }
before(:each) do before(:each) do
subject.stub(:orm_module).and_return(strategy_class) allow(subject).to receive(:orm_module).and_return(strategy_class)
end end
context "in response to a LoadError" do 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 it "should raise UnknownStrategySpecified" do
expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified
end end
it "should ask orm_module if it will list available_strategies" do 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 expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified
end end
it "should use available_strategies (for the error message) if its available" do 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 expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified
end end
@ -546,11 +546,11 @@ module DatabaseCleaner
it "should return the constant of the Strategy class requested" do it "should return the constant of the Strategy class requested" do
strategy_strategy_class = double("strategy strategy_class") 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
end end
@ -558,52 +558,52 @@ module DatabaseCleaner
describe 'set_default_orm_strategy' do describe 'set_default_orm_strategy' do
it 'sets strategy to :transaction for ActiveRecord' do it 'sets strategy to :transaction for ActiveRecord' do
cleaner = DatabaseCleaner::Base.new(:active_record) 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 end
it 'sets strategy to :transaction for DataMapper' do it 'sets strategy to :transaction for DataMapper' do
cleaner = DatabaseCleaner::Base.new(:data_mapper) 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 end
it 'sets strategy to :truncation for MongoMapper' do it 'sets strategy to :truncation for MongoMapper' do
cleaner = DatabaseCleaner::Base.new(:mongo_mapper) 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 end
it 'sets strategy to :truncation for Mongoid' do it 'sets strategy to :truncation for Mongoid' do
cleaner = DatabaseCleaner::Base.new(:mongoid) 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 end
it 'sets strategy to :truncation for CouchPotato' do it 'sets strategy to :truncation for CouchPotato' do
cleaner = DatabaseCleaner::Base.new(:couch_potato) 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 end
it 'sets strategy to :transaction for Sequel' do it 'sets strategy to :transaction for Sequel' do
cleaner = DatabaseCleaner::Base.new(:sequel) 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 end
it 'sets strategy to :truncation for Moped' do it 'sets strategy to :truncation for Moped' do
cleaner = DatabaseCleaner::Base.new(:moped) 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 end
it 'sets strategy to :truncation for Ohm' do it 'sets strategy to :truncation for Ohm' do
cleaner = DatabaseCleaner::Base.new(:ohm) 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 end
it 'sets strategy to :truncation for Redis' do it 'sets strategy to :truncation for Redis' do
cleaner = DatabaseCleaner::Base.new(:redis) 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 end
it 'sets strategy to :transaction for Neo4j' do it 'sets strategy to :transaction for Neo4j' do
cleaner = DatabaseCleaner::Base.new(:neo4j) 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
end end

View file

@ -30,71 +30,71 @@ describe ::DatabaseCleaner do
it "should accept :active_record" do it "should accept :active_record" do
cleaner = ::DatabaseCleaner[:active_record] cleaner = ::DatabaseCleaner[:active_record]
cleaner.should be_a(::DatabaseCleaner::Base) expect(cleaner).to be_a(::DatabaseCleaner::Base)
cleaner.orm.should eq :active_record expect(cleaner.orm).to eq :active_record
::DatabaseCleaner.connections.size.should eq 1 expect(::DatabaseCleaner.connections.size).to eq 1
end end
it "should accept :data_mapper" do it "should accept :data_mapper" do
cleaner = ::DatabaseCleaner[:data_mapper] cleaner = ::DatabaseCleaner[:data_mapper]
cleaner.should be_a(::DatabaseCleaner::Base) expect(cleaner).to be_a(::DatabaseCleaner::Base)
cleaner.orm.should eq :data_mapper expect(cleaner.orm).to eq :data_mapper
::DatabaseCleaner.connections.size.should eq 1 expect(::DatabaseCleaner.connections.size).to eq 1
end end
it "should accept :mongo_mapper" do it "should accept :mongo_mapper" do
cleaner = ::DatabaseCleaner[:mongo_mapper] cleaner = ::DatabaseCleaner[:mongo_mapper]
cleaner.should be_a(::DatabaseCleaner::Base) expect(cleaner).to be_a(::DatabaseCleaner::Base)
cleaner.orm.should eq :mongo_mapper expect(cleaner.orm).to eq :mongo_mapper
::DatabaseCleaner.connections.size.should eq 1 expect(::DatabaseCleaner.connections.size).to eq 1
end end
it "should accept :couch_potato" do it "should accept :couch_potato" do
cleaner = ::DatabaseCleaner[:couch_potato] cleaner = ::DatabaseCleaner[:couch_potato]
cleaner.should be_a(::DatabaseCleaner::Base) expect(cleaner).to be_a(::DatabaseCleaner::Base)
cleaner.orm.should eq :couch_potato expect(cleaner.orm).to eq :couch_potato
::DatabaseCleaner.connections.size.should eq 1 expect(::DatabaseCleaner.connections.size).to eq 1
end end
it "should accept :moped" do it "should accept :moped" do
cleaner = ::DatabaseCleaner[:moped] cleaner = ::DatabaseCleaner[:moped]
cleaner.should be_a(::DatabaseCleaner::Base) expect(cleaner).to be_a(::DatabaseCleaner::Base)
cleaner.orm.should eq :moped expect(cleaner.orm).to eq :moped
::DatabaseCleaner.connections.size.should eq 1 expect(::DatabaseCleaner.connections.size).to eq 1
end end
it 'accepts :ohm' do it 'accepts :ohm' do
cleaner = ::DatabaseCleaner[:ohm] cleaner = ::DatabaseCleaner[:ohm]
cleaner.should be_a(::DatabaseCleaner::Base) expect(cleaner).to be_a(::DatabaseCleaner::Base)
cleaner.orm.should eq :ohm expect(cleaner.orm).to eq :ohm
::DatabaseCleaner.connections.size.should eq 1 expect(::DatabaseCleaner.connections.size).to eq 1
end end
end end
it "should accept multiple orm's" do it "should accept multiple orm's" do
::DatabaseCleaner[:couch_potato] ::DatabaseCleaner[:couch_potato]
::DatabaseCleaner[:data_mapper] ::DatabaseCleaner[:data_mapper]
::DatabaseCleaner.connections.size.should eq 2 expect(::DatabaseCleaner.connections.size).to eq 2
::DatabaseCleaner.connections[0].orm.should eq :couch_potato expect(::DatabaseCleaner.connections[0].orm).to eq :couch_potato
::DatabaseCleaner.connections[1].orm.should eq :data_mapper expect(::DatabaseCleaner.connections[1].orm).to eq :data_mapper
end end
context "connection/db specification" do context "connection/db specification" do
it "should accept a connection parameter and store it" do it "should accept a connection parameter and store it" do
cleaner = ::DatabaseCleaner[:active_record, {:connection => :first_connection}] cleaner = ::DatabaseCleaner[:active_record, {:connection => :first_connection}]
cleaner.should be_a(::DatabaseCleaner::Base) expect(cleaner).to be_a(::DatabaseCleaner::Base)
cleaner.orm.should eq :active_record expect(cleaner.orm).to eq :active_record
cleaner.db.should eq :first_connection expect(cleaner.db).to eq :first_connection
end end
it "should accept multiple connections for a single orm" do it "should accept multiple connections for a single orm" do
::DatabaseCleaner[:data_mapper,{:connection => :first_db}] ::DatabaseCleaner[:data_mapper,{:connection => :first_db}]
::DatabaseCleaner[:data_mapper,{:connection => :second_db}] ::DatabaseCleaner[:data_mapper,{:connection => :second_db}]
::DatabaseCleaner.connections.size.should eq 2 expect(::DatabaseCleaner.connections.size).to eq 2
::DatabaseCleaner.connections[0].orm.should eq :data_mapper expect(::DatabaseCleaner.connections[0].orm).to eq :data_mapper
::DatabaseCleaner.connections[0].db.should eq :first_db expect(::DatabaseCleaner.connections[0].db).to eq :first_db
::DatabaseCleaner.connections[1].orm.should eq :data_mapper expect(::DatabaseCleaner.connections[1].orm).to eq :data_mapper
::DatabaseCleaner.connections[1].db.should eq :second_db expect(::DatabaseCleaner.connections[1].db).to eq :second_db
end end
it "should accept multiple connections and multiple orms" do it "should accept multiple connections and multiple orms" do
@ -103,19 +103,19 @@ describe ::DatabaseCleaner do
::DatabaseCleaner[:active_record,{:connection => :first_db} ] ::DatabaseCleaner[:active_record,{:connection => :first_db} ]
::DatabaseCleaner[:data_mapper, {:connection => :second_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 expect(::DatabaseCleaner.connections[0].orm).to eq :data_mapper
::DatabaseCleaner.connections[0].db.should eq :first_db expect(::DatabaseCleaner.connections[0].db).to eq :first_db
::DatabaseCleaner.connections[1].orm.should eq :active_record expect(::DatabaseCleaner.connections[1].orm).to eq :active_record
::DatabaseCleaner.connections[1].db.should eq :second_db expect(::DatabaseCleaner.connections[1].db).to eq :second_db
::DatabaseCleaner.connections[2].orm.should eq :active_record expect(::DatabaseCleaner.connections[2].orm).to eq :active_record
::DatabaseCleaner.connections[2].db.should eq :first_db expect(::DatabaseCleaner.connections[2].db).to eq :first_db
::DatabaseCleaner.connections[3].orm.should eq :data_mapper expect(::DatabaseCleaner.connections[3].orm).to eq :data_mapper
::DatabaseCleaner.connections[3].db.should eq :second_db expect(::DatabaseCleaner.connections[3].db).to eq :second_db
end end
end end
@ -123,7 +123,7 @@ describe ::DatabaseCleaner do
it "should retrieve a db rather than create a new one" do it "should retrieve a db rather than create a new one" do
pending pending
connection = ::DatabaseCleaner[:active_record].strategy = :truncation connection = ::DatabaseCleaner[:active_record].strategy = :truncation
::DatabaseCleaner[:active_record].should eq connection expect(::DatabaseCleaner[:active_record]).to eq connection
end end
end end
@ -132,9 +132,9 @@ describe ::DatabaseCleaner do
it "should give me a default (autodetection) databasecleaner by default" do it "should give me a default (autodetection) databasecleaner by default" do
cleaner = double("cleaner").as_null_object 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
end end
@ -143,34 +143,34 @@ describe ::DatabaseCleaner do
it "should proxy strategy=" do it "should proxy strategy=" do
stratagum = double("stratagum") stratagum = double("stratagum")
connection.should_receive(:strategy=).with(stratagum) expect(connection).to receive(:strategy=).with(stratagum)
::DatabaseCleaner.strategy = stratagum ::DatabaseCleaner.strategy = stratagum
end end
it "should proxy orm=" do it "should proxy orm=" do
orm = double("orm") orm = double("orm")
connection.should_receive(:orm=).with(orm) expect(connection).to receive(:orm=).with(orm)
::DatabaseCleaner.orm = orm ::DatabaseCleaner.orm = orm
end end
it "should proxy start" do it "should proxy start" do
connection.should_receive(:start) expect(connection).to receive(:start)
::DatabaseCleaner.start ::DatabaseCleaner.start
end end
it "should proxy clean" do it "should proxy clean" do
connection.should_receive(:clean) expect(connection).to receive(:clean)
::DatabaseCleaner.clean ::DatabaseCleaner.clean
end end
it 'should proxy cleaning' do it 'should proxy cleaning' do
connection.should_receive(:cleaning) expect(connection).to receive(:cleaning)
::DatabaseCleaner.cleaning { } ::DatabaseCleaner.cleaning { }
end end
it "should proxy clean_with" do it "should proxy clean_with" do
stratagem = double("stratgem") stratagem = double("stratgem")
connection.should_receive(:clean_with).with(stratagem, {}) expect(connection).to receive(:clean_with).with(stratagem, {})
::DatabaseCleaner.clean_with stratagem, {} ::DatabaseCleaner.clean_with stratagem, {}
end end
end end
@ -184,26 +184,26 @@ describe ::DatabaseCleaner do
let(:data_mapper) { double("data_mock") } let(:data_mapper) { double("data_mock") }
before(:each) do before(:each) do
::DatabaseCleaner.stub(:connections).and_return([active_record,data_mapper]) allow(::DatabaseCleaner).to receive(:connections).and_return([active_record,data_mapper])
end end
it "should proxy orm to all connections" do it "should proxy orm to all connections" do
active_record.should_receive(:orm=) expect(active_record).to receive(:orm=)
data_mapper.should_receive(:orm=) expect(data_mapper).to receive(:orm=)
::DatabaseCleaner.orm = double("orm") ::DatabaseCleaner.orm = double("orm")
end end
it "should proxy start to all connections" do it "should proxy start to all connections" do
active_record.should_receive(:start) expect(active_record).to receive(:start)
data_mapper.should_receive(:start) expect(data_mapper).to receive(:start)
::DatabaseCleaner.start ::DatabaseCleaner.start
end end
it "should proxy clean to all connections" do it "should proxy clean to all connections" do
active_record.should_receive(:clean) expect(active_record).to receive(:clean)
data_mapper.should_receive(:clean) expect(data_mapper).to receive(:clean)
::DatabaseCleaner.clean ::DatabaseCleaner.clean
end end
@ -220,20 +220,20 @@ describe ::DatabaseCleaner do
end end
::DatabaseCleaner.cleaning do ::DatabaseCleaner.cleaning do
active_record.started.should == true expect(active_record.started).to eq(true)
data_mapper.started.should == true expect(data_mapper.started).to eq(true)
active_record.cleaned.should == nil expect(active_record.cleaned).to eq(nil)
data_mapper.cleaned.should == nil expect(data_mapper.cleaned).to eq(nil)
@yielded = true @yielded = true
end end
active_record.cleaned.should == true expect(active_record.cleaned).to eq(true)
data_mapper.cleaned.should == true expect(data_mapper.cleaned).to eq(true)
end end
it "should proxy clean_with to all connections" do it "should proxy clean_with to all connections" do
stratagem = double("stratgem") stratagem = double("stratgem")
active_record.should_receive(:clean_with).with(stratagem) expect(active_record).to receive(:clean_with).with(stratagem)
data_mapper.should_receive(:clean_with).with(stratagem) expect(data_mapper).to receive(:clean_with).with(stratagem)
::DatabaseCleaner.clean_with stratagem ::DatabaseCleaner.clean_with stratagem
end end
@ -250,15 +250,15 @@ describe ::DatabaseCleaner do
::DatabaseCleaner.connections_stub [active_record_1,active_record_2,data_mapper_1] ::DatabaseCleaner.connections_stub [active_record_1,active_record_2,data_mapper_1]
active_record_1.should_receive(:orm=).with(:data_mapper) expect(active_record_1).to receive(:orm=).with(:data_mapper)
active_record_2.should_receive(:orm=).with(:data_mapper) expect(active_record_2).to receive(:orm=).with(:data_mapper)
data_mapper_1.should_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.orm = :data_mapper
::DatabaseCleaner.connections.size.should eq 2 expect(::DatabaseCleaner.connections.size).to eq 2
end end
it "should proxy strategy to all connections and remove duplicate connections" do 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] ::DatabaseCleaner.connections_stub [active_record_1,active_record_2]
active_record_1.should_receive(:strategy=).with(strategy) expect(active_record_1).to receive(:strategy=).with(strategy)
active_record_2.should_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.strategy = strategy
::DatabaseCleaner.connections.size.should eq 1 expect(::DatabaseCleaner.connections.size).to eq 1
end end
end end
end end
@ -288,18 +288,18 @@ describe ::DatabaseCleaner do
::DatabaseCleaner.connections_stub [connection,connection,connection] ::DatabaseCleaner.connections_stub [connection,connection,connection]
::DatabaseCleaner.remove_duplicates ::DatabaseCleaner.remove_duplicates
::DatabaseCleaner.connections.size.should eq 1 expect(::DatabaseCleaner.connections.size).to eq 1
end end
end end
describe "app_root" do describe "app_root" do
it "should default to Dir.pwd" do it "should default to Dir.pwd" do
DatabaseCleaner.app_root.should eq Dir.pwd expect(DatabaseCleaner.app_root).to eq Dir.pwd
end end
it "should store specific paths" do it "should store specific paths" do
DatabaseCleaner.app_root = '/path/to' DatabaseCleaner.app_root = '/path/to'
DatabaseCleaner.app_root.should eq '/path/to' expect(DatabaseCleaner.app_root).to eq '/path/to'
end end
end end
@ -308,37 +308,37 @@ describe ::DatabaseCleaner do
it "should return DatabaseCleaner::ActiveRecord for :active_record" do it "should return DatabaseCleaner::ActiveRecord for :active_record" do
::DatabaseCleaner::ActiveRecord = double("ar module") unless defined? ::DatabaseCleaner::ActiveRecord ::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 end
it "should return DatabaseCleaner::DataMapper for :data_mapper" do it "should return DatabaseCleaner::DataMapper for :data_mapper" do
::DatabaseCleaner::DataMapper = double("dm module") unless defined? ::DatabaseCleaner::DataMapper ::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 end
it "should return DatabaseCleaner::MongoMapper for :mongo_mapper" do it "should return DatabaseCleaner::MongoMapper for :mongo_mapper" do
::DatabaseCleaner::MongoMapper = double("mm module") unless defined? ::DatabaseCleaner::MongoMapper ::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 end
it "should return DatabaseCleaner::Mongoid for :mongoid" do it "should return DatabaseCleaner::Mongoid for :mongoid" do
::DatabaseCleaner::Mongoid = double("mongoid module") unless defined? ::DatabaseCleaner::Mongoid ::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 end
it "should return DatabaseCleaner::Mongo for :mongo" do it "should return DatabaseCleaner::Mongo for :mongo" do
::DatabaseCleaner::Mongo = double("mongo module") unless defined? ::DatabaseCleaner::Mongo ::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 end
it "should return DatabaseCleaner::CouchPotato for :couch_potato" do it "should return DatabaseCleaner::CouchPotato for :couch_potato" do
::DatabaseCleaner::CouchPotato = double("cp module") unless defined? ::DatabaseCleaner::CouchPotato ::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 end
it "should return DatabaseCleaner::Neo4j for :neo4j" do it "should return DatabaseCleaner::Neo4j for :neo4j" do
::DatabaseCleaner::Neo4j = double("nj module") unless defined? ::DatabaseCleaner::Neo4j ::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
end end

View file

@ -9,31 +9,31 @@ module DatabaseCleaner
let(:database) { double('database') } let(:database) { double('database') }
before(:each) do before(:each) do
::CouchPotato.stub(:couchrest_database).and_return(database) allow(::CouchPotato).to receive(:couchrest_database).and_return(database)
end end
it "should re-create the database" do it "should re-create the database" do
database.should_receive(:recreate!) expect(database).to receive(:recreate!)
Truncation.new.clean Truncation.new.clean
end end
it "should raise an error when the :only option is used" do it "should raise an error when the :only option is used" do
running { expect(running {
Truncation.new(:only => ['document-type']) Truncation.new(:only => ['document-type'])
}.should raise_error(ArgumentError) }).to raise_error(ArgumentError)
end end
it "should raise an error when the :except option is used" do it "should raise an error when the :except option is used" do
running { expect(running {
Truncation.new(:except => ['document-type']) Truncation.new(:except => ['document-type'])
}.should raise_error(ArgumentError) }).to raise_error(ArgumentError)
end end
it "should raise an error when invalid options are provided" do it "should raise an error when invalid options are provided" do
running { expect(running {
Truncation.new(:foo => 'bar') Truncation.new(:foo => 'bar')
}.should raise_error(ArgumentError) }).to raise_error(ArgumentError)
end end
end end

View file

@ -4,7 +4,7 @@ require 'database_cleaner/shared_strategy'
module DatabaseCleaner module DatabaseCleaner
describe DataMapper do describe DataMapper do
it { should respond_to(:available_strategies) } it { is_expected.to respond_to(:available_strategies) }
end end
module DataMapper module DataMapper
@ -14,16 +14,16 @@ module DatabaseCleaner
describe ExampleStrategy do describe ExampleStrategy do
it_should_behave_like "a generic strategy" it_should_behave_like "a generic strategy"
it { should respond_to(:db) } it { is_expected.to respond_to(:db) }
it { should respond_to(:db=) } it { is_expected.to respond_to(:db=) }
it "should store my desired db" do it "should store my desired db" do
subject.db = :my_db subject.db = :my_db
subject.db.should eq :my_db expect(subject.db).to eq :my_db
end end
it "should default to :default" do it "should default to :default" do
subject.db.should eq :default expect(subject.db).to eq :default
end end
end end
end end

View file

@ -24,7 +24,7 @@ module DataMapper
2.times { DmUser.create } 2.times { DmUser.create }
connection.truncate_table(DmUser.storage_names[:default]) connection.truncate_table(DmUser.storage_names[:default])
DmUser.count.should eq 0 expect(DmUser.count).to eq 0
end end
it "resets AUTO_INCREMENT index of table" do it "resets AUTO_INCREMENT index of table" do
@ -33,7 +33,7 @@ module DataMapper
connection.truncate_table(DmUser.storage_names[:default]) connection.truncate_table(DmUser.storage_names[:default])
DmUser.create.id.should eq 1 expect(DmUser.create.id).to eq 1
end end
end end
end end

View file

@ -35,14 +35,14 @@ module ::DatabaseCleaner
let (:strategy) { ExampleStrategy.new } let (:strategy) { ExampleStrategy.new }
before do before do
# DatabaseCleaner.strategy = :truncation # DatabaseCleaner.strategy = :truncation
connection.stub(:disable_referential_integrity).and_yield allow(connection).to receive(:disable_referential_integrity).and_yield
connection.stub(:database_cleaner_view_cache).and_return([]) allow(connection).to receive(:database_cleaner_view_cache).and_return([])
connection.stub(:database_cleaner_table_cache).and_return([]) allow(connection).to receive(:database_cleaner_table_cache).and_return([])
::ActiveRecord::Base.stub(:connection).and_return(connection) allow(::ActiveRecord::Base).to receive(:connection).and_return(connection)
end end
it "calls #clean even if there is an exception" do it "calls #clean even if there is an exception" do
strategy.should_receive :clean expect(strategy).to receive :clean
expect do expect do
strategy.cleaning do strategy.cleaning do
raise NoMethodError raise NoMethodError
@ -51,7 +51,7 @@ module ::DatabaseCleaner
end end
it "calls #clean after processing the block" do it "calls #clean after processing the block" do
strategy.should_receive :clean expect(strategy).to receive :clean
strategy.cleaning do strategy.cleaning do
end end
end end

View file

@ -41,13 +41,13 @@ module ::DatabaseCleaner
end end
context "private methods" do 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 it 'expects #tables_to_truncate to be implemented later' do
expect{ truncation_example.send :tables_to_truncate }.to raise_error(NotImplementedError) expect{ truncation_example.send :tables_to_truncate }.to raise_error(NotImplementedError)
end end
it { should_not respond_to(:migration_storage_names) } it { is_expected.not_to respond_to(:migration_storage_names) }
end end
describe "initialize" do describe "initialize" do
@ -66,40 +66,40 @@ module ::DatabaseCleaner
context "" do context "" do
subject { TruncationExample.new( { :only => ["something"] } ) } subject { TruncationExample.new( { :only => ["something"] } ) }
it { subject.only.should eq ["something"] } it { expect(subject.only).to eq ["something"] }
it { subject.except.should eq [] } it { expect(subject.except).to eq [] }
end end
context "" do context "" do
subject { TruncationExample.new( { :except => ["something"] } ) } subject { TruncationExample.new( { :except => ["something"] } ) }
it { subject.only.should eq nil } it { expect(subject.only).to eq nil }
it { subject.except.should include("something") } it { expect(subject.except).to include("something") }
end end
context "" do context "" do
subject { TruncationExample.new( { :reset_ids => ["something"] } ) } subject { TruncationExample.new( { :reset_ids => ["something"] } ) }
it { subject.reset_ids?.should eq true } it { expect(subject.reset_ids?).to eq true }
end end
context "" do context "" do
subject { TruncationExample.new( { :reset_ids => nil } ) } subject { TruncationExample.new( { :reset_ids => nil } ) }
it { subject.reset_ids?.should eq false } it { expect(subject.reset_ids?).to eq false }
end end
context "" do context "" do
subject { TruncationExample.new( { :pre_count => ["something"] } ) } subject { TruncationExample.new( { :pre_count => ["something"] } ) }
it { subject.pre_count?.should eq true } it { expect(subject.pre_count?).to eq true }
end end
context "" do context "" do
subject { TruncationExample.new( { :pre_count => nil } ) } subject { TruncationExample.new( { :pre_count => nil } ) }
it { subject.pre_count?.should eq false } it { expect(subject.pre_count?).to eq false }
end end
context "" do context "" do
subject { MigrationExample.new } subject { MigrationExample.new }
it { subject.only.should eq nil } it { expect(subject.only).to eq nil }
it { subject.except.should eq %w[migration_storage_name] } it { expect(subject.except).to eq %w[migration_storage_name] }
end end
context "" do context "" do
@ -107,8 +107,8 @@ module ::DatabaseCleaner
subject { MigrationExample.new( { :except => EXCEPT_TABLES } ) } subject { MigrationExample.new( { :except => EXCEPT_TABLES } ) }
it "should not modify the array of excepted tables" do it "should not modify the array of excepted tables" do
subject.except.should include("migration_storage_name") expect(subject.except).to include("migration_storage_name")
EXCEPT_TABLES.should_not include("migration_storage_name") expect(EXCEPT_TABLES).not_to include("migration_storage_name")
end end
end end
end end

View file

@ -25,7 +25,7 @@ module DatabaseCleaner
# very odd and disconcerting... # very odd and disconcerting...
expected_counts.each do |model_class, expected_count| expected_counts.each do |model_class, expected_count|
actual_count = model_class.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
end end

View file

@ -4,7 +4,7 @@ require 'database_cleaner/shared_strategy'
module DatabaseCleaner module DatabaseCleaner
describe MongoMapper do describe MongoMapper do
it { should respond_to(:available_strategies) } it { is_expected.to respond_to(:available_strategies) }
end end
module MongoMapper module MongoMapper
@ -17,15 +17,15 @@ module DatabaseCleaner
it_should_behave_like "a generic strategy" it_should_behave_like "a generic strategy"
describe "db" do describe "db" do
it { should respond_to(:db=) } it { is_expected.to respond_to(:db=) }
it "should store my desired db" do it "should store my desired db" do
subject.db = :my_db subject.db = :my_db
subject.db.should eq :my_db expect(subject.db).to eq :my_db
end end
it "should default to :default" do it "should default to :default" do
subject.db.should eq :default expect(subject.db).to eq :default
end end
end end
end end

View file

@ -26,7 +26,7 @@ module DatabaseCleaner
begin begin
expected_counts.each do |model_class, expected_count| expected_counts.each do |model_class, expected_count|
actual_count = model_class.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
rescue RSpec::Expectations::ExpectationNotMetError => e rescue RSpec::Expectations::ExpectationNotMetError => e
raise !sanity_check ? e : RSpec::ExpectationNotMetError::ExpectationNotMetError.new("SANITY CHECK FAILURE! This should never happen here: #{e.message}") raise !sanity_check ? e : RSpec::ExpectationNotMetError::ExpectationNotMetError.new("SANITY CHECK FAILURE! This should never happen here: #{e.message}")

View file

@ -29,7 +29,7 @@ module DatabaseCleaner
# very odd and disconcerting... # very odd and disconcerting...
expected_counts.each do |model_class, expected_count| expected_counts.each do |model_class, expected_count|
actual_count = model_class.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
end end

View file

@ -4,7 +4,7 @@ require 'database_cleaner/shared_strategy'
module DatabaseCleaner module DatabaseCleaner
describe Neo4j do describe Neo4j do
it { should respond_to(:available_strategies) } it { is_expected.to respond_to(:available_strategies) }
end end
module Neo4j module Neo4j
@ -15,28 +15,28 @@ module DatabaseCleaner
describe ExampleStrategy do describe ExampleStrategy do
it_should_behave_like "a generic strategy" it_should_behave_like "a generic strategy"
it { should respond_to(:db) } it { is_expected.to respond_to(:db) }
it { should respond_to(:db=) } it { is_expected.to respond_to(:db=) }
it "should store my describe db" do it "should store my describe db" do
db_conf = {:connection => {:type => :server_db, :path => 'http://localhost:7474'}} db_conf = {:connection => {:type => :server_db, :path => 'http://localhost:7474'}}
subject.db = db_conf subject.db = db_conf
subject.db.should eq db_conf expect(subject.db).to eq db_conf
end end
it "should respect additional connection parameters" do it "should respect additional connection parameters" do
db_conf = {:type => :server_db, :path => 'http://localhost:7474', basic_auth: {username: 'user', password: 'pass'}} db_conf = {:type => :server_db, :path => 'http://localhost:7474', basic_auth: {username: 'user', password: 'pass'}}
subject.db = db_conf 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 subject.start
end end
it "should default to nil" do it "should default to nil" do
subject.db.should be_nil expect(subject.db).to be_nil
end end
it "should return default configuration" do 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 end
end end

View file

@ -3,11 +3,11 @@ require 'spec_helper'
module DatabaseCleaner module DatabaseCleaner
describe NullStrategy do describe NullStrategy do
it 'responds to .start' do it 'responds to .start' do
expect { NullStrategy.start }.not_to raise_error(NoMethodError) expect { NullStrategy.start }.not_to raise_error
end end
it 'responds to .clean' do it 'responds to .clean' do
expect { NullStrategy.clean }.not_to raise_error(NoMethodError) expect { NullStrategy.clean }.not_to raise_error
end end
describe '.cleaning' do describe '.cleaning' do

View file

@ -39,19 +39,19 @@ module DatabaseCleaner
it "truncates all keys by default" do it "truncates all keys by default" do
create_widget create_widget
create_gadget create_gadget
@redis.keys.size.should eq 6 expect(@redis.keys.size).to eq 6
Truncation.new.clean Truncation.new.clean
@redis.keys.size.should eq 0 expect(@redis.keys.size).to eq 0
end end
context "when keys are provided to the :only option" do context "when keys are provided to the :only option" do
it "only truncates the specified keys" do it "only truncates the specified keys" do
create_widget create_widget
create_gadget create_gadget
@redis.keys.size.should eq 6 expect(@redis.keys.size).to eq 6
Truncation.new(:only => ['*Widget*']).clean Truncation.new(:only => ['*Widget*']).clean
@redis.keys.size.should eq 3 expect(@redis.keys.size).to eq 3
@redis.get('DatabaseCleaner::Ohm::Gadget:id').should eq '1' expect(@redis.get('DatabaseCleaner::Ohm::Gadget:id')).to eq '1'
end end
end end
@ -59,10 +59,10 @@ module DatabaseCleaner
it "truncates all but the specified keys" do it "truncates all but the specified keys" do
create_widget create_widget
create_gadget create_gadget
@redis.keys.size.should eq 6 expect(@redis.keys.size).to eq 6
Truncation.new(:except => ['*Widget*']).clean Truncation.new(:except => ['*Widget*']).clean
@redis.keys.size.should eq 3 expect(@redis.keys.size).to eq 3
@redis.get('DatabaseCleaner::Ohm::Widget:id').should eq '1' expect(@redis.get('DatabaseCleaner::Ohm::Widget:id')).to eq '1'
end end
end end
end end

View file

@ -5,7 +5,7 @@ require 'database_cleaner/shared_strategy'
module DatabaseCleaner module DatabaseCleaner
describe Redis do describe Redis do
it { should respond_to(:available_strategies) } it { is_expected.to respond_to(:available_strategies) }
end end
module Redis module Redis
@ -16,14 +16,14 @@ module DatabaseCleaner
describe ExampleStrategy do describe ExampleStrategy do
it_should_behave_like "a generic strategy" it_should_behave_like "a generic strategy"
it { should respond_to(:db) } it { is_expected.to respond_to(:db) }
it { should respond_to(:db=) } it { is_expected.to respond_to(:db=) }
context "when passing url" do context "when passing url" do
it "should store my describe db" do it "should store my describe db" do
url = 'redis://localhost:6379/2' url = 'redis://localhost:6379/2'
subject.db = 'redis://localhost:6379/2' subject.db = 'redis://localhost:6379/2'
subject.db.should eq url expect(subject.db).to eq url
end end
end end
@ -31,12 +31,12 @@ module DatabaseCleaner
it "should store my describe db" do it "should store my describe db" do
connection = ::Redis.new :url => 'redis://localhost:6379/2' connection = ::Redis.new :url => 'redis://localhost:6379/2'
subject.db = connection subject.db = connection
subject.db.should eq connection expect(subject.db).to eq connection
end end
end end
it "should default to :default" do it "should default to :default" do
subject.db.should eq :default expect(subject.db).to eq :default
end end
end end
end end

View file

@ -31,19 +31,19 @@ module DatabaseCleaner
it "truncates all keys by default" do it "truncates all keys by default" do
create_widget create_widget
create_gadget create_gadget
@redis.keys.size.should eq 2 expect(@redis.keys.size).to eq 2
Truncation.new.clean Truncation.new.clean
@redis.keys.size.should eq 0 expect(@redis.keys.size).to eq 0
end end
context "when keys are provided to the :only option" do context "when keys are provided to the :only option" do
it "only truncates the specified keys" do it "only truncates the specified keys" do
create_widget create_widget
create_gadget create_gadget
@redis.keys.size.should eq 2 expect(@redis.keys.size).to eq 2
Truncation.new(:only => ['Widge*']).clean Truncation.new(:only => ['Widge*']).clean
@redis.keys.size.should eq 1 expect(@redis.keys.size).to eq 1
@redis.get('Gadget').should eq '1' expect(@redis.get('Gadget')).to eq '1'
end end
end end
@ -51,10 +51,10 @@ module DatabaseCleaner
it "truncates all but the specified keys" do it "truncates all but the specified keys" do
create_widget create_widget
create_gadget create_gadget
@redis.keys.size.should eq 2 expect(@redis.keys.size).to eq 2
Truncation.new(:except => ['Widg*']).clean Truncation.new(:except => ['Widg*']).clean
@redis.keys.size.should eq 1 expect(@redis.keys.size).to eq 1
@redis.get('Widget').should eq '1' expect(@redis.get('Widget')).to eq '1'
end end
end end
end end

View file

@ -5,7 +5,7 @@ require 'sequel'
module DatabaseCleaner module DatabaseCleaner
describe Sequel do describe Sequel do
it { should respond_to(:available_strategies) } it { is_expected.to respond_to(:available_strategies) }
end end
module Sequel module Sequel
@ -15,16 +15,16 @@ module DatabaseCleaner
describe ExampleStrategy do describe ExampleStrategy do
it_should_behave_like "a generic strategy" it_should_behave_like "a generic strategy"
it { should respond_to(:db) } it { is_expected.to respond_to(:db) }
it { should respond_to(:db=) } it { is_expected.to respond_to(:db=) }
it "should store my desired db" do it "should store my desired db" do
subject.db = :my_db subject.db = :my_db
subject.db.should eq :my_db expect(subject.db).to eq :my_db
end end
it "should default to :default" do it "should default to :default" do
subject.db.should eq :default expect(subject.db).to eq :default
end end
pending "I figure out how to use Sequel and write some real tests for it..." pending "I figure out how to use Sequel and write some real tests for it..."

View file

@ -134,17 +134,17 @@ module DatabaseCleaner
subject { Truncation.new.tap { |t| t.db = db } } subject { Truncation.new.tap { |t| t.db = db } }
it 'should return false initially' do it 'should return false initially' do
subject.send(:pre_count?).should eq false expect(subject.send(:pre_count?)).to eq false
end end
it 'should return true if @reset_id is set and non false or nil' do it 'should return true if @reset_id is set and non false or nil' do
subject.instance_variable_set(:"@pre_count", true) subject.instance_variable_set(:"@pre_count", true)
subject.send(:pre_count?).should eq true expect(subject.send(:pre_count?)).to eq true
end end
it 'should return false if @reset_id is set to false' do it 'should return false if @reset_id is set to false' do
subject.instance_variable_set(:"@pre_count", false) subject.instance_variable_set(:"@pre_count", false)
subject.send(:pre_count?).should eq false expect(subject.send(:pre_count?)).to eq false
end end
end end
@ -154,8 +154,8 @@ module DatabaseCleaner
it "should rely on #pre_count_truncate_tables if #pre_count? returns true" do it "should rely on #pre_count_truncate_tables if #pre_count? returns true" do
subject.instance_variable_set(:"@pre_count", true) subject.instance_variable_set(:"@pre_count", true)
subject.should_not_receive(:truncate_tables) expect(subject).not_to receive(:truncate_tables)
subject.should_receive(:pre_count_truncate_tables) expect(subject).to receive(:pre_count_truncate_tables)
subject.clean subject.clean
end end
@ -163,8 +163,8 @@ module DatabaseCleaner
it "should not rely on #pre_count_truncate_tables if #pre_count? return false" do it "should not rely on #pre_count_truncate_tables if #pre_count? return false" do
subject.instance_variable_set(:"@pre_count", false) subject.instance_variable_set(:"@pre_count", false)
subject.should_not_receive(:pre_count_truncate_tables) expect(subject).not_to receive(:pre_count_truncate_tables)
subject.should_receive(:truncate_tables) expect(subject).to receive(:truncate_tables)
subject.clean subject.clean
end end

View file

@ -1,15 +1,15 @@
shared_examples_for "a generic strategy" do shared_examples_for "a generic strategy" do
it { should respond_to(:db) } it { is_expected.to respond_to(:db) }
end end
shared_examples_for "a generic truncation strategy" do shared_examples_for "a generic truncation strategy" do
it { should respond_to(:start) } it { is_expected.to respond_to(:start) }
it { should respond_to(:clean) } it { is_expected.to respond_to(:clean) }
it { should respond_to(:cleaning) } it { is_expected.to respond_to(:cleaning) }
end end
shared_examples_for "a generic transaction strategy" do shared_examples_for "a generic transaction strategy" do
it { should respond_to(:start) } it { is_expected.to respond_to(:start) }
it { should respond_to(:clean) } it { is_expected.to respond_to(:clean) }
it { should respond_to(:cleaning) } it { is_expected.to respond_to(:cleaning) }
end end

View file

@ -21,14 +21,6 @@ RSpec.configure do |config|
# get run. # get run.
config.filter_run :focus config.filter_run :focus
config.run_all_when_everything_filtered = true 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 end
alias running lambda alias running lambda