当前位置 : 主页 > 编程语言 > ruby >

ruby – 在RSpec中检查方法调用参数double的测试

来源:互联网 收集:自由互联 发布时间:2021-06-23
是否可以检查传递给方法调用参数的参数是否满足某些约束.我想做点什么 my_double = double("MyObject")my_double.should_receive(:mocked_method).with{ something that has an attribute called name and value "john" } 非常
是否可以检查传递给方法调用参数的参数是否满足某些约束.我想做点什么

my_double = double("MyObject")
my_double.should_receive(:mocked_method).with{ <something that has an attribute called name and value "john"> }

非常感谢提前.

编辑:我会尝试澄清一下我想要完成的事情

我想要的是检查模拟的给定方法是否被调用传递满足某些条件的对象

作为记录.我想要完成的是什么

@test_double.should_receive(:send_mail) do |mail|
    mail.to.should eq(["john@aol.com"])
    mail.body.decoded.should include "Error"
  end

并且代码应该使用满足块中指定条件的参数调用给定对象的方法send_mail.

网友评论