【问题标题】:getting the object passed as an argument to a stubbed method with Mocha使用 Mocha 将对象作为参数传递给存根方法
【发布时间】:2011-07-03 20:52:11
【问题描述】:
Foo.expects(:bar)
Foo.bar(:abc => 123, :xyz => 987)

# assert Foo.bar was called with a hash that has a key of :abc == 123

基本上,我想检查作为参数传递给存根方法的对象,以便检查该对象的值。在我的情况下,我不能使用Foo.expects(:bar).with({:abc => 123}),因为我知道对象不会彼此相等。我只想比较参数的子值。

这当然是可能的,我只是在这里找不到语法或策略。

【问题讨论】:

    标签: ruby mocking stubbing ruby-mocha


    【解决方案1】:

    我想通了!原来with 可以阻止。

    Foo.expects(:bar).with do |the_hash|
      the_hash[:abc] == 123
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 2015-11-22
      • 2019-11-27
      • 2020-06-05
      • 2012-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多