小编wrz*_*asa的帖子

自定义匹配器中的rspec mock should_receive

我正在尝试使用RSpec模拟和should_receive自定义匹配器.我想捕获由should_receive匹配器返回正确值导致的错误,并导致它输出我的自定义失败消息.

怎么做?或许我应该改变我的做法?

rspec mocking match

5
推荐指数
1
解决办法
639
查看次数

红宝石的投掷和效率

catch在Ruby中意味着跳出深层嵌套的代码.在Java中,例如可以用Java try-catch来处理异常,但它被认为是不好的解决方案,而且效率也非常低.在Ruby中我们处理异常begin-raise-rescue,我认为将它用于其他任务也很昂贵.

Ruby是否catch-throw真的是一个更有效的解决方案,begin-raise-rescue还是有任何其他理由使用它来打破嵌套块而不是begin-raise-rescue

ruby performance try-catch control-structure throw

5
推荐指数
2
解决办法
1183
查看次数

从超类static main创建子类

我有一个通用的抽象类(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.如何SubClassmain方法中实例化适当的对象?

  • 我不能做新的因为SuperClass我不知道实际的名字SubClass
  • 使用反射它,我不能这样做,因为我无法得到的名字SubClass从实现的静态方法SuperClass(从超类中的一个子类中获取名称) …

java methods static instantiation derived-class

3
推荐指数
1
解决办法
2413
查看次数