Sha256: 8b84f05892adb21be8e3c11131f68a085c200d8579cb32de8ce301b9dc42a606

Contents?: true

Size: 1.35 KB

Versions: 31

Compression:

Stored size: 1.35 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

31 entries across 31 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.7.21 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.20 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.19 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.18 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.17 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.16 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.15 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.14 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.12 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.11 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.10 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.8 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.7 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.6 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.5 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.4 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.3 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.2 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.1 spec/core_ext/hash/options_spec.rb
fedux_org-stdlib-0.7.0 spec/core_ext/hash/options_spec.rb