我想按照这些思路在 RSpec 测试期间创建一个 DataMapper 模型。但是如何从 RSpec 测试中创建底层 temp_models 表?
require 'spec_helper'
class TempModel
include DataMapper::Resource
property :id, Serial
property :foo, String
end
describe "MyTests" do
before(:all) do
# what goes here to create the table and finalize the model?
end
after(:all) do
# what goes here to drop the table?
end
before(:each) do
TempModel.destroy!
end
it 'creates a TempModel' do
expect { TempModel.create(:foo => "yowza")}.to_not raise_error
end
end
所以,就像代码说的那样,我应该在before(:all)
块中添加什么来在数据库中创建表并创建 DataMapper 模型?并在after(:all)
块中删除表?
更新
或者,如何创建“本地迁移”并对其执行上下移动?