Sha256: c3ef0208db6b9ce967d869e35a7731722087f4afd693aab002cf3e4ad17a31e1

Contents?: true

Size: 1.73 KB

Versions: 17

Compression:

Stored size: 1.73 KB

Contents

require 'spec_helper'

describe Acfs::Resource::Attributes::Boolean do
  subject { Acfs::Resource::Attributes::Boolean.new }

  describe '#cast' do
    it 'casts nil' do
      expect(subject.cast(nil)).to eq nil
    end

    it 'casts empty string to false' do
      expect(subject.cast('')).to eq nil
    end

    it 'casts blank string to false' do
      expect(subject.cast("  \t")).to eq nil
    end

    it 'preserves boolean values' do
      expect(subject.cast(false)).to eq false
      expect(subject.cast(true)).to eq true
    end

    it 'casts falsy values to false' do
      expect(subject.cast(false)).to eq false
      expect(subject.cast(0)).to eq false
      expect(subject.cast('0')).to eq false
      expect(subject.cast('no')).to eq false
      expect(subject.cast('NO')).to eq false
      expect(subject.cast('off')).to eq false
      expect(subject.cast('OFF')).to eq false
      expect(subject.cast('false')).to eq false
      expect(subject.cast('FALSE')).to eq false
      expect(subject.cast('f')).to eq false
      expect(subject.cast('F')).to eq false
    end

    it 'casts any other value to true' do
      expect(subject.cast(true)).to eq true
      expect(subject.cast(1)).to eq true
      expect(subject.cast('1')).to eq true
      expect(subject.cast('yes')).to eq true
      expect(subject.cast('YES')).to eq true
      expect(subject.cast('on')).to eq true
      expect(subject.cast('ON')).to eq true
      expect(subject.cast('true')).to eq true
      expect(subject.cast('TRUE')).to eq true
      expect(subject.cast('t')).to eq true
      expect(subject.cast('T')).to eq true

      expect(subject.cast(2)).to eq true
      expect(subject.cast('wrong')).to eq true
      expect(subject.cast('random')).to eq true
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
acfs-1.3.2 spec/acfs/resource/attributes/boolean_spec.rb
acfs-1.3.1 spec/acfs/resource/attributes/boolean_spec.rb
acfs-1.3.0 spec/acfs/resource/attributes/boolean_spec.rb
acfs-1.2.1 spec/acfs/resource/attributes/boolean_spec.rb
acfs-0.50.0 spec/acfs/resource/attributes/boolean_spec.rb
acfs-1.2.0 spec/acfs/resource/attributes/boolean_spec.rb
acfs-0.49.1 spec/acfs/resource/attributes/boolean_spec.rb
acfs-1.1.1 spec/acfs/resource/attributes/boolean_spec.rb
acfs-0.49.0 spec/acfs/resource/attributes/boolean_spec.rb
acfs-1.1.0 spec/acfs/resource/attributes/boolean_spec.rb
acfs-0.48.2 spec/acfs/resource/attributes/boolean_spec.rb
acfs-1.0.1 spec/acfs/resource/attributes/boolean_spec.rb
acfs-0.48.1 spec/acfs/resource/attributes/boolean_spec.rb
acfs-1.0.0 spec/acfs/resource/attributes/boolean_spec.rb
acfs-0.48.0 spec/acfs/resource/attributes/boolean_spec.rb
acfs-0.47.0 spec/acfs/resource/attributes/boolean_spec.rb
acfs-0.46.0 spec/acfs/resource/attributes/boolean_spec.rb