Sha256: a8ce366a37b8a0ff0f2a77151571ad44073e54c9684c878f2b21d477468ecaca

Contents?: true

Size: 1.29 KB

Versions: 10

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

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

10 entries across 10 versions & 2 rubygems

Version Path
mongoid-7.1.11 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.1.10 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.1.9 spec/mongoid/matchable/regexp_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/spec/mongoid/matchable/regexp_spec.rb
mongoid-7.1.8 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.1.7 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.1.6 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.1.5 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.1.4 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.1.2 spec/mongoid/matchable/regexp_spec.rb