I needed to create a temporary model and its backing store for RSpec testing in order to test an acts_as_xxx module I've written. After digging around the sources for a while, I came up with the following solution. (NB: This is cross posted from Stack Overflow, but I thought it would make a useful mini-tutorial.)
require 'spec_helper' class TempModel include DataMapper::Resource property :id, Serial property :name, String end describe "MyTests" do before(:all) do # Create the temp_models db table and finalize the model DataMapper.auto_upgrade! TempModel.finalize end after(:all) do # drop the temp_models table adapter = DataMapper.repository(:default).adapter adapter.execute("DROP TABLE #{TempModel.storage_name}") end before(:each) do # assure an empty table before each test TempModel.destroy! end it 'creates a TempModel' do expect { TempModel.create(:name => "yowza")}.to_not raise_error end end -- You received this message because you are subscribed to the Google Groups "DataMapper" group. To unsubscribe from this group and stop receiving emails from it, send an email to datamapper+unsubscr...@googlegroups.com. To post to this group, send email to datamapper@googlegroups.com. Visit this group at http://groups.google.com/group/datamapper?hl=en. For more options, visit https://groups.google.com/groups/opt_out.