I've been using the NullDb (<a href="http://agilewebdevelopment.com/plugins/nulldb">http://agilewebdevelopment.com/plugins/nulldb</a>) plugin to disconnect RSpec from the database.<br><br>I don't like the global disconnect (for all specs everywhere) that the web page suggests, so I set up this in my spec_helper:<br>
<br>describe "Unit Spec", :shared => true do<br>
before :all do<br>
ActiveRecord::Base.establish_connection(:adapter => :nulldb)<br>
end<br>
<br>
after :all do<br>
ActiveRecord::Base.establish_connection(:test)<br>
end<br>
end<br><br>and then say this inside any describe block I want to disconnect from the db:<br><br>require File.dirname(__FILE__) + "/../spec_helper"<br><br>describe User do<br> it_should_behave_like "Unit Spec"<br>
.<br>.<br>.<br><br>using nested describes to separate my unit (don't hit the db) from my functional (do hit the db) specs<br><br>-Jake <br><br><div class="gmail_quote">On Wed, Jun 11, 2008 at 8:37 AM, Ryan Platte <<a href="mailto:ryan@platte.name">ryan@platte.name</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>Here are some Rake tasks I created to use RSpec with UnitRecord. I set the default task to first run spec:fast, then spec:slow, so if the fast ones fail we don't have to wait on the slow ones to set up and run.</div>
<div><br></div><div>The fly in the ointment is that schema.rb has to be current.</div><div><br></div><div>namespace :spec do</div><div><br></div><div> desc "Run all fast specs in spec directory (excluding plugin specs)"</div>
<div> Spec::Rake::SpecTask.new(:fast) do |t|</div><div> t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]</div><div> t.spec_files = FileList['spec/**/*_fast_spec.rb']</div>
<div> #t.ruby_opts = ['-r spec/spec_helper', '-rubygems', '-runit_record', "-e 'ActiveRecord::Base.disconnect!'"]</div><div> end</div><div><br></div><div> desc "Run all non-fast specs in spec directory (excluding plugin specs)"</div>
<div> Spec::Rake::SpecTask.new(:slow => spec_prereq) do |t|</div><div> t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]</div><div> t.spec_files = FileList['spec/**/*_spec.rb'].exclude('spec/**/*_fast_spec.rb')</div>
<div> end</div><div><br></div><div>end</div><div><div></div><div class="Wj3C7c"><div><br></div><br><div class="gmail_quote">On Wed, Jun 11, 2008 at 1:36 AM, David Chelimsky <<a href="mailto:dchelimsky@gmail.com" target="_blank">dchelimsky@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Jun 9, 2008, at 11:31 PM, David Chelimsky wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hey Chirb,<div><br>
<br>
Lastly, I may have mis-spoke about rails loading up columns from schema.rb - I'm looking into it and will follow up when I learn the truth. So Ryan - keep using unit-record for now :)<br>
</div></blockquote>
<br>
I definitely mis-spoke. I don't know where I got that in my head, but it seems I did.<br>
<br>
I don't recall who said it, but unit_record does the column caching I thought rails did. So now it's off to figure out how to get rspec to play nice w/ unit_record.<br>
<br>
More soon.<div><div></div><div><br>
<br>
Cheers,<br>
David<br>
_______________________________________________<br>
<a href="mailto:ChicagoGroup-Members-List@rubyforge.org" target="_blank">ChicagoGroup-Members-List@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/chicagogroup-members-list" target="_blank">http://rubyforge.org/mailman/listinfo/chicagogroup-members-list</a><br>
</div></div></blockquote></div><br><br clear="all"><br></div></div>-- <br><font color="#888888">Ryan Platte
</font><br>_______________________________________________<br>
<a href="mailto:ChicagoGroup-Members-List@rubyforge.org">ChicagoGroup-Members-List@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/chicagogroup-members-list" target="_blank">http://rubyforge.org/mailman/listinfo/chicagogroup-members-list</a><br></blockquote></div><br>