我正在尝试使用RSpec模拟和should_receive自定义匹配器.我想捕获由should_receive匹配器返回正确值导致的错误,并导致它输出我的自定义失败消息.
怎么做?或许我应该改变我的做法?
catch在Ruby中意味着跳出深层嵌套的代码.在Java中,例如可以用Java try-catch来处理异常,但它被认为是不好的解决方案,而且效率也非常低.在Ruby中我们处理异常begin-raise-rescue,我认为将它用于其他任务也很昂贵.
Ruby是否catch-throw真的是一个更有效的解决方案,begin-raise-rescue还是有任何其他理由使用它来打破嵌套块而不是begin-raise-rescue?
我有一个通用的抽象类(SuperClass).我希望有一个main方法,它将是每个子类的默认主要方法,并且会做同样的事情,但是使用适当的子类对象派生并调用它.
像这样:
public abstract class SuperClass {
// some code here...
public static void main(String args[]) {
// here instantiate the subclass
// extending this SuperClass, and call
// some methods
}
}
public SubClass extends SuperClass {
// here just implement some
// abstract methods from SupeClass
// and NOT implement main()
}
Run Code Online (Sandbox Code Playgroud)
现在我希望能够运行SubClass独立程序,执行默认main派生程序SuperClass.如何SubClass在main方法中实例化适当的对象?
SuperClass我不知道实际的名字SubClassSubClass从实现的静态方法SuperClass(从超类中的一个子类中获取名称) …