Sha256: ad3cdb1ce035ee15d8ed246ae4d4591f0c2c56d2ff229f95e4099a5b3e82c252

Contents?: true

Size: 1.28 KB

Versions: 14

Compression:

Stored size: 1.28 KB

Contents

require 'spec_helper'

try_spec do
  describe Ardm::Property::Regexp  do
    before do
      class ::User < Ardm::Record
        property :id, Serial
        property :regexp, Regexp
      end

      @property = User.properties[:regexp]
    end

    describe '.load' do
      describe 'when argument is a string' do
        before do
          @input  = '[a-z]\d+'
          @result = @property.load(@input)
        end

        it 'create a regexp instance from argument' do
          expect(@result).to eq(Regexp.new(@input))
        end
      end

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

        it 'returns nil' do
          expect(@result).to be_nil
        end
      end
    end

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

        it 'escapes the argument' do
          expect(@result).to eq('\\d+')
        end
      end

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

        it 'returns nil' do
          expect(@result).to be_nil
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ardm-0.4.0.ar427 spec/unit/regexp_spec.rb
ardm-0.4.0 spec/unit/regexp_spec.rb
ardm-0.3.2 spec/unit/regexp_spec.rb
ardm-0.3.1 spec/unit/regexp_spec.rb
ardm-0.3.0 spec/unit/regexp_spec.rb
ardm-0.2.7 spec/unit/regexp_spec.rb
ardm-0.2.6 spec/unit/regexp_spec.rb
ardm-0.2.5 spec/unit/regexp_spec.rb
ardm-0.2.4 spec/unit/regexp_spec.rb
ardm-0.2.3 spec/unit/regexp_spec.rb
ardm-0.2.2 spec/unit/regexp_spec.rb
ardm-0.2.1 spec/unit/regexp_spec.rb
ardm-0.2.0 spec/unit/regexp_spec.rb
ardm-0.1.0 spec/unit/regexp_spec.rb