Rails 3 unit test - define a common configuration method that will be performed before each test

I want to clear my before running each test, where should I put the script to achieve this behavior? db

+3
source share
1 answer

Although I cannot imagine why you can do this, perhaps you can try this: https://github.com/bmabey/database_cleaner

In any case, instructions that can be called before each test should be placed in a call to configure:

setup do
    # statements executed on start of every test
end

UPDATE . To explain a little more:

One thing you can do is inside your file test_helper.rb:

class ActiveSupport::TestCase

  ### Common setup for all tests ###
  setup do
      # write code to clean up your database here
  end

end

, , ActiveSupport::TestCase, require 'test_helper'.

, , - , .

, ?

+6

All Articles