Sha256: 56632bbb3af37e376841b01037387d145e9a401027f52ed84e7d145d0def4627

Contents?: true

Size: 1.33 KB

Versions: 56

Compression:

Stored size: 1.33 KB

Contents

# encoding: utf-8
require 'spec_helper'
require 'fedux_org_stdlib/core_ext/hash/options'

RSpec.describe '#to_options' do
  it 'converts hash to array of command line options' do
    hash = {}

    expect(hash.to_options).to be_kind_of Array
  end

  it 'converts true value' do
    hash = {
      opt1: true
    }

    expect(hash.to_options).to eq %w(--opt1)
  end

  it 'converts false value' do
    hash = {
      opt1: false
    }

    expect(hash.to_options).to eq %w(--no-opt1)
  end

  it 'converts integervalue' do
    hash = {
      opt1: 1
    }

    expect(hash.to_options).to eq %w(--opt1 1)
  end

  it 'converts string value' do
    hash = {
      opt1: 'string'
    }

    expect(hash.to_options).to eq %w(--opt1 string)
  end

  it 'converts symbol value' do
    hash = {
      opt1: :string
    }

    expect(hash.to_options).to eq %w(--opt1 string)
  end

  it 'handles umlauts as well' do
    hash = {
      'öäopt1' => 'string'
    }

    expect(hash.to_options).to eq %w(--opt1 string)
  end

  it 'handles special characters as well' do
    hash = {
      "$o p\tt1" => 'string'
    }

    expect(hash.to_options).to eq %w(--opt1 string)
  end

  it 'handles special characters in value as well' do
    hash = {
      opt1: 'string$string string'
    }

    expect(hash.to_options).to eq ['--opt1', 'string\$string\ string']
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.8.6 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.8.5 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.8.4 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.8.3 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.8.0 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.33 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.31 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.30 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.29 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.28 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.27 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.26 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.25 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.24 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.23 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.22 spec/core_ext/hash/options_spec.rb