I am using the hanami framework and the rspec lib to test my code and PG database. When I trying to test one action I get following error:
PG::InFailedSqlTransaction: ERROR:  current transaction is aborted, commands ignored until end of transaction block
My action has been wrapped in repository transaction:
  def call(params, dependencies)
    begin
      dependencies.repository.transaction do
        create_user(params, dependencies)
        assign_tags(params, dependencies)
        assign_notes(params, dependencies)
      end
    rescue Hanami::Model::Error, Domain::Errors::Exception => error
      raise Domain::Errors::CreateUserFailed, error.message
    end
  end
Here you can see part of my test which are failing:
it 'should raise exception if params contains duplicated email' do
expect{service.call(duplicated_email)}
  .to raise_exception(Domain::Errors::CreateUserFailed)
  .with_message('Duplicated values found (id or 
  email)')
end
it 'should raise exception if params contains duplicated note id' do
expect{service.call(duplicated_note_id)}
  .to raise_exception(Domain::Errors::CreateUserFailed)
end
First test pass but the second one raises exception I mentioned earlier. I know this is caused that previous test raised exception in transaction block. I have found solution mentioned in this answer but I don't work in my case.
RSpec.configure do |config|
  config.before(:suite) do
   DatabaseCleaner.clean_with :deletion
  end
  config.before(:each) do
   DatabaseCleaner.strategy = :transaction
  end
  config.before(:each) do
   DatabaseCleaner.start
  end
  config.after(:each) do
   DatabaseCleaner.clean
  end
end
Thanks for all answers:)
EDIT:
 Failure/Error:
   expect{service.call(duplicated_note_id)}
     .to raise_exception(Domain::Errors::CreateUserFailed)
     .with_message('Duplicated values found in user notes (id)')
   expected Domain::Errors::CreateUserFailed with "Duplicated values found in user notes (id)", got #<Domain::Errors::CreateUserFailed: PG::InFailedSqlTransaction: ERROR:  current transaction is aborted, commands ignored until end of transaction block
   > with backtrace:
     # ./lib/domain/commands/create_user.rb:17:in `rescue in call'
     # ./lib/domain/commands/create_user.rb:8:in `call'
     # ./spec/domain/commands/create_user_spec.rb:210:in `block (3 levels) in <top (required)>'
     # ./spec/domain/commands/create_user_spec.rb:210:in `block (2 levels) in <top (required)>'
 # ./spec/domain/commands/create_user_spec.rb:210:in `block (2 levels) in <top (required)>'
