Database Cleaner not working in minitest rails

后端 未结 5 659
慢半拍i
慢半拍i 2021-01-02 14:48

My Minitest controller tests are working fine if I run them alone using rake minitest:controllers but when I run rake minitest:all then I get valid

5条回答
  •  悲&欢浪女
    2021-01-02 15:05

    If for whatever reason you don't want to add the 'minitest-around' gem (to have more than one setup and teardown method), you can do this in your test_helper.rb...

    require "database_cleaner"
    DatabaseCleaner.strategy = :transaction
    
    module AroundEachTest
      def before_setup
        super
        DatabaseCleaner.start
      end
    
      def after_teardown
        super
        DatabaseCleaner.clean
      end
    end
    
    class Minitest::Test
      include AroundEachTest
    end
    

提交回复
热议问题