Sha256: d7559aa811ab5598a08335706c69c978122d9d3ab033d323af59a96fc2a28903

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

try_spec do
  describe DataMapper::Types::Regexp  do
    describe '.load' do
      describe 'when argument is a string' do
        before :all do
          @input  = '[a-z]\d+'
          @result = DataMapper::Types::Regexp.load(@input, :property)
        end

        it 'create a regexp instance from argument' do
          @result.should == Regexp.new(@input)
        end
      end

      describe 'when argument is nil' do
        before :all do
          @input  = nil
          @result = DataMapper::Types::Regexp.load(@input, :property)
        end

        it 'returns nil' do
          @result.should be_nil
        end
      end
    end

    describe '.dump' do
      describe 'when argument is a regular expression' do
        before :all do
          @input  = /\d+/
          @result = DataMapper::Types::Regexp.dump(@input, :property)
        end

        it 'escapes the argument' do
          @result.should == '\\d+'
        end
      end

      describe 'when argument is nil' do
        before :all do
          @input = nil
          @result = DataMapper::Types::Regexp.dump(@input, :property)
        end

        it 'returns nil' do
          @result.should be_nil
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dm-types-0.10.2 spec/unit/regexp_spec.rb
dm-types-0.10.1 spec/unit/regexp_spec.rb
dm-types-0.10.0 spec/unit/regexp_spec.rb