Are there any differences at all between calling def setup
and setup do
in Rails Minitests? I had been using def setup
this whole time, but I suddenly found that my setup
for a particular test file was not being called. When I changed it to setup do
, it suddenly worked again (without changing anything else). But I find this very peculiar, and I'd rather stick to def setup
for everything if possible, for consistency. Any advice is appreciated.
require 'test_helper'
require_relative '../../helpers/user_helper'
class FooTest < ActiveSupport::TestCase
include UserHelper
# This method doesn't get called as-is.
# But it does get called if I change the below to `setup do`.
def setup
# create_three_users is a UserHelper method.
create_three_users
@test_user = User.first
end
test 'should abc' do
# Trying to call @test_user here returned nil.
end
end