Passing a DB connection between scripts

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs