2

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

DaniG2k
  • 4,772
  • 36
  • 77
  • Why you need super? define method in `Authorized` and call it in setup or `teardown`. – Roman Kiselenko Oct 19 '18 at 10:13
  • I basically want `setup` and `teardown` to execute the code in the base class but if there is also a `setup` and `teardown` in the test itself, I want that to be executed too - in reverse order of specificity. – DaniG2k Oct 19 '18 at 10:15
  • 1
    you can use super only in the method definition, use plain method definition. – Roman Kiselenko Oct 19 '18 at 10:17

0 Answers0