Skip to content

Instantly share code, notes, and snippets.

@petervandenabeele
Created January 4, 2012 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petervandenabeele/1559937 to your computer and use it in GitHub Desktop.
Save petervandenabeele/1559937 to your computer and use it in GitHub Desktop.
Rspec with spork (pre-loaded) 400 examples mysql, postgresql, sqlite3
So, sqlite3 was not really running _in-memory_ here
(thanks @xavierdefrang for the hat tip).
At the bottom I document what I did to try to get it
running in-memory.
~/b$ # with mysql 5.1.58
~/b$ time rspec spec
................................................................................................................................................................................................................................................................................................................................................................................................................
Finished in 22.48 seconds
400 examples, 0 failures
real 0m8.779s
user 0m0.352s
sys 0m0.060s
~/b$ time rspec spec
................................................................................................................................................................................................................................................................................................................................................................................................................
Finished in 55.13 seconds
400 examples, 0 failures
real 0m8.563s
user 0m0.348s
sys 0m0.056s
~/b$ # with postgresql 9.1.1
~/b$ time rspec spec
................................................................................................................................................................................................................................................................................................................................................................................................................
Finished in 23.32 seconds
400 examples, 0 failures
real 0m5.786s
user 0m0.352s
sys 0m0.056s
~/b$ time rspec spec
................................................................................................................................................................................................................................................................................................................................................................................................................
Finished in 31.07 seconds
400 examples, 0 failures
real 0m5.690s
user 0m0.348s
sys 0m0.048s
~/b$
~/b$ # with sqlite 3.7.7
~/b$ time rspec spec
................................................................................................................................................................................................................................................................................................................................................................................................................
Finished in 31.64 seconds
400 examples, 0 failures
real 0m5.534s
user 0m0.376s
sys 0m0.052s
~/b$ time rspec spec
................................................................................................................................................................................................................................................................................................................................................................................................................
Finished in 39.09 seconds
400 examples, 0 failures
real 0m5.442s
user 0m0.368s
sys 0m0.060s
~/b$
# trying to get use sqlite3 with real in-memory database
for testing with rspec and spork (did not fully work :-/)
~/b/config/initializers$ cat ../database.yml
test:
adapter: sqlite3
pool: 5
timeout: 5000
database: ":memory:"
~/b/config/initializers$ cat test_sqlite3_in_memory.rb
def in_memory_database?
if (ENV["RAILS_ENV"] == "test")
ActiveRecord::Base.establish_connection
(ActiveRecord::Base.connection.class == ActiveRecord::ConnectionAdapters::SQLite3Adapter) &&
(Rails.configuration.database_configuration['test']['database'] == ':memory:')
end
end
if in_memory_database?
puts "creating sqlite in memory database"
# load "#{RAILS_ROOT}/db/schema.rb" # use db agnostic schema by default
ActiveRecord::Migrator.up('db/migrate') # use migrations
end
~/b/config/initializers$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment