Sha256: 2568853501c0817b7e5d2a3234caa46ce00af2573236f2584dd04cc06534c496

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

require File.dirname(__FILE__) + '/../../helper'
require 'test/unit'
require 'jinx/cli/command'
require 'set'

module Jinx
  class CommandTest < Test::Unit::TestCase
    def test_empty
      verify_execution(CLI::Command.new, '', {})
    end
    
    def test_arg
      verify_execution(CLI::Command.new([[:arg, 'ARG']]), '4', {:arg => '4'})
    end
    
    def test_option
      verify_execution(CLI::Command.new([[:opt, '--opt N', 'option']]), '--opt 4', {:opt => '4'})
    end
    
    def test_typed_option
      verify_execution(CLI::Command.new([[:opt, '--opt N', Integer, 'option']]), '--opt 4', {:opt => 4})
    end
    
    def test_both
      verify_execution(CLI::Command.new([[:arg, 'ARG'], [:opt, '--opt N', 'option']]), '4 --opt 5', {:arg => '4', :opt => '5'})
    end
   
    private
    
    def verify_execution(cmd, s, expected)
      ARGV.clear.concat(s.split)
      cmd.start do |actual|
        actual.each do |opt, aval|
          eval = expected[opt]
          assert_not_nil(aval, "Command option #{opt} not found.")
          assert_equal(eval, aval, "Command option #{opt} parsed incorrectly.")
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jinx-2.1.4 test/lib/jinx/command_test.rb
jinx-2.1.3 test/lib/jinx/command_test.rb
jinx-2.1.2 test/lib/jinx/command_test.rb
jinx-2.1.1 test/lib/jinx/command_test.rb