Sha256: c1b0e7cd5987f078689f3f6ab99f7cf485818c0f938b84fb8e041b4f00668763

Contents?: true

Size: 1.96 KB

Versions: 13

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Sinclair::MethodDefinition::Stringifier do
  describe '.value_string' do
    context 'when value is nil' do
      it 'returns string representing nil' do
        expect(described_class.value_string(nil)).to eq('nil')
      end
    end

    context 'when value is a symbol' do
      it 'returns string representing a symbol' do
        expect(described_class.value_string(:symbol)).to eq(':symbol')
      end
    end

    context 'when value is a string' do
      it 'returns string representing a string' do
        expect(described_class.value_string('string')).to eq('"string"')
      end
    end

    context 'when value is a number' do
      it 'returns string representing a number' do
        expect(described_class.value_string(10)).to eq('10')
      end
    end

    context 'when value is a float' do
      it 'returns string representing a float' do
        expect(described_class.value_string(1.20)).to eq('1.2')
      end
    end

    context 'when value is a true' do
      it 'returns string representing a true' do
        expect(described_class.value_string(true)).to eq('true')
      end
    end

    context 'when value is a false' do
      it 'returns string representing a false' do
        expect(described_class.value_string(false)).to eq('false')
      end
    end

    context 'when value is a class' do
      it 'returns string representing a class' do
        expect(described_class.value_string(Sinclair::Model)).to eq('Sinclair::Model')
      end
    end

    context 'when value is a hash' do
      it 'returns string representing a Hash' do
        expect(described_class.value_string({ a: 10, 'b' => 'value' }))
          .to eq('{:a=>10, "b"=>"value"}')
      end
    end

    context 'when value is an Array' do
      it 'returns string representing a Array' do
        expect(described_class.value_string([:a, 10, 'b', true, nil]))
          .to eq('[:a, 10, "b", true, nil]')
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
sinclair-2.1.1 spec/lib/sinclair/method_definition/stringifier_spec.rb
sinclair-2.1.0 spec/lib/sinclair/method_definition/stringifier_spec.rb
sinclair-2.0.1 spec/lib/sinclair/method_definition/stringifier_spec.rb
sinclair-2.0.0 spec/lib/sinclair/method_definition/stringifier_spec.rb
sinclair-1.16.3 spec/lib/sinclair/method_definition/stringifier_spec.rb
sinclair-1.16.2 spec/lib/sinclair/method_definition/stringifier_spec.rb
sinclair-1.16.1 spec/lib/sinclair/method_definition/stringifier_spec.rb
sinclair-1.16.0 spec/lib/sinclair/method_definition/stringifier_spec.rb
sinclair-1.15.0 spec/lib/sinclair/method_definition/stringifier_spec.rb
sinclair-1.14.2 spec/lib/sinclair/method_definition/stringifier_spec.rb
sinclair-1.14.1 spec/lib/sinclair/method_definition/stringifier_spec.rb
sinclair-1.14.0 spec/lib/sinclair/method_definition/stringifier_spec.rb
sinclair-1.13.0 spec/lib/sinclair/method_definition/stringifier_spec.rb