Sha256: b1684f729384c70eabf1d9f2d03007784e86182302800c92a4c2f7e9a1ac46d3

Contents?: true

Size: 1.97 KB

Versions: 4

Compression:

Stored size: 1.97 KB

Contents

require 'spec_helper'
require 'pathname'

describe MiniGit do
  let(:git) { MiniGit::new }

  describe '#switches_for' do
    it 'passes regular arguments' do
      assert { git.switches_for('foo') == %w'foo' }
      assert { git.switches_for('foo', 'bar') == %w'foo bar' }
      assert { git.switches_for('foo', 'bar', 'baz quux') == ['foo', 'bar', 'baz quux'] }
    end

    it 'converts hashes to switches' do
      assert { git.switches_for(:foo => 'bar') == %w'--foo=bar' }
      assert { git.switches_for(:f => 'bar') == %w'-f bar' }
      assert { git.switches_for('foo', 'bar', :baz => 'quux') == %w'foo bar --baz=quux' }
      assert { git.switches_for({ :foo => 'bar' }, 'baz', 'quux') == %w'--foo=bar baz quux' }
    end

    it 'sorts switch names in hash' do
      assert { git.switches_for(:foo => 'bar', :baz => 'quux') == %w'--baz=quux --foo=bar' }
    end

    it 'converts underscores to dashes' do
      assert { git.switches_for(:foo_bar_baz => 'quux') == %w'--foo-bar-baz=quux' }
    end

    it 'recursively flattens the arrays' do
      assert { git.switches_for('foo', ['bar', 'baz'], 'quux') == %w'foo bar baz quux' }
      assert { git.switches_for('foo', ['bar', ['baz']], 'quux') == %w'foo bar baz quux' }
      assert { git.switches_for('foo', ['bar', {:baz => 'quux'}], 'xyzzy') == %w'foo bar --baz=quux xyzzy' }
    end

    it 'multiplies the switch if hash value is an array' do
      assert { git.switches_for(:foo => ['bar', 'baz', 'quux']) == %w'--foo=bar --foo=baz --foo=quux' }
    end

    it 'converts positional aruments to strings' do
      assert { git.switches_for(:foo, Pathname.new(__FILE__)) == ['foo', __FILE__] }
    end

    it 'interpretes true value as a boolean switch' do
      assert { git.switches_for(:foo => true) == %w'--foo' }
      assert { git.switches_for(:f => true) == %w'-f' }
    end


    it 'converts underscore to dash in a positional symbol' do
      assert { git.switches_for(:foo_bar, 'baz_quux') == %w'foo-bar baz_quux' }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
minigit-0.0.4 spec/minigit_switches_for_spec.rb
minigit-0.0.3 spec/minigit_switches_for_spec.rb
minigit-0.0.2 spec/minigit_switches_for_spec.rb
minigit-0.0.1 spec/minigit_switches_for_spec.rb