是否可以暂时将某些方法应用于某个类进行测试?我希望能够运行规格取决于许多方式来应用它。虽然我可以制作一系列不同设置的灯具,但我发现在测试中只需要模型class_eval
。例如:您如何临时“class_eval”进行测试?
describe "some context"
before do
Page.class_eval do
my_applying_method :some => :option
end
end
it "should..."
end
然后在另一个上下文块:
describe "another context without the gem applied"
before do
Page.class_eval do
# nothing here since I want to page to be as is
end
end
it "should do something else..."
end
但问题与上次上下文块是它有经修饰的类(在上面的上下文块修改)。 是否可以在class_eval
之后重置班级?怎么样?
谢谢!
我啊'include'用'some_applying_method'其他模块。就像一个典型的插件。谢谢,这将有助于! – 2011-05-23 01:19:38