Monday, July 12, 2010

[Rails] How to run unit tests w/o first blowing away test db?

The documentation on fixtures makes a tantalizing claim:

| If you preload your test database with all fixture data
| (probably in the Rakefile task) and use transactional
| fixtures, then you may omit all fixtures declarations
| in your test cases since all the data's already there
| and every case rolls back its changes.

Yup! That's exactly what I want: I have some LARGE constant tables that
are used pervasively, so I want to load them ONCE and exploit the
efficiency of transactional fixtures thereafter. I know I can preload
the test database from fixtures like this:

% rake db:fixtures:load RAILS_ENV=test

But then how do I run unit tests while preserving my carefully preloaded
data?

- ff

[some details...]

I know I can't simply use 'rake test:units', defined as:

Rake::TestTask.new(:units => "db:test:prepare") do |t|
t.libs << "test"
t.pattern = 'test/unit/**/*_test.rb'
t.verbose = true
end
Rake::Task['test:units'].comment = "Run the unit tests in test/unit"

The dependency on "db:test:prepare" clears the database. I could define
a rake task "test:units_without_blowing_away_my_data_please" that
eliminates that dependency, or perhaps better, a define a task that
loads the fixtures before running the unit tests.

But the comment in the fixture documentation makes me think that there's
an easier way. Is there?
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate