Sha256: 95a2693f1e8c1ed80477d49a2698fa6f8082636874dd31c27d65f8dd365c98a9

Contents?: true

Size: 1.84 KB

Versions: 16

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

RSpec::Matchers.define :be_int32 do |num|
  match do |actual|
    actual == [num].pack('l<')
  end
end

RSpec::Matchers.define :be_int64 do |num|
  match do |actual|
    actual == [num].pack('q<')
  end
end

RSpec::Matchers.define :be_int64_sequence do |array|
  match do |actual|
    actual == array.reduce(String.new) do |buffer, num|
      buffer << [num].pack('q<')
    end
  end
end

RSpec::Matchers.define :be_cstring do |string|
  match do |actual|
    actual == "#{string.dup.force_encoding(BSON::BINARY)}\0"
  end
end

RSpec::Matchers.define :be_bson do |hash|
  match do |actual|
    actual == hash.to_bson.to_s
  end
end

RSpec::Matchers.define :be_bson_sequence do |array|
  match do |actual|
    actual == array.map(&:to_bson).join
  end
end

RSpec::Matchers.define :be_ciphertext do
  match do |object|
    object.is_a?(BSON::Binary) && object.type == :ciphertext
  end
end


RSpec::Matchers.define :match_with_type do |event|
  match do |actual|
    Utils.match_with_type?(event, actual)
  end
end

RSpec::Matchers.define :be_uuid do
  match do |object|
    object.is_a?(BSON::Binary) && object.type == :uuid
  end
end

RSpec::Matchers.define :take_longer_than do |min_expected_time|
  match do |proc|
    start_time = Time.now
    proc.call
    (Time.now - start_time).should > min_expected_time
  end
end

RSpec::Matchers.define :take_shorter_than do |min_expected_time|
  match do |proc|
    start_time = Time.now
    proc.call
    (Time.now - start_time).should < min_expected_time
  end
end

RSpec::Matchers.define :be_explain_output do
  match do |actual|
    Hash === actual && (
      actual.key?('queryPlanner') ||
      actual.key?('allPlans')
    )
  end

  failure_message do |actual|
    "expected that #{actual} is explain output: is a hash with either allPlans or queryPlanner keys present"
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
mongo-2.16.4 spec/support/matchers.rb
mongo-2.17.4 spec/support/matchers.rb
mongo-2.18.3 spec/support/matchers.rb
mongo-2.18.2 spec/support/matchers.rb
mongo-2.17.3 spec/support/matchers.rb
mongo-2.18.1 spec/support/matchers.rb
mongo-2.18.0 spec/support/matchers.rb
mongo-2.17.2 spec/support/matchers.rb
mongo-2.16.3 spec/support/matchers.rb
mongo-2.18.0.beta1 spec/support/matchers.rb
mongo-2.16.2 spec/support/matchers.rb
mongo-2.17.1 spec/support/matchers.rb
mongo-2.16.1 spec/support/matchers.rb
mongo-2.17.0 spec/support/matchers.rb
mongo-2.16.0 spec/support/matchers.rb
mongo-2.16.0.alpha1 spec/support/matchers.rb