# Passing a DB connection between scripts

**URL:** <https://www.ruby-forum.com/t/passing-a-db-connection-between-scripts/172037>\
**Category:** Rails\
**Created:** [July 13, 2009, 6:17pm UTC](https://www.ruby-forum.com/t/passing-a-db-connection-between-scripts/172037 "2009-07-13T18:17:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [July 13, 2009, 6:17pm UTC](https://www.ruby-forum.com/t/passing-a-db-connection-between-scripts/172037/1 "2009-07-13T18:17:19Z")

</div>

I am attempting to test a stand-alone script. I wish to call the script  
from inside the test framework, passing it a variety of command line  
arguments, and verify the results.

The difficulty I have is that the testing framework I am using,  
cucumber, holds db updates inside an incomplete db transaction. It  
thereby avoids the processing cost of an actual commit while easily  
resetting the db for the next test by performing a rollback at the end  
of the present test.

In this situation, opening a new instance of the script via the backtick  
kernel method creates a new db connection. Since this is a different  
connection from that opened by the test framework, incomplete  
transactions are invisible to it and so the script fails, because the  
test data is not available. What I would like to do is to execute the  
script inside the existing Ruby instance and inherit the DB connection.  
This I cannot figure out how to accomplish. I thought that simply  
"load"ing the script would suffice, but no. In this case it evidently  
neither opens its own connection nor inherits the existing one for I  
receive this error at the load statement.

```
  PGError: not connected: ROLLBACK (ActiveRecord::StatementInvalid)
  /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:212:in

```

`log’

Does anyone have any ideas on how I can accomplish what I desire?
