# Running Unit Tests With SphinxSE

**URL:** <https://www.ruby-forum.com/t/running-unit-tests-with-sphinxse/176217>\
**Category:** Rails\
**Created:** [September 26, 2009, 11:32pm UTC](https://www.ruby-forum.com/t/running-unit-tests-with-sphinxse/176217 "2009-09-26T23:32:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaggotChild](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MaggotChild](https://www.ruby-forum.com/u/MaggotChild)\
**Post date:** [September 26, 2009, 11:32pm UTC](https://www.ruby-forum.com/t/running-unit-tests-with-sphinxse/176217/1 "2009-09-26T23:32:37Z")

</div>

Several of my unit tests run queries against SphinxSE. Since Rails  
creates the test DB by dumping the dev DB schema, my SphinxSE queries  
aren’t run against the test DB.

There seems to be no way to hook into the test:clone\_structure task,  
so I thought that I’ll just have the appropriate unit tests include  
this:

module SphinxTest  
@@index = ‘ct\_test\_index’  
mattr\_accessor :index, :host, :port

self \<\< class  
def included(klass)  
alter\_test\_table unless  
end

```
#MySQL specific
def alter_test_table
  return unless ActiveRecord::Base.connection.table_exists?

```

(Query::TABLE\_SPHINX)

```
  create = ActiveRecord::Base.connection.select_value "show create

```

table #{Query::TABLE\_SPHINX}"  
if @@index && md = create.match %r|sphinx://([-.\w]+):(\d+)?/[-  
\w]+|  
host = @@host || md[0]  
port = @@port || md[1]

```
    alter = %|alter table #{Query::TABLE_SPHINX}

```

connection=“sphinx://#{host}:#{port}/#{@@index}”|  
ActiveRecord::Base.connection.execute alter  
end  
end  
end  
end

does anyone know of way to do this from outside my unit tests?

On a side note, assuming portability was an issue, there seems to be  
know way to get the TableDefinition from the connection. Is this  
really the case?

Thanks
