[rspec-users] Sqlite3, in-memory db and rspec_server

Scott Taylor mailing_lists at railsnewbie.com
Thu Jun 21 15:21:01 EDT 2007


Here is the method definition in which it bails out:

         def table_structure(table_name)
           returning structure = execute("PRAGMA table_info(# 
{table_name})") do
             raise(ActiveRecord::StatementInvalid, "Could not find  
table '#{table_name}'") if structure.empty?
           end
         end

I'm not sure why you the string "could not find..." was not included  
in the error.  Maybe different versions of rails?  (I notice the line  
numbers are different...so you probably aren't using trunk).

Maybe I should look into modifying the DRB server to not run rake  
db:test:prepare (and leave this for later on in the process)? (Any  
tips from core members would be nice ; )  )

Also, I wonder if it would be useful to have something like fixture  
data which doesn't get loaded into the DB.  That is, preset data  
specified in YAML, which could be reloaded to it's original state  
after every specification block, but which would never touch the DB  
on invokation.  It would certainly be faster (even faster than in  
memory databases), and would work just fine for validating AR objects.

Scott






On Jun 21, 2007, at 2:54 PM, Ed Howland wrote:

> On 6/21/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:
>>
>> On Jun 21, 2007, at 1:32 PM, Ed Howland wrote:
>>
>>> Hi everyone.
>>>
>>> I can't get the above(subject line) combination to work. If I use a
>>> standard sqlite3 file db for the test db, and spec_server all the
>>> specs on my models pass. If I use an in-memory db for the test db,
>>> script/spec w/o spec_server, they all pass. But if I use in- 
>>> memory and
>>> spec_server I get the following error:
>>> 1)
>>> ActiveRecord::StatementInvalid in 'User should be valid'
>>> ActiveRecord::StatementInvalid
>>> ./spec/models/user_spec.rb:5:in `new'
>>> ./spec/models/user_spec.rb:5:
>>> ./script/spec_server:23:in `run'
>>> ./script/spec_server:44:
>>>
>>> Line 5 is the User.new in the before clause.
>>>
>>> I have tried this on various versions of things. RSpec 1.0.5, Ubuntu
>>> 6.04, Rails 1.2.3,  Sqlite 3.2.8, sqlit3-ruby 1.2.1 (gem)
>>> And on Ubuntu 7.04, Sqlite 3.3.13
>>>
>>> Same results.
>>> Any ideas?
>>
>> I've had the same problem before, even using the in-memory plugin (by
>> Geoffrey Grosenbach).
>>
>> If my memory serves me right,  I believe that something like the
>> following is going on: the DRB server performs certain actions (like
>> creating the test database schema) only once.  Normally the test
>> database schema would be recreated after every Test::Unit class /
>> RSpec Behavior.  Since the database schema isn't recreated when using
>> the drb server, the in memory database no longer exists (go figure)
>> after a bit (say, after the first few specs), and Rails throws an
>> exception.
>>
>> I'd be interesting in seeing a full trace. Maybe we can get to the
>> bottom of this bug.
>
> Here it is:
> rspec -b spec/models/user_spec.rb
> F
>
> 1)
> ActiveRecord::StatementInvalid in 'User should be valid'
> ActiveRecord::StatementInvalid
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
> active_record/connection_adapters/sqlite_adapter.rb:360:in
> `table_structure'
> /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/ 
> active_support/core_ext/object/misc.rb:23:in
> `returning'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
> active_record/connection_adapters/sqlite_adapter.rb:359:in
> `table_structure'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
> active_record/connection_adapters/sqlite_adapter.rb:210:in
> `columns'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
> active_record/base.rb:763:in
> `columns'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
> active_record/base.rb:2060:in
> `attributes_from_column_definition_without_lock'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
> active_record/locking/optimistic.rb:45:in
> `attributes_from_column_definition'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
> active_record/base.rb:1502:in
> `initialize_without_callbacks'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ 
> active_record/callbacks.rb:225:in
> `initialize'
> ./spec/models/user_spec.rb:5:in `new'
> ./spec/models/user_spec.rb:5:
> ./script/../vendor/plugins/rspec/lib/spec/dsl/ 
> composite_proc_builder.rb:16:in
> `instance_eval'
> ./script/../vendor/plugins/rspec/lib/spec/dsl/ 
> composite_proc_builder.rb:16:in
> `proc'
> ./script/../vendor/plugins/rspec/lib/spec/dsl/ 
> composite_proc_builder.rb:11:in
> `collect'
> ./script/../vendor/plugins/rspec/lib/spec/dsl/ 
> composite_proc_builder.rb:11:in
> `proc'
> ./script/../vendor/plugins/rspec/lib/spec/dsl/example.rb:63:in  
> `instance_eval'
> ./script/../vendor/plugins/rspec/lib/spec/dsl/example.rb:63:in  
> `setup_example'
> ./script/../vendor/plugins/rspec/lib/spec/dsl/example.rb:22:in `run'
> /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout'
> ./script/../vendor/plugins/rspec/lib/spec/dsl/example.rb:21:in `run'
> ./script/../vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:77:in `run'
> ./script/../vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in  
> `each'
> ./script/../vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in `run'
> ./script/../vendor/plugins/rspec/lib/spec/runner/ 
> behaviour_runner.rb:45:in
> `run_behaviours'
> ./script/../vendor/plugins/rspec/lib/spec/runner/ 
> behaviour_runner.rb:44:in
> `each'
> ./script/../vendor/plugins/rspec/lib/spec/runner/ 
> behaviour_runner.rb:44:in
> `run_behaviours'
> ./script/../vendor/plugins/rspec/lib/spec/runner/ 
> behaviour_runner.rb:27:in
> `run'./script/../vendor/plugins/rspec/lib/spec/runner/ 
> command_line.rb:17:in
> `run'
> ./script/spec_server:23:in `run'
> /usr/local/lib/ruby/1.8/drb/drb.rb:1555:in `__send__'
> /usr/local/lib/ruby/1.8/drb/drb.rb:1555:in `perform_without_block'
> /usr/local/lib/ruby/1.8/drb/drb.rb:1515:in `perform'
> /usr/local/lib/ruby/1.8/drb/drb.rb:1589:in `main_loop'
> /usr/local/lib/ruby/1.8/drb/drb.rb:1585:in `loop'
> /usr/local/lib/ruby/1.8/drb/drb.rb:1585:in `main_loop'
> /usr/local/lib/ruby/1.8/drb/drb.rb:1581:in `start'
> /usr/local/lib/ruby/1.8/drb/drb.rb:1581:in `main_loop'
> /usr/local/lib/ruby/1.8/drb/drb.rb:1430:in `run'
> /usr/local/lib/ruby/1.8/drb/drb.rb:1427:in `start'
> /usr/local/lib/ruby/1.8/drb/drb.rb:1427:in `run'
> /usr/local/lib/ruby/1.8/drb/drb.rb:1347:in `initialize'
> /usr/local/lib/ruby/1.8/drb/drb.rb:1627:in `new'
> /usr/local/lib/ruby/1.8/drb/drb.rb:1627:in `start_service'
> ./script/spec_server:44:
>
> Finished in 0.009507 seconds
>
> 1 example, 1 failure
>
>
>
>
>
>
>
>
>
>
>
>>
>> Best,
>>
>> Scott
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>
>
> -- 
> Ed Howland
> http://greenprogrammer.blogspot.com
> "The information transmitted is intended only for the person or entity
> to which it is addressed and may contain proprietary, confidential
> and/or legally privileged material. Any review, retransmission,
> dissemination or other use of, or taking of any action in reliance
> upon, this information by persons or entities other than the intended
> recipient is prohibited. If you received this in error, please contact
> the sender and delete the material from all computers."
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list