Sha256: 892005477bd5f2e2e4ca8906775e835c2b86ca4586490f676ba6ded0e3fd24d8

Contents?: true

Size: 1.49 KB

Versions: 5

Compression:

Stored size: 1.49 KB

Contents

require 'helper'
require 'flipper/typecast'

RSpec.describe Flipper::Typecast do
  {
    nil => false,
    '' => false,
    0 => false,
    1 => true,
    '0' => false,
    '1' => true,
    true => true,
    false => false,
    'true' => true,
    'false' => false,
  }.each do |value, expected|
    context "#to_boolean for #{value.inspect}" do
      it "returns #{expected}" do
        expect(described_class.to_boolean(value)).to be(expected)
      end
    end
  end

  {
    nil => 0,
    '' => 0,
    0 => 0,
    1 => 1,
    '1' => 1,
    '99' => 99,
  }.each do |value, expected|
    context "#to_integer for #{value.inspect}" do
      it "returns #{expected}" do
        expect(described_class.to_integer(value)).to be(expected)
      end
    end
  end

  {
    nil => Set.new,
    '' => Set.new,
    Set.new([1, 2]) => Set.new([1, 2]),
    [1, 2] => Set.new([1, 2]),
  }.each do |value, expected|
    context "#to_set for #{value.inspect}" do
      it "returns #{expected}" do
        expect(described_class.to_set(value)).to eq(expected)
      end
    end
  end

  it 'raises argument error for integer value that cannot be converted to an integer' do
    expect do
      described_class.to_integer(['asdf'])
    end.to raise_error(ArgumentError, %(["asdf"] cannot be converted to an integer))
  end

  it 'raises argument error for set value that cannot be converted to a set' do
    expect do
      described_class.to_set('asdf')
    end.to raise_error(ArgumentError, %("asdf" cannot be converted to a set))
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
flipper-0.11.0.beta6 spec/flipper/typecast_spec.rb
flipper-0.11.0.beta5 spec/flipper/typecast_spec.rb
flipper-0.11.0.beta4 spec/flipper/typecast_spec.rb
flipper-0.11.0.beta3 spec/flipper/typecast_spec.rb
flipper-0.11.0.beta1 spec/flipper/typecast_spec.rb