Sha256: 2d97aa32706f209fd48f652037f7160d43bced4f3036aa30f4da692fef6ced54

Contents?: true

Size: 1.31 KB

Versions: 43

Compression:

Stored size: 1.31 KB

Contents

module BsonMatchers
  class BeBsonEql
    def initialize(expected)
      @expected = expected
    end

    def matches?(target)
      @target = target
      @target == @expected
    end

    def failure_message
      "expected\...#{@target.inspect}\n" +
      "to be BSON code equivalent to\...#{@expected.inspect}\n" +
      "Difference:\...#{@expected.diff(@target).inspect}"
    end

    def negative_failure_message
      "expected\...#{@target.inspect}\n" +
      "to be BSON code different from\...#{@expected.inspect}"
    end
  end

  class BeMongoEql
    def initialize(expected, include_id)
      @include_id = include_id
      @expected = include_id ? expected : expected.except('_id')
    end

    def matches?(target)
      @target = @include_id ? target : target.except('_id')
      @target == @expected
    end

    def failure_message
      "expected\...#{@target.inspect}\n" +
      "to be BSON code equivalent to\...#{@expected.inspect}\n" +
      "Difference:\...#{@expected.diff(@target).inspect}"
    end

    def negative_failure_message
      "expected\...#{@target.inspect}\n" +
      "to be BSON code different from\...#{@expected.inspect}"
    end
  end

  def be_bson_eql(expected)
    BeBsonEql.new(expected)
  end

  def be_mongo_eql(expected, include_id = true)
    BeMongoEql.new(expected, include_id)
  end
end

Version data entries

43 entries across 43 versions & 3 rubygems

Version Path
mongo_doc-0.6.26 spec/bson_matchers.rb
mongo_doc-0.6.25 spec/bson_matchers.rb
mongo_doc-0.6.23 spec/bson_matchers.rb
mongo_doc-0.6.22 spec/bson_matchers.rb
mongo_doc-0.6.21 spec/bson_matchers.rb
mongo_doc-0.6.20 spec/bson_matchers.rb
mongo_doc-0.6.19 spec/bson_matchers.rb
mongo_doc-0.6.18 spec/bson_matchers.rb
mongo_doc-0.6.17 spec/bson_matchers.rb
mongo_doc-0.6.16 spec/bson_matchers.rb
mongo_doc-0.6.15 spec/bson_matchers.rb
mongo_doc-0.6.14 spec/bson_matchers.rb
mongo_doc-0.6.13 spec/bson_matchers.rb
mongo_doc-0.6.12 spec/bson_matchers.rb
mongo_doc-0.6.11 spec/bson_matchers.rb
mongo_doc-0.6.10 spec/bson_matchers.rb
mongo_doc-0.6.9 spec/bson_matchers.rb
mongo_doc-0.6.8 spec/bson_matchers.rb
mongo_doc-0.6.7 spec/bson_matchers.rb
mongo_doc-0.6.6 spec/bson_matchers.rb