As a learning exercise, I am building a practice app using Sinatra, Datamapper and RSpec. I am using this template, which is basically a boilerplate for all the above.
The problem I am having is that the way RSpec and Datamapper seem to be configured, every time a spec is run that tests Database related functionality, those tests directly change my development database instead of a test database.
For example, I wish to create a few database objects before running the rest of the spec...
before(:all) {
Region.new(:country => "Canada", :country_code => "CA").save
ProductLine.new(:reference => "Molders").save
Product.new(:name => "The Black Molder").save
Cart.new(:price => 25.95).save
}
Yet every time I run RSpec, the above elements get added to my development database.
Why isn't a test database being generated instead? How can I get the test database to work properly?
This appears pretty similar to this issue here, except for Sinatra instead of Rails.
If it's any help, my code can be seen here.
ENV['RACK_ENV'] = 'test'
in various places and getting frustrated as to why it wasn't picking it up - after reading your answer I put it at the top ofspec_helper.rb
beforerequire 'sinatra'
and now it works! – Pestilential