0
사용자 작업을 모방하고 서로를 의존하는 일련의 테스트가 있습니다.특정 rspec 테스트 그룹의 한가운데서 database_cleaner가 실행되지 않도록하려면 어떻게해야합니까?
database_cleaner
을 정렬 테스트 중에 데이터베이스를 정리하지 않도록 구성하려면 어떻게합니까? 테스트
/spec/support/database_cleaner.rb:
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
샘플 :
RSpec.describe Conversation, type: :model, order: :defined do
context 'by default' do
before :context do
@alice = create :user
@bob = create :user
@subject = 'subject'
@body = 'body'
@conversation = @alice.send_message(@bob, @subject, @body)
end
it 'should have the subject it was opened with' do
expect(@conversation.subject).to eq @subject
end
it 'should have one message upon opening' do
expect(@conversation.messages.count).to eq 1
end
it 'should be initiated by @alice' do
expect(@conversation.initiator).to eq @alice
end
it 'should be received by @bob' do
expect(@conversation.recipient).to eq @bob
end
it 'should have two messages when bob sends a new message' do
@conversation.add_message(@bob, 'This is my second message')
expect(@conversation.messages.count).to eq 2
end
end