Sha256: 26cd53b8ee436837903a35150b521f5e2aa1c30eee932f2ef27db727e33aff9d

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 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('^Em')
      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
        /^Em/
      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

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-5.4.1 spec/mongoid/matchable/regexp_spec.rb
mongoid-5.4.0 spec/mongoid/matchable/regexp_spec.rb
mongoid-5.2.1 spec/mongoid/matchable/regexp_spec.rb