ruby 定制匹配器以确定公共活动

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 定制匹配器以确定公共活动相关的知识,希望对你有一定的参考价值。

RSpec::Matchers.define :log_activity do |options|

  match do |actual|
    trackable = []
    if options[:trackable_id] || [:trackable_type]
      trackable << "trackable_id = #{options[:trackable_id]}" if options[:trackable_id]
      trackable << "trackable_type = #{options[:trackable_type]}" if options[:trackable_type]
      trackable.join(" AND ") if options[:trackable_id] && options[:trackable_type]
    end

    owner = []
    if options[:owner_id] || [:owner_type]
      owner << "owner_id = #{options[:owner_id]}" if options[:owner_id]
      owner << "owner_type = #{options[:owner_type]}" if options[:owner_type]
      owner.join(" AND ") if options[:owner_id] && options[:owner_type]
    end

    recipient = []
    if options[:recipient_id] || [:recipient_type]
      recipient << "owner_id = #{options[:recipient_id]}" if options[:recipient_id]
      recipient << "owner_type = #{options[:recipient_type]}" if options[:recipient_type]
      recipient.join(" AND ") if options[:recipient_id] && options[:recipient_type]
    end

    query = []
    query << trackable unless trackable.empty?
    query << owner unless owner.empty?
    query << recipient unless recipient.empty?
    query.flatten.join(" OR ")

    pa = PublicActivity::Activity.where(query)
    pa.count >= 1
  end

  failure_message do |actual|
    "expected to log an activity but did not"
  end

  failure_message_when_negated do |actual|
    "expected to not log an activity"
  end

  description do
    "logs an activity"
  end
end

以上是关于ruby 定制匹配器以确定公共活动的主要内容,如果未能解决你的问题,请参考以下文章

Select2 自定义匹配器以在组标题匹配时保持选项打开

更新接口构建器以匹配约束

太阳女神Miss Ruby生日Party

Appium给出'错误:运行测试时意图匹配多个活动

确定公共 WiFi 是不是具有网络连接

如何在 spark-submit 之前触发催化剂优化器以减少执行时间?