How to write a base setup and teardown that runs before every ActionDispatch::IntegrationTest

754 Views Asked by At

I have a number of integration tests written using ActionDispatch::IntegrationTest for a Rails 4 app. I'm trying to add a few lines to every setup and teardown which I want to get called before each test runs, without overriding the setup and teardown callbacks that are specific to each test.

So basically, I'm looking to do something like the following:

class ActionDispatch::IntegrationTest
  setup do
    DatabaseCleaner.start
    super
  end

  teardown do
    Warden.test_reset!
    DatabaseCleaner.clean
    super
  end
end

I do not want these to overwrite the more specific setups, but rather would like them to run before. So I want this setup to run after the base one written above:

class Authorized < ActionDispatch::IntegrationTest
  setup do
    @user = create(:user)
    sign_in(@user)
  end

  test 'some stuff' do
    # Integration test here
  end
end

I am currently getting an error with the above:

NoMethodError: super called outside of method

and so am wondering what the correct way to do this would be. Any advice would be much appreciated! Thanks in advance

0

There are 0 best solutions below