Sha256: 0c4f149c509824274be37a87901f7575e8e552a26c07b949593171c4beaae3de

Contents?: true

Size: 1.31 KB

Versions: 13

Compression:

Stored size: 1.31 KB

Contents

require 'spec_helper'

try_spec do
  describe DataMapper::Property::Regexp  do
    before :all do
      class ::User
        include DataMapper::Resource
        property :id, Serial
        property :regexp, Regexp
      end

      @property = User.properties[:regexp]
    end

    describe '.load' do
      describe 'when argument is a string' do
        before :all do
          @input  = '[a-z]\d+'
          @result = @property.load(@input)
        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 = @property.load(@input)
        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 = @property.dump(@input)
        end

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

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

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

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
ardm-types-1.2.3 spec/unit/regexp_spec.rb
ardm-types-1.2.2 spec/unit/regexp_spec.rb
dm-types-1.2.2 spec/unit/regexp_spec.rb
dm-types-1.2.1 spec/unit/regexp_spec.rb
dm-types-1.2.0 spec/unit/regexp_spec.rb
dm-types-1.2.0.rc2 spec/unit/regexp_spec.rb
dm-types-1.2.0.rc1 spec/unit/regexp_spec.rb
dm-types-1.1.0 spec/unit/regexp_spec.rb
dm-types-1.1.0.rc3 spec/unit/regexp_spec.rb
dm-types-1.1.0.rc2 spec/unit/regexp_spec.rb
dm-types-1.1.0.rc1 spec/unit/regexp_spec.rb
dm-types-1.0.2 spec/unit/regexp_spec.rb
dm-types-1.0.1 spec/unit/regexp_spec.rb