Sha256: 86eb5e2e79b8e411de6986241583730104906c72a63e60ac902a05d2478f28cd

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

require "spec_helper"

describe Mongoid::Matchable::Regexp do

  let(:matcher) do
    described_class.new(attribute)
  end

  let(:attribute) do
    'Emily'
  end

  describe '#_matches?' do

    context 'when a BSON::Regexp::Raw object is passed' do

      let(:regexp) do
        BSON::Regexp::Raw.new("\\AEm")
      end

      it 'compiles the regexp object to a native regexp for the matching' do
        expect(matcher._matches?(regexp)).to be(true)
      end

      context 'when the value does not match the attribute' do

        let(:attribute) do
          'ily'
        end

        it 'compiles the regexp object to a native regexp for the matching' do
          expect(matcher._matches?(regexp)).to be(false)
        end
      end
    end

    context 'when a native Regexp object is passed' do

      let(:regexp) do
        /\AEm/
      end

      it 'calls super with the native regexp' do
        expect(matcher._matches?(regexp)).to be(true)
      end

      context 'when the value does not match the attribute' do

        let(:attribute) do
          'ily'
        end

        it 'compiles the regexp object to a native regexp for the matching' do
          expect(matcher._matches?(regexp)).to be(false)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mongoid-7.0.13 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.0.12 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.0.11 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.0.10 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.0.8 spec/mongoid/matchable/regexp_spec.rb