Sha256: 99b8677e6def90557c03b0b400bdef5b4f82ee6a74a687cb2aa6bb7b5dac3717

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')

describe Attributor::String do

  subject(:type) { Attributor::String }

  context '.native_type' do
    it "returns String" do
      type.native_type.should be(::String)
    end
  end

  context '.example' do
    it "should return a valid String" do
      type.example(options:{regexp: /\w\d{2,3}/}).should be_a(::String)
    end

    it "should return a valid String" do
      type.example.should be_a(::String)
    end

    it 'handles regexps that Randexp can not (#72)' do
      regex = /\w+(,\w+)*/
      expect {
        val = Attributor::String.example(options:{regexp: regex})
        val.should be_a(::String)
      }.to_not raise_error
    end

  end

  context '.load' do
    let(:value) { nil }

    it 'returns nil for nil' do
      type.load(nil).should be(nil)
    end

    context 'for incoming String values' do

      it 'returns the incoming value' do
        ['', 'foo', '0.0', '-1.0', '1.0', '1e-10', 1].each do |value|
          type.load(value).should eq(String(value))
        end
      end
    end

  end

  context 'for incoming Symbol values' do
    let(:value) { :something }
    it 'returns the stringified-value' do
      type.load(value).should == value.to_s
    end
  end

  context 'for Enumerable values' do
    let(:value) { [1] }

    it 'raises IncompatibleTypeError' do
      expect {
        type.load(value)
      }.to raise_error(Attributor::IncompatibleTypeError)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
attributor-4.0.1 spec/types/string_spec.rb
attributor-4.0.0 spec/types/string_spec.rb
attributor-3.0.1 spec/types/string_spec.rb
attributor-3.0 spec/types/string_spec.rb