【问题标题】:What does #equal_set do in Rspec?#equal_set 在 Rspec 中做了什么?
【发布时间】:2017-08-25 16:19:35
【问题描述】:

我尝试在网上查找,但在 equal_set 上找不到任何关于 Rspec 的内容。我知道它是用来测试序列化程序的,但就是这样。

【问题讨论】:

  • 我认为它不是正式的 RSpec 的一部分。它可能是您的代码库正在使用的自定义匹配器,或者来自另一个已安装 gem 的 RSpec 助手。我猜它就像match_array,但将被比较的数组视为一组独特的元素。

标签: ruby-on-rails rspec serialization


【解决方案1】:

它被用在 gem peck-on-rails 中,它是 Peck 的扩展,使测试 Rails 更容易。 Peck 是一个并发规范框架。

下面是equal_set方法,参考here

def equal_set(*others)
  left, right = @this, others
  left.flatten! if left.respond_to?(:flatten)
  right.flatten! if right.respond_to?(:flatten)

  message = "Expected sets to be #{!@negated ? 'equal' : 'unequal'}: #{left.inspect} - #{right.inspect}"
  satisfy(message) { Set.new(left) == Set.new(right) }
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-09
    • 2010-11-29
    • 2014-08-03
    • 2012-02-12
    • 2010-10-26
    • 2019-07-12
    • 2010-11-20
    • 2011-07-24
    相关资源
    最近更新 更多