I understand that it will still have access to the variable but I think the problem is that the connection being yielded is now dependent on a variable outside of the helper method which I don't think is a good practice.

```ruby
def test_pk_and_sequence_for_with_non_standard_primary_key
  with_example_table(
    'ex_with_non_standard_pk',
    '`code` INT(11) auto_increment, PRIMARY KEY  (`code`)'
  ) do

    pk, seq = @conn.pk_and_sequence_for('ex_with_non_standard_pk')
    assert_equal 'code', pk
    assert_equal @conn.default_sequence_name('ex_with_non_standard_pk', 'code'), seq
  end
end
```
Taking the above test for instance,  ```connection``` is currently set to the default of ```ActiveRecord::Base.connection``` in the helper method. In this case, ```@conn = ActiveRecord::Base.connection``` which works just fine. However, there is no direct relationship with the connection yielded within the helper method unless it is passed in as a variable. Therefore, if ```@conn``` is changed,  the tests will break. Another suggestion I have is to not set the default connection to ```ActiveRecord::Base.connection``` and have the user explicitly pass it in. I think that would improve readability and avoid confusions like [this](https://github.com/rails/rails/pull/14400/files#r10710576)