[rspec-users] Examples not getting rolled back...
David Chelimsky
dchelimsky at gmail.com
Thu Jan 8 08:37:38 EST 2009
On Thu, Jan 8, 2009 at 3:56 AM, Tero Tilus <tero at tilus.net> wrote:
> Forgot to mention before. I'm on Rails 2.2.2 and RSpec 1.1.4.
Aha! There's the problem. RSpec-1.1.4 was released in May and Rails
2.2.2 was released AFTER in November.
I'd grab the 1.1.12 release candidates from github:
gem sources -a http://gems.github.com
[sudo] gem install dchelimsky-rspec
[sudo] gem install dchelimsky-rspec-rails
Cheers,
David
>
> Inspired by older discussion touching this issue (see
> http://www.nabble.com/Database-clearing-td19572270.html) I've now got
>
> Spec::Runner.configure do |config|
> config.use_transactional_fixtures = false
> ...
> tables_to_truncate =
> ActiveRecord::Base.connection.tables - ["schema_migrations"]
> config.before(:all) do
> tables_to_truncate.each do |table_name|
> ActiveRecord::Base.connection.execute("TRUNCATE TABLE
> #{table_name};")
> end
> end
> ...
> end
>
> And if I run rake spec all specs pass. But if I run script/spec
> spec/models/class_foo_spec.rb then
>
> it "finds no ghost foos" do
> ClassFoo.should have(:no).records
> end
>
> fails. That is the first example of describe ClassFoo. Looks like
> script/spec runs examples (see pastie http://pastie.org/354521) in the
> order they are defined and rake spec in reverse order. And that of
> course makes ClassFoo.should have(:no).records fail when run _after_
> examples that create ClassFoo instances (befause ive got transactions
> off and the db state "bleeds" within one describe.
>
> 2009-01-07 16:11, Tero Tilus:
>> I'm keep getting the following kind of pattern in my logs
>>
>> ... log from example starts here ...
>> SQL (0.0ms) BEGIN
>> SQL (0.0ms) BEGIN
>> ClassFoo Create (0.2ms) INSERT ...
>> Group Load (0.4ms) SELECT ...
>> Contains Create (0.2ms) INSERT ...
>> ... other stuff from example, no transaction stuff ...
>> SQL (1.9ms) COMMIT
>> SQL (0.1ms) ROLLBACK
>> ... log from example ends here ...
>
> If I turn use_transactional_fixtures off, the outer transaction is
> gone.
>
> --
> Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
More information about the rspec-users
mailing list