我正在運行到一個磚牆測試類重定義,只是不知道如何處理它。下面是我測試的情況(這不是核心數據):Ruby運動:從對象空間完全刪除一個Ruby類
- 應用與模型版本上運行1級
- 熱切的程序員通過添加/刪除/重定義列
- 應用程序運行時修改模型在第2版
模型在那裏我遇到了問題,在模擬實際刪除從內存的應用程序,並從頭開始吧重建。這很重要,因爲當包含MotionModel::Model
模塊時,會建立許多與模型有關的事情,並且只會發生一次:模塊包含在類中時。以下是我覺得可能工作:
it "column removal" do
class Removeable
include MotionModel::Model
columns :name => :string, :desc => :string
end
@foo = Removeable.create(:name=> 'Bob', :desc => 'who cares anyway?')
Removeable.serialize_to_file('test.dat')
@foo.should.respond_to :desc
Object.send(:remove_const, :Removeable) # Should remove all traces of Removeable
class Removeable
include MotionModel::model # Should include this again instead
columns :name => :string, # of just reopening the old Removeable
:address => :string # class
end
Removeable.deserialize_from_file # Deserialize old data into new model
Removeable.length.should == 1
@bar = Removeable.first
@bar.should.respond_to :name
@bar.should.respond_to :address
@bar.should.not.respond_to :desc
@bar.name.should == 'Bob'
@bar.address.should == nil
end
end
不幸的是,Object.send(:remove_const, :Removeable)
沒有做什麼,我所願,和Ruby只是認爲它可以重新打開Removeable
,而不是運行MotionModel::Model
模塊的self.included()
方法。
關於如何在規範示例的上下文中從頭開始模擬創建此類的任何想法?
可能是一個愚蠢的建議,但你試過一個字符串,而不是一個符號? 「可移動」? –
我使用Object.send(:remove_const,:Foo)if defined?(Foo)'在我對MotionModel的提交中很好,也許這不再是問題? RubyMotion緩存修復的1.35版本可能已經解決了這個問題。 – aceofspades