是否可以暂时将某些方法应用于类进行测试?我希望能够根据多种应用方式来运行规范。虽然我可以制作一堆具有不同设置的夹具,但我发现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
吗?如何?
谢谢!