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.11.18 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.17 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.16 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.15 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.14 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.12 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.11 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.9 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.8 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.7 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.6 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.5 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.4 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.3 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.2 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.1 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.11.0 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.10.9 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.10.8 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.10.7 spec/core_ext/hash/options_spec.rb